I'm stuck trying to use a variable in another variable declaration. Here is the code in my playbook:
- hosts: operate
roles:
- { role: dns, vargroup: 'test' }
- hosts: test
roles:
- common
- certbot
- ...
And now the very first lines of my dns role:
- debug: var=vargroup
- name: Extracting IP(s) {{vargroup}}
vars:
extractip: "{{ hostvars[groups['{{ vargroup }}'][0]]['ip'] }}"
set_fact:
newip: "{{ item.expose }}"
with_items:
- '{{ extractip }}'
Vargroup is correclty printed in debug and my task name. But in the extractip part, i've got this error:
{
"msg": "'dict object' has no attribute '{{ vargroup }}'",
"_ansible_no_log": false
}
Obviously, i've try hardcoding the line like:
extractip: "{{ hostvars[groups['test'][0]]['ip'] }}"
And it worked like a charm. I really don't know how to use this var in my var declaration :)