ansible-cmdb icon indicating copy to clipboard operation
ansible-cmdb copied to clipboard

Using facts_cache for esx hosts is not working properly

Open tuxpeople opened this issue 6 months ago • 1 comments

As my inventories are not suitable for ansible-cmdb, I've to rely on the cached facts. I have some VMware ESXi 8.0.2 nodes, and if I use ansible -m setup to get the facts, ansible-cmdb is working. But I'm missing many information like CPU, RAM. Product Name etc.

There's also a ansible module to get more facts from esx: community.vmware.vmware_host_facts. As soon as I use that, ansible-cmdb fails to create the detail pages for the hosts. But its showing CPU, RAM and Product Name in the overview. But they are displayed the same for all ESX nodes, using the information from the last parsed host for all off them.

here's the error:

$ ansible-cmdb -d -f ./  -t html_fancy_split
Trying python bin: /Users/tdeutsch/bin/python
Trying ansible-cmdb bin: /opt/homebrew/bin/../lib/ansiblecmdb/ansible-cmdb.py
Using python bin /Users/tdeutsch/bin/python
Using ansible-cmdb bin /opt/homebrew/bin/../lib/ansiblecmdb/ansible-cmdb.py
config_dir = None
data_dir = /opt/homebrew/lib/python3.11/site-packages/ansiblecmdb/data
tpl_dir = /opt/homebrew/lib/python3.11/site-packages/ansiblecmdb/data/tpl
static_dir = /opt/homebrew/lib/python3.11/site-packages/ansiblecmdb/data/static
inventory files = None
template params = {'lib_dir': '/opt/homebrew/lib/python3.11/site-packages/ansiblecmdb/data', 'data_dir': '/opt/homebrew/lib/python3.11/site-packages/ansiblecmdb/data', 'version': '1.31', 'log': <RootLogger root (DEBUG)>, 'columns': None, 'exclude_columns': None, 'cust_cols': []}
Parsing fact dir: ./
Reading host facts from ./tpi-node2
Reading host facts from ./tpi-node3
Reading host facts from ./tpi-node4
Reading host facts from ./garm
Reading host facts from ./esx1
Reading host facts from ./tpi-node1
Reading host facts from ./linux-vm2_fab8
Reading host facts from ./localhost
Reading host facts from ./esx4
Reading host facts from ./test_a188
Reading host facts from ./esx2
Reading host facts from ./esx5
Reading host facts from ./linux-vm_1202
Rendering host overview for tpi-node2
Rendering host overview for tpi-node3
Rendering host overview for tpi-node4
Rendering host overview for garm
Rendering host overview for esx1
Rendering host overview for tpi-node1
Rendering host overview for linux-vm2_fab8
Rendering host overview for localhost
Rendering host overview for esx4
Rendering host overview for test_a188
Rendering host overview for esx2
Rendering host overview for esx5
Rendering host overview for linux-vm_1202
Whoops, it looks like something went wrong while rendering the template.

The reported error was: KeyError: 'network'

The full error was:

    Traceback (most recent call last):
      File "/opt/homebrew/bin/../lib/ansiblecmdb/ansible-cmdb.py", line 214, in <module>
        output = renderer.render(ansible.get_hosts(), params)
      File "/opt/homebrew/lib/python3.11/site-packages/ansiblecmdb/render.py", line 44, in render
        return self._render_py(hosts, vars)
      File "/opt/homebrew/lib/python3.11/site-packages/ansiblecmdb/render.py", line 63, in _render_py
        return module.render(hosts, vars=vars, tpl_dirs=self.tpl_dirs)
      File "/opt/homebrew/lib/python3.11/site-packages/ansiblecmdb/data/tpl/html_fancy_split.py", line 30, in render
        output = template.render(host=host, **vars).lstrip().decode('utf8')
      File "/opt/homebrew/lib/python3.11/site-packages/mako/template.py", line 438, in render
        return runtime._render(self, self.callable_, args, data)
      File "/opt/homebrew/lib/python3.11/site-packages/mako/runtime.py", line 874, in _render
        _render_context(
      File "/opt/homebrew/lib/python3.11/site-packages/mako/runtime.py", line 916, in _render_context
        _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
      File "/opt/homebrew/lib/python3.11/site-packages/mako/runtime.py", line 943, in _exec_template
        callable_(context, *args, **kwargs)
      File "/opt/homebrew/lib/python3.11/site-packages/ansiblecmdb/data/tpl/html_fancy_split_detail.tpl", line 21, in render_body
        <% html_host_detail(host, collapsed=collapsed, skip_empty=skip_empty, is_split=True) %>
      File "/opt/homebrew/lib/python3.11/site-packages/ansiblecmdb/data/tpl/html_fancy_defs.html", line 350, in render_html_host_detail
        <% host_network(host, collapsed_class) %>
      File "/opt/homebrew/lib/python3.11/site-packages/ansiblecmdb/data/tpl/html_fancy_defs.html", line 315, in host_network
        <%def name="html_host_detail(host, collapsed=False, skip_empty=False, is_split=False)">
      File "/opt/homebrew/lib/python3.11/site-packages/ansiblecmdb/data/tpl/html_fancy_defs.html", line 881, in render_host_network
        <td>${net['network']}</td>
    KeyError: 'network'

The output is probably not correct.

!!! This is probably a problem with missing information in your host facts

I've attached four facts files for one of the hosts, using different methods to gather the facts.

File: esx1_gathering_facts.txt Method: Empty playbook with gather_facts: true

File: esx1_setup.txt Method: Used ansible -m setup

File: esx1_summary.txt Method: Using a playbook with gather_facts: true and this task:

- name: gather host facts
  community.vmware.vmware_host_facts:
    hostname: "{{ ansible_host }}"
    username: "{{ esxi.username }}"
    password: "{{ esxi.password }}"
    validate_certs: false
    schema: summary
  register: host_facts
  delegate_to: localhost

File: esx1_vsphere.txt Method: Using a playbook with gather_facts: true and this task:

- name: gather host facts
  community.vmware.vmware_host_facts:
    hostname: "{{ ansible_host }}"
    username: "{{ esxi.username }}"
    password: "{{ esxi.password }}"
    validate_certs: false
    schema: vsphere
  register: host_facts
  delegate_to: localhost

tuxpeople avatar Feb 22 '24 11:02 tuxpeople

And here are the attachments, sorry.

esx1_gathering_facts.txt esx1_setup.txt esx1_summary.txt esx1_vsphere.txt

tuxpeople avatar Feb 22 '24 11:02 tuxpeople