I’m trying to do something complex with variables that allows me to auto-generate kickstart files for the VMs in my inventory. It almost works but I’m getting an odd error. The variables are spread across multiple files so here is an example:
group_vars/all
prod_vlan12_network_gateway: 192.168.12.1
host_vars/host.domain.com
default_gateway: “{{ prod_vlan12_network_gateway }}”
(The host variable references the global one, DRY style.)
role/kickstart
I have a template in this role that references the host variable like this: {{ hostvars[item][‘default_gateway’] }}
where item comes from a: “with_items: groups[‘vms’]” statement in the role’s task file
The overall pattern works fine except in this case where the host variable references a global one. In this case the template output is, “{{ prod_vlan12_network_gateway }}” rather than the expected “192.168.12.1”. In cases where the host variable is defined directly, e.g. “vcpus: 2”, it works fine.
I do this to avoid repeating data like the gateway IP address multiple times. Is there a Jinja trick or something else I can try to get it resolve these nested variables?
Thanks,
Aaron