I am having trouble using json_query to search the below data structure from which I want to create two separate lists.
List 1 should contain the name key from each dictionary for entries whose members list contains the subPath key AND whose value contains a specific value.
List 2 should contain the name key from each dictionary for entries whose members list does NOT contain the subPath key and whose name contains a specific value.
The closest I'm able to get thus far is finding those dictionaries whose members dictionary has the subPath
key:
- name: debug
debug:
msg: "{{ device_facts.gtm_a_pools | json_query(query) }}"
vars:
query: "[].members[?!subPath][].name"
or doesn't have the subPath key:
- name: debug
debug:
msg: "{{ device_facts.gtm_a_pools | json_query(query) }}"
vars:
query: "[].members[?subPath][].name"
But this is returning the name key from within the members dictionary, when what I want is the name key from each gtm_a_pools dictionary based on the two above criterion (one list that has the subPath and one list for those without).
Using the below data structure:
- List1 = ['a2-test_pool']
- LIst 2 = ['aci_pool']
"gtm_a_pools": [
{
"alternate_mode": "global-availability",
"dynamic_ratio": "no",
"enabled": "yes",
"fallback_mode": "return-to-dns",
"full_path": "/Common/a2-test_pool",
"load_balancing_mode": "global-availability",
"manual_resume": "no",
"max_answers_returned": 1,
"members": [
{
"disabled": "no",
"enabled": "yes",
"limitMaxBps": 0,
"limitMaxBpsStatus": "disabled",
"limitMaxConnections": 0,
"limitMaxConnectionsStatus": "disabled",
"limitMaxPps": 0,
"limitMaxPpsStatus": "disabled",
"member_order": 0,
"monitor": "default",
"name": "a2-test_443_vs",
"partition": "Common",
"ratio": 1,
"subPath": "test-dmz-dc1-pair:/Common"
},
{
"disabled": "no",
"enabled": "yes",
"limitMaxBps": 0,
"limitMaxBpsStatus": "disabled",
"limitMaxConnections": 0,
"limitMaxConnectionsStatus": "disabled",
"limitMaxPps": 0,
"limitMaxPpsStatus": "disabled",
"member_order": 1,
"monitor": "default",
"name": "dc2-a2-test_443_vs",
"partition": "Common",
"ratio": 1,
"subPath": "test-dmz-dc2-pair:/Common"
}
],
"name": "a2-test_pool",
"partition": "Common",
"qos_hit_ratio": 5,
"qos_hops": 0,
"qos_kilobytes_second": 3,
"qos_lcs": 30,
"qos_packet_rate": 1,
"qos_rtt": 50,
"qos_topology": 0,
"qos_vs_capacity": 0,
"qos_vs_score": 0,
"ttl": 30,
"verify_member_availability": "yes"
},
{
"alternate_mode": "round-robin",
"dynamic_ratio": "no",
"enabled": "yes",
"fallback_mode": "return-to-dns",
"full_path": "/Common/aci_pool",
"load_balancing_mode": "round-robin",
"manual_resume": "no",
"max_answers_returned": 1,
"members": [
{
"disabled": "no",
"enabled": "yes",
"limitMaxBps": 0,
"limitMaxBpsStatus": "disabled",
"limitMaxConnections": 0,
"limitMaxConnectionsStatus": "disabled",
"limitMaxPps": 0,
"limitMaxPpsStatus": "disabled",
"member_order": 0,
"monitor": "default",
"name": "prod_dc1_servers:aci",
"partition": "Common",
"ratio": 1
},
{
"disabled": "no",
"enabled": "yes",
"limitMaxBps": 0,
"limitMaxBpsStatus": "disabled",
"limitMaxConnections": 0,
"limitMaxConnectionsStatus": "disabled",
"limitMaxPps": 0,
"limitMaxPpsStatus": "disabled",
"member_order": 1,
"monitor": "default",
"name": "prod_dc1_servers:aci",
"partition": "Common",
"ratio": 1
}
],
"name": "aci_pool",
"partition": "Common",
"qos_hit_ratio": 5,
"qos_hops": 0,
"qos_kilobytes_second": 3,
"qos_lcs": 30,
"qos_packet_rate": 1,
"qos_rtt": 50,
"qos_topology": 0,
"qos_vs_capacity": 0,
"qos_vs_score": 0,
"ttl": 30,
"verify_member_availability": "yes"
}
]