ansible-collection-icinga
ansible-collection-icinga copied to clipboard
Variable expansion breaks when calling vars['key']
Like described in #266 variable expansion can break when referring a variable via vars['key'] instead of using key directly.
This can be a problem if, e.g., you want to define some components of say icingaweb2 within your hostvars and want to refer to them in your playbook's vars key.
Example:
test.yml
---
- name: Test
hosts: localhost
vars:
foo: "{{ bar }}"
tasks:
- name: Directly
debug:
msg: "{{ foo }}"
- name: Via vars
debug:
msg: "{{ vars['foo'] }}"
ansible-playbook --connection local -i localhost, test.yml -e bar=value
Output:
PLAY [Test] ******************************************************************************************************
TASK [Gathering Facts] *******************************************************************************************
ok: [localhost]
TASK [Directly] **************************************************************************************************
ok: [localhost] => {
"msg": "value"
}
TASK [Via vars] **************************************************************************************************
ok: [localhost] => {
"msg": "{{ bar }}"
}
PLAY RECAP *******************************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Proposed solution
Like it was previously fixed for icinga2 in #266 we could change all occurrences of vars[key].sub.key... to just key.sub.key... within all roles.