Mounting data onto your filesystem for fun and unfortunately no profit

A little more than a year ago I was working for a client that desired to have a simple way do do an inventory of their linux servers (running SLES). They had their networking DTAP configured to make every environment only available via a bastion host and only that host.
Luckily you can do a lot with Ansible in conjunction with ProxyCommands (see https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Proxies_and_Jump_Hosts) so reaching the servers was not really a problem and since Ansible's excellent setup module provides a wealth of information, I had all the ingredients I needed, I just needed to connect the dots.

Since I wanted to learn more about filesystems (and FUSE in particular) I thought it would be a nice exercise to try and "map" the collected data from Ansible's setup module onto a mountpoint to make it easy to grep and parse and all that jazz. Since the data format Ansible uses is JSON anyway, I thought it would be best to first focus on creating a script that can mount an arbitrary datastructure in JSON format, which is exactly what I did:

https://github.com/yhekma/datamounter

Using this script, you can mount your JSON files like so:

datamounter.py -c my_file.json /opt/infra_map

After which the contents of the json files are mounted.
So, when you have the following dictionary/json:

{'key1': {'key2': 'data1',
  'key3': ['something', 'something_else', 'and_another_thing']},
 'key4': 'bla'}

it gets mapped as:

mountpoint/
mountpoint/key4
mountpoint/key1
mountpoint/key1/key2
mountpoint/key1/key3
mountpoint/key1/key3/listitem_0
mountpoint/key1/key3/listitem_2
mountpoint/key1/key3/listitem_1

Where the contents of mountpoint/key1/key2 is "data1" and the content of mountpoint/key1/key3/listitem_0 is "something".

In a followup post I will describe the realtime mounting process in which we can configure the filesystem so that the values like free swap space or load get collected the moment you open the file for reading.

Comments

Popular posts from this blog

Runing Saltstack in multi-master

Recursively update Composite Content Views in Satellite 6/Katello

First!