Tag.py – Simple host OS tags for Automation

Tags in IT are not new, they allow grouping of servers or applications and have been used for a while especially in virtualisation platforms such as VMware and public cloud compute platforms.

However I have not seen anything to add tags to the host operating system, which could be queried by automation engines, scripts or tools, such as Ansible. I therefore took it upon myself to write something to achieve this which would give me something useful to try using python which I am playing around with, ashamedly for the first time.

I came up with tag,py https://github.com/pdunn467/tag.py which is quite simple, and is based on some python tutorials I found from Palash Bauri

The idea is the tag program can be used to add any number of different tags and values to a host, which are then stored in a simple JSON NoSQL Database. These can be queried using the same tag.py command allowing the automation software to decide if this host is a candidate for running automation against depending on its criteria.

To add a tag and its value, the add operator is used:

./tag.py add OS Linux
adding 1 tags
Adding Tag: OS: Linux

The get operator is used to return a value for a tag:

./tag.py get OS
Linux

Tags can be deleted when no longer needed:

./tag.py delete OS
Deleting Tag: OS

All tags and values can also be viewed in one go, outputted in JSON

./tag.py view
{'OS': 'Linux', 'DPlevel': '4', 'category': 'production'}

The next step will be to create an Ansible Module, to use the same operator functions, so tags can be added, viewed and deleted directly from playbooks to allow tag based automation at the host level, outside of a dynamic inventory.

Hopefully you will clone the repo and try it for yourself, ideally in your own environments. Any issues or bugs please add them to the issues log on github.

Related Post

Leave a Reply