# Using Ansible to make an /proc like mount for your environment

**URL:** <https://forum.ansible.com/t/using-ansible-to-make-an-proc-like-mount-for-your-environment/17673>\
**Category:** Ansible Project\
**Created:** [March 5, 2015, 10:23am UTC](https://forum.ansible.com/t/using-ansible-to-make-an-proc-like-mount-for-your-environment/17673 "2015-03-05T10:23:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yoram\_Hekma](https://avatars.discourse-cdn.com/v4/letter/y/90ced4/32.png) [@Yoram\_Hekma](https://forum.ansible.com/u/Yoram_Hekma)\
**Post date:** [March 5, 2015, 10:23am UTC](https://forum.ansible.com/t/using-ansible-to-make-an-proc-like-mount-for-your-environment/17673/1 "2015-03-05T10:23:40Z")

</div>

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](https://github.com/yhekma/datamounter).

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](https://github.com/terencehonles/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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [March 5, 2015, 2:22pm UTC](https://forum.ansible.com/t/using-ansible-to-make-an-proc-like-mount-for-your-environment/17673/2 "2015-03-05T14:22:00Z")

</div>

Note that fact caching with the jsonfile plugin already does the work  
of the 1st script w/o the need to execute separately.

---

<div class="post-metadata">

**Author:** ![Yoram\_Hekma](https://avatars.discourse-cdn.com/v4/letter/y/90ced4/32.png) [@Yoram\_Hekma](https://forum.ansible.com/u/Yoram_Hekma)\
**Post date:** [March 5, 2015, 3:17pm UTC](https://forum.ansible.com/t/using-ansible-to-make-an-proc-like-mount-for-your-environment/17673/3 "2015-03-05T15:17:26Z")

</div>

Yeah, thats true. But there are some additional options you can use with ansible\_fetcher. For instance, if you want to mount stuff realtime, you need the json-value (to be translated to the filepath), but not really the content.  
For instance, lets say I want a file named “sar” which always contains the output of “sar -Ap”. If I want to mount 100+ hosts, the resulting json file would be huge, but the actual data would not even be used (because when you access the “sar” file, the data gets fetched again anyway). In this case you can use --skeleton to clean up the datastructure before writing it out to the file.

Also I do some “sanitizing” to make some stuff easier to navigate when mounted.

But as stated, datamounter.py is in no way dependent on Ansible, I just find it an interesting usecase:)
