All,
I made 2 scripts I wanted to show to you guys. Maybe someone finds them useful, and maybe someone has some suggestions on improving them (I am an engineer, not a developer, and this is the first time I am doing stuff with FUSE). The code is available on github.
After I saw how much data you can get “for free” (ie: no root required) with the setup module and how easy it was to use the Ansible module in python, I wanted to use these things to create a layout of my infrastructure independent of network location. What I came up with are 2 scripts, a ansible_fetcher.py that collects all the data provided by “ansible -m setup $host” as well as running optional custom commands and collecting their output. This is all saved in a json file. The second script, datamounter.py, can mount json files on your (linux) filesystem using fusepy. Optionally you can pass a --realtime parameter so that when a file gets opened (say, ansible_memfree), the data is updated using Ansible before the contents are shown.
Note that datamounter is not only useful in tandem with Ansible, I can imagine complex configurations being made available as a filesystem so you can easily grep through them or something…
In practice:
yoram@mac-air ~/DEV/Datamounter (master) $ ./ansible_fetcher.py --pattern my_hosts --retries 5 -f ./my_hosts.json
yoram@mac-air ~/DEV/Datamounter (master) $ ls -lh my_hosts.json
-rw-r–r-- 1 yoram staff 2.6M Feb 20 14:01 my_hosts.json
yoram@mac-air ~/DEV/Datamounter (master) $ ./datamounter.py --cache my_hosts.json ./Test
Loading data
done
yoram@mac-air ~/DEV/Datamounter (master*) $ mount
-------------------------- snip ---------------------------
DataFS on /Users/yoram/DEV/Datamounter/Test (osxfusefs, nodev, nosuid, read-only, synchronous, mounted by yoram)
yoram@mac-air ~/DEV/Datamounter (master*) $ ls Test
serverora220 serverora210 servermwf001 serverbeh003 serverweb008
serverora221 serverora211 servermwf002 serverbvb001 serverweb009
serverora222 serverora307 servermwf003 serverbvb002
-------------------------------------- etc ---------------------------------------
yoram@mac-air ~/DEV/Datamounter/Test (master*) $ cd Test
yoram@mac-air ~/DEV/Datamounter/Test (master*) $ find serverora220 | wc -l
216
yoram@mac-air ~/DEV/Datamounter/Test (master*) $ find serverora220 | head
serverora220
serverora220/ansible_all_ipv4_addresses
serverora220/ansible_all_ipv4_addresses/listitem_0
serverora220/ansible_all_ipv6_addresses
serverora220/ansible_architecture
serverora220/ansible_bios_date
serverora220/ansible_bios_version
serverora220/ansible_devices/sda
serverora220/ansible_devices/sda/holders
serverora220/ansible_devices/sda/host
serverora220/ansible_devices/sda/model
serverora220/ansible_devices/sda/partitions
serverora220/ansible_devices/sda/partitions/sda1
serverora220/ansible_devices/sda/partitions/sda1/sectors
serverora220/ansible_devices/sda/partitions/sda1/sectorsize
serverora220/ansible_devices/sda/partitions/sda1/size
serverora220/ansible_devices/sda/partitions/sda1/start
---------------------------- snip -------------------------------
Any input is more than welcome. I have to admit I am somewhat hesitant to post this because of my lack of experience, but as you see have made the plunge:)
Cheers,
Yoram