Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include for showing the packages facts #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yodatak
Copy link

@yodatak yodatak commented May 8, 2018

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>

@Prophecy67
Copy link

+1

@Prophecy67
Copy link

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants