{"id":66,"date":"2020-07-07T19:48:03","date_gmt":"2020-07-07T18:48:03","guid":{"rendered":"https:\/\/www.slowergram.com\/?p=66"},"modified":"2020-08-19T19:49:27","modified_gmt":"2020-08-19T18:49:27","slug":"tag-py-simple-host-os-tags-for-automation","status":"publish","type":"post","link":"https:\/\/www.slowergram.com\/index.php\/2020\/07\/07\/tag-py-simple-host-os-tags-for-automation\/","title":{"rendered":"Tag.py \u2013 Simple host OS tags for Automation"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>I came up with tag,py&nbsp;<a href=\"https:\/\/github.com\/pdunn467\/tag.py\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/pdunn467\/tag.py<\/a>&nbsp;which is quite simple, and is based on some python tutorials I found from&nbsp;<a href=\"https:\/\/www.freecodecamp.org\/news\/author\/palash\/\" target=\"_blank\" rel=\"noreferrer noopener\">Palash Bauri<\/a><\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>To add a tag and its value, the add operator is used:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/tag.py add OS Linux\nadding 1 tags\nAdding Tag: OS: Linux\n<\/code><\/pre>\n\n\n\n<p>The get operator is used to return a value for a tag:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/tag.py get OS\nLinux\n<\/code><\/pre>\n\n\n\n<p>Tags can be deleted when no longer needed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/tag.py delete OS\nDeleting Tag: OS\n<\/code><\/pre>\n\n\n\n<p>All tags and values can also be viewed in one go, outputted in JSON<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/tag.py view\n{'OS': 'Linux', 'DPlevel': '4', 'category': 'production'}\n<\/code><\/pre>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>Hopefully you will clone the&nbsp;<a href=\"https:\/\/github.com\/pdunn467\/tag.py\" target=\"_blank\" rel=\"noreferrer noopener\">repo<\/a>&nbsp;and try it for yourself, ideally in your own environments. Any issues or bugs please add them to the issues log on github.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 <a href=\"https:\/\/www.slowergram.com\/index.php\/2020\/07\/07\/tag-py-simple-host-os-tags-for-automation\/\" class=\"btn btn-link continue-link\">Continue Reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[10,14,13],"class_list":["post-66","post","type-post","status-publish","format-standard","hentry","category-uncategorised","tag-homelab","tag-opensource","tag-python"],"_links":{"self":[{"href":"https:\/\/www.slowergram.com\/index.php\/wp-json\/wp\/v2\/posts\/66","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.slowergram.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.slowergram.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.slowergram.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.slowergram.com\/index.php\/wp-json\/wp\/v2\/comments?post=66"}],"version-history":[{"count":0,"href":"https:\/\/www.slowergram.com\/index.php\/wp-json\/wp\/v2\/posts\/66\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.slowergram.com\/index.php\/wp-json\/wp\/v2\/media?parent=66"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.slowergram.com\/index.php\/wp-json\/wp\/v2\/categories?post=66"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.slowergram.com\/index.php\/wp-json\/wp\/v2\/tags?post=66"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}