Hello!
I am currently writing role which is supposed to automate creation of GRE tunnels between endpoints .
So I created new role and it uses variable named gre_tunnels which is list. It usually looks like this:
gre_tunnels:
- name: lb1-app1
ttl: 64
local:
addr: “{{lxc_gre_ip}}”
endpoint: “{{ansible_eth0.ipv4.address}}”
network: “{{lxc_subnet}}”
cidr: “{{lxc_subnet_bits}}”
remote:
addr: “{{hostvars[‘app1’][‘lxc_gre_ip’]}}”
endpoint: “{{hostvars[‘app1’][‘ansible_eth0’][‘ipv4’][‘address’]}}”
network: “{{hostvars[‘app1’][‘lxc_subnet’]}}”
cidr: “{{hostvars[‘app1’][‘lxc_subnet_bits’]}}”
This role doesn’t do anything particularly fancy, it iterates gre_tunnels list by means of ‘with_items’,
then generates interface definitions for Debian/Ubuntu , brings interfaces up and generates firewall configuration.
My problem is:
I noticed that when I use templates in host_vars like in example above not all of them are rendered.
Specifically ‘local’ hash variable values will be correctly presented while ‘remote’ hash values will be rendered incorrectly.
If I try to use values from this hash in a ‘template’ module variable values look like ‘{#hostvars[‘app1’][‘lxc_gre_ip’]#}’ (without quotes).
Problem exists in every ‘{{ }}’ jinja block when hostvars are referenced inside . I’m not sure whether it’s a bug or I am doing something stupid.
My idea of templating in host_vars is based on assumption that it would be a good idea not to force myself to change IP addresses in multiple places
( You probably know DRY principle and all that stuff )
So, what should I do next?