Ansible : Accessing a variable containing a :

Hi

I’ve got an issue with the variables coming from the setup module
It list all the network interfaces on the target system and I need to reuse the ip address from the eth0:0 interface in a template

From the setup module :

“ansible_eth0”: {
“active”: true,
“device”: “eth0”,
“ipv4”: {
“address”: “10.0.2.15”,
“netmask”: “255.255.255.0”,
“network”: “10.0.2.0”
},
“ipv6”: [
{
“address”: “fe80::a00:27ff:febb:8ca9”,
“prefix”: “64”,
“scope”: “link”
}
],
“macaddress”: “08:00:27:bb:8c:a9”,
“module”: “e1000”,
“mtu”: 1500,
“type”: “ether”
},
“ansible_eth0:0”: {
“active”: true,
“device”: “eth0”,
“ipv4”: {
“address”: “192.168.77.60”,
“netmask”: “255.255.255.0”,
“network”: “192.168.77.0”
},
“macaddress”: “08:00:27:bb:8c:a9”,
“module”: “e1000”,
“mtu”: 1500,
“type”: “ether”
},

To access it i’ve tried different format but either the play stopped or in the final file, the name of the variable is written not the content
{{ “ansible_eth0:0.ipv4.address” }}
{{ “ansible_eth0:0”.ipv4.address }}

And same with the $ notation

Is there a way to get it or is it a bug ?

Thanks
Frank

“{{ “ansible_eth0:0.ipv4.address” }}”

Don’t quote things, you’re requesting the template engine return the string you passed in!

{{ hostvars[inventory_hostname][‘ansible_eth0:0’][‘ipv4’][‘address’] }}

will work for you

I agree we should replace the “:”'s with an underscore though.

Please file a ticket on github and we will make it so.

Hi Michael

Thanks for the workaround

I’ve tried this in my test environment and confirm it is working fine

Many thanks
Frank