Hi,
I successfully managed to add a private IP address on my servers. I
can see both network interfaces eth0 and eth1 when I ask for the facts
of this server (I stuggled to death to find this command) :
$ ansible server -m setup -i production
"ansible_eth0": {
"active": true,
"device": "eth0",
"ipv4": {
"address": "x.x.x.x",
"netmask": "x.x.x.x",
"network": "x.x.x.x"
},
"ipv6": [
{
"address": "x:x:x:x",
"prefix": "64",
"scope": "link"
}
],
"macaddress": "x:x:x:x:x:x",
"module": "e1000e",
"mtu": 1500,
"type": "ether"
},
"ansible_eth1": {
"active": true,
"device": "eth1",
"ipv4": {
"address": "x.x.x.x",
"netmask": "x.x.x.x",
"network": "x.x.x.x"
},
"ipv6": [
{
"address": "x:x:x:x",
"prefix": "64",
"scope": "link"
}
],
"macaddress": "x:x:x:x:x:x",
"module": "e1000e",
"mtu": 9000,
"type": "ether"
},
But when I want to access the "ansible_eth1" fact from my playbook :
# dest file is /etc/hosts
# locally resolve private IPs
{% for host in groups['all'] %}
{{ hostvars[host]['ansible_eth1']['ipv4']['address'] }} {{ host }}
{% endfor %}
I get the following error on every single server :
fatal: [server] => {'msg': "One or more undefined variables: 'dict
object' has no attribute 'ipv4'", 'failed': True}
This kind of code worked really good with eth0 ,as you can see in my
fully working iptables template extract :
{% for host in groups['all'] %}
# access from {{ host }}
- -A INPUT -p tcp -m tcp -s {{
hostvars[host]['ansible_eth0']['ipv4']['address'] }} --dport {{
some_port }} -j ACCEPT
{% endfor %}
What am I doing wrong ?
How can I debug this ? I thought "ansible server -m setup -i
production" would provide me the correct information, but I was wrong.
Thanks.
- --
Jean-Philippe Caruana