I would like to be able to reference the direct parent of an ansible host as a variable.
Take the following example inventory:
[resourcegroup1]
host1
host2
[resourcegroup2]
host3
host4
[application:children]
[resourcegroup1]
[database:children]
[resourcegroup2]
[environoments:children]
[application]
[database]
[enivronoments]
dev
staging
prod
I would like to run a looping task in a play which can reference a hosts parent. Example:
tasks:
- name: Start Datanbase Servers
with_items: "{{ groups['database'] }}"
azure_rm_virtualmachine:
name: "{{ item }}"
resource_group: "{{ item.parent }}"
started: yes
allocated: yes
{{ item }} would iterate through the values of "host3" and "host4" while I am looking for what I could put in place of {{ item.parent }} that would be the hosts direct parent, in this case: "resourcegroup2".
Is there any way to reference the hierarchy of an inventory?