===== Ansible CMDB =====
RHEL 7:
$ sudo useradd -d /opt/ansible_cmdb -s /bin/bash ansible
$ sudo mkdir /opt/ansible_cmdb
$ sudo chown -R ansible.ansible /opt/ansible_cmdb/
$ sudo cd /opt/
$ su - ansible
$ virtualenv --python=/usr/bin/python3.4 ansible_cmdb
$ cd /opt/ansible_cmdb/
$ source bin/activate
$ pip install ansible-cmdb
==== Configure Templates ====
If you used /opt/ansible_cmdb for your virtualenv, the templates will be on **/opt/ansible_cmdb/lib/python3.4/site-packages/ansiblecmdb/data/tpl/**.
We will modify html_fancy, the default template, we will display a new column on the table, we want see SELinux info.
$ cd /opt/ansible_cmdb/lib/python3.4/site-packages/ansiblecmdb/data/tpl/
$ cp html_fancy_defs.html html_fancy_selinux_defs.html
$ cp html_fancy.tpl html_fancy_selinux.tpl
Edit html_fancy_selinux.tpl change the line:
<%namespace name="defs" file="/html_fancy_defs.html" import="*" />
To:
<%namespace name="defs" file="/html_fancy_selinux_defs.html" import="*" />
Edit html_fancy_selinux_defs.html, add one line on cols definition similar to:
{"title": "Product Name", "id": "prodname", "func": col_prodname, "sType": "string", "visible": False},
{"title": "Product Serial","id": "prodserial", "func": col_prodserial, "sType": "string", "visible": False},
{"title": "SELinux", "id": "selinux", "func": col_selinux, "sType": "string", "visible": False},
]
Also add a new function on functions section:
<%def name="col_selinux(host, **kwargs)">
${jsonxs(host, 'ansible_facts.ansible_selinux', default='')}
%def>
##
## Detailed host information blocks
##
==== Use with semaphore ====
I will suppose that your semaphore home is /home/semaphore.
The inventory will be a file with the name inventory_xxx (where x is a number) that will be you headache, every change on semaphore inventories will require a modification on your crontab script.
I will suppose that you inventory file is inventory_85.
Execute the ansible output for your hosts and create the html file:
$ ansible -m setup -i inventory_85 all --tree out/
$ ansible-cmdb out/> overview.html
Move the file to a web server visible file:
$ sudo mv overview.html /var/www/html/ansible-overview/index.html
==== Update ====
$ pip install --upgrade ansible-cmdb
==== SSL problems ====
$ pip install --upgrade --trusted-host pypi.org --trusted-host files.pythonhosted.org ansible-cmdb