Template the physical host address

In the scenario where the fallback group 'all' is used to find the
physical host address, there are typically containers present in this
group with ansible_host settings like "{{ container_name }}".

When this happens, you get physical_host_addrs lists like:
aiotest1 127.0.0.1
test1 1.1.1.1
test-1-zbx1 {{ container_name }}
test-1-cdns1 {{ container_name }}
test-1-lb1 {{ container_name }}
test-1-lb2 {{ container_name }}
fatal: [aiotest1]: FAILED! => {"msg": "'container_name' is undefined"}

To avoid this we need to run the physical_host_addr through a templar
loaded with the physical_host_vars:

aiotest1 127.0.0.1
test1 1.1.1.1
test-1-zbx1 test-1-zbx1
test-1-cdns1 test-1-cdns1
test-1-lb1 test-1-lb1
test-1-lb2 test-1-lb2
test-1-tpxy1 test-1-tpxy1
ok: [aiotest1]

Change-Id: I7a4e89c579a3e688decaeb91b9035500129c7b16
This commit is contained in:
Logan V 2018-06-29 23:44:37 -05:00
parent 054e504036
commit a743d4c81f
1 changed files with 5 additions and 2 deletions

View File

@ -135,8 +135,11 @@ class StrategyModule(LINEAR.StrategyModule):
physical_host_vars = self._variable_manager.get_vars(
host=self._inventory.get_host(physical_host)
)
physical_host_addr = physical_host_vars.get('ansible_host',
physical_host)
physical_host_templar = LINEAR.Templar(loader=self._loader,
variables=physical_host_vars)
physical_host_addr = physical_host_templar.template(
physical_host_vars.get('ansible_host',
physical_host))
physical_host_addrs[physical_host] = physical_host_addr
task_vars['physical_host_addrs'] = physical_host_addrs