Hi,
I am having a variable replaced with the contents of another (which has a completely different name). This is the relevant part of my task file, which installs a new version of the application I’m supporting. This part checks if we are actually going to install, and shuts it down if we are:
`
- block:
- debug: msg={{ customer }}
stop the running instance, if it exists (if it doesn’t exist, then the version is set to ‘not_found’)
- name: Stop the installed domain
include: appctl.yml action=stop
when: “{{ ‘not_found’ != hostvars[inventory_hostname][‘app_info_’ ~ customer][‘version’] }}”
`
This is not the whole playbook, of course. I added the “debug” line just to show how the value changes between lines (the variable being messed up here is “customer”. The output of this fragment is:
TASK [node_servers : debug msg={{ customer }}] ********************************* ok: [server.example.com] => { "changed": false, "msg": "test" } TASK [node_servers : Stop the installed instance] ******************************** included: /path/to/roles/node_servers/tasks/avpsctl.yml for server.example.com TASK [node_servers : Stop nodes] *********************************************** fatal: [server.example.com]: FAILED! => {"failed": true, "msg": "ERROR! The conditional check '{{ 'not_found' != hostvars[inventory_hostname]['app_info_' ~ customer]['version'] }}' failed. The error was: ERROR! 'dict' object has no attribute u\"app_info_{u'name': 'anotherserver.example.com', u'port': 9000}\""}
The debug task outputs the correct value (“test”), while in the templated conditional it gets changed to a dict (by the way, initially I was using “+” for concatenation and lost a couple hours with a “cannot concatenate str and dict” error…). That dict is defined earlier in the playbook, in an included var file whose path depends on “customer”, but that is where the relation ends.
I’ll try to come up with a reduced sample to demonstrate the error, in the meantime: is this a known issue? any place where to look for a solution?
Thanks and regards