ansible-cmdb
ansible-cmdb copied to clipboard
Include for showing the packages facts
Ansible 2.5.0 is out and the packages facts is supported so i propose to at least explain https://docs.ansible.com/ansible/2.5/modules/package_facts_module.html
or integrate into the existing templeting or to add a new template only for demonstrate how to recover packages_facts
I use in my exemple of curl but it can be another package that is usefull.
For generate ansible output for your hosts
ansible -m setup --tree out/outsetup all
ansible -m package_facts --tree out/outpackages all
Then generate the html
ansible-cmdb out/outsetup out/outpackages > overview.html
Into the html template by exemple you can do:
{"title": "Curl 64 bits", "id": "curl64", "func": col_curl64, "sType": "string", "visible": True},
{"title": "Curl 32 bits", "id": "curl32", "func": col_curl32, "sType": "string", "visible": True},
And add with libcurl the name of the package
<%def name="col_curl64(host, **kwargs)">
${jsonxs(host, 'ansible_facts.packages.libcurl[0].version', default='')}
</%def>
<%def name="col_curl32(host, **kwargs)">
${jsonxs(host, 'ansible_facts.packages.libcurl.[1].version', default='')}
</%def>
+1
There is a possibility to do this in html_fancy_defs as well. I added a class so the installed packages are listed as a collapsed class under each host. Though you aren't able to sort/search for these and get a birds-eye view if a host has package X or Y installed. Having a separate column for every possible package would be overkill..
This also still requires the additional facts(package_facts) being dumped with --tree
<%def name="packages(host, collapsed_class)">
<h4 class="toggle-collapse ${collapsed_class}">Packages</h4>
<div class="collapsable ${collapsed_class}">
<table>
<tr>
<th>packages</th>
<td>
% if type(jsonxs(host, 'ansible_facts.packages', default=[])) == list:
${r_list(jsonxs(host, 'ansible_facts.packages', default=[]))}
% else:
${r_dict(jsonxs(host, 'ansible_facts.packages', default={}))}
% endif
</td>
</tr>
</table>
</div>
</%def>