All,
Perhaps someone knows the answer for my problem:
I gather the facts of a machine and want to use it as variable in a template.
As far as i know you just use {{ ansible_eth0.ipv4.address }} to get the ip address of the interface eth0.
Now my problem, the interface has a dot (.) in it’s name.
So it is called: “ansible_eth0.2” and now i have a problem because {{ ansible_eth0.2.ipv4.address }} gives errors.
I tried to exclude the dot in so many ways but now i’m stuck.
Any one got the solution for me?
Kind regards,
Oliver.
Does escaping the “.” in the interface name work? If not, you can always revert back to regular python dictionary syntax, for example (from my system):
- hosts: localhost
tasks:
- debug: msg=‘{{hostvars[inventory_hostname][“ansible_virbr0”].ipv4.address}}’
Outputs:
TASK: [debug msg=‘{{hostvars[inventory_hostname][“ansible_virbr0”].ipv4.address}}’] ***
ok: [127.0.0.1] => {
“msg”: “192.168.122.1”
}
James,
Escaping the dot didn’t work but below syntax did!!!
Thanks, had tried a lot of possibilities but i probably not this one
Kind regards,
Oliver.