I am getting following error while executing playbook to create /etc/hosts like file using jinja2 template. For loop with fact variables are used in templates
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleUndefinedVariable: 'dict object' has no attribute 'default_ipv4'. 'dict object' has no attribute 'default_ipv4'
fatal: [node1]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute 'default_ipv4'. 'dict object' has no attribute 'default_ipv4'"}
$ansible -m setup all - too big file . I hope next one is good enough for your propose:
[student@workstation a]$ ansible -m setup -a "filter=ansible_default_ipv4" all
node2 | SUCCESS => {
"ansible_facts": {
"ansible_default_ipv4": {},
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false
}
node1 | SUCCESS => {
"ansible_facts": {
"ansible_default_ipv4": {
"address": "172.25.250.9",
"alias": "eth0",
"broadcast": "172.25.250.255",
"gateway": "172.25.250.254",
"interface": "eth0",
"macaddress": "52:54:00:00:fa:09",
"mtu": 1500,
"netmask": "255.255.255.0",
"network": "172.25.250.0",
"type": "ether"
},
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false
}
Exactly. Here's another guy who has written about this behavior, but I'm not sure his proposed "solution" is necessarily a good one, I'd have to think about that (if you don't have a default route, you really don't have a good way to select a "default" IP address on a system).
https://medium.com/opsops/ansible-default-ipv4-is-not-what-you-think-edb8ab154b10
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.