---
- name: Consolidate output
hosts: localhost
gather_facts: no
vars:
data_set_1:
host1:
field1: '1'
field2: '2'
host2:
field3: '3'
field4: '4'
host3:
field1: '1'
field3: '3'
host4:
field5: '5'
field6: '6'
data_set_2:
- host1
- host2
- host3
I just need to parse through both the data sets and build the list of fields and the value for hosts in data set 2.
For example, data_set_2 has three hosts host1, 2 and 3. Corresponding data from data_set_1 for host1, 2 and 3 is host1: field1: '1' field2: '2' host2: field3: '3' field4: '4' host3: field1: '1' field3: '3'
From this, I just need to build the result like this.
result = {
field1: "1",
field2: "2",
field3: "3",
field4: "4"
}
How can I do this from ansible playbook?