arillso / ansible.hosts

Ansible role that dynamically creates the hosts file.
MIT License
6 stars 11 forks source link

Broken on `Ansible 2.11.6` / `Jinja2 3.0.3`? #50

Open Kariton opened 3 years ago

Kariton commented 3 years ago

Hey,

I just cloned the master branch and discovered that the deployment of the hosts file failed:

I execute the role as the following:

# ansible-playbook playbook/hostsfile.yml -e "hosts_inventory_to_hosts=true"

The Error:

TASK [system_hosts : Edits the hosts file in /etc] ****************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'ipv4'
fatal: [host1.example.com]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'ipv4'"}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'ipv4'
fatal: [host2.example.com]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'ipv4'"}

The full traceback is:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/ansible/template/__init__.py", line 1100, in do_template
    res = j2_concat(rf)
  File "<template>", line 108, in root
  File "/usr/local/lib/python3.6/site-packages/ansible/template/__init__.py", line 265, in wrapper
    ret = func(*args, **kwargs)
  File "/opt/ansible/collections/ansible_collections/ansible/netcommon/plugins/filter/ipaddr.py", line 560, in ipaddr
    elif not value or value is True:
  File "/usr/local/lib/python3.6/site-packages/jinja2/runtime.py", line 903, in _fail_with_undefined_error
    raise self._undefined_exception(self._undefined_message)
jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'ipv4'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/ansible/plugins/action/template.py", line 146, in run
    resultant = templar.do_template(template_data, preserve_trailing_newlines=True, escape_backslashes=False)
  File "/usr/local/lib/python3.6/site-packages/ansible/template/__init__.py", line 1137, in do_template
    raise AnsibleUndefinedVariable(e)
ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'ipv4'
fatal: [host1.example.com]: FAILED! => {
    "changed": false,
    "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'ipv4'"
}

Removing cached facs or direktly trigger ansible.builtin.setup as pre_tasks changed nothing.

Proof that the dict object exists:

# ansible -m setup --tree facts/ GROUP
# cat facts/host1.example.com | jq . -C | grep '"ipv4"' -A 5
      "ipv4": {
        "address": "172.28.20.41",
        "broadcast": "172.28.20.255",
        "netmask": "255.255.255.0",
        "network": "172.28.20.0"
      },
--
      "ipv4": {
        "address": "127.0.0.1",
        "broadcast": "",
        "netmask": "255.0.0.0",
        "network": "127.0.0.0"
      },
# ansible --version
ansible [core 2.11.6]
  python version = 3.6.8 (default, Sep 12 2021, 04:40:35) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
  jinja version = 3.0.3
  libyaml = True

Can anyone reproduce this error?

Kariton commented 3 years ago

Downgraded Jinja2 to jinja version = 2.11.0 - changed nothing

Kariton commented 3 years ago

I think my problem is related to different interface names

In my case this are an oVirt node and oVirt engine.