When I run the following task:
- name: Get info about DVPG
community.vmware.vmware_dvs_portgroup_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ datacenter_name }}"
validate_certs: no
register: dvpg_var
It returns the following result:
{
"dvpg_var":{
"changed":false,
"dvs_portgroup_info":{
"WIFI-NEPTUNE":[
{
"active_uplinks":[
"lag1"
],
"description":null,
"dvswitch_name":"WIFI-NEPTUNE",
"key":"dvportgroup-3000",
"mac_learning":{
"allow_unicast_flooding":null,
"enabled":false,
"limit":null,
"limit_policy":null
},
"network_policy":{
"forged_transmits":true,
"mac_changes":true,
"promiscuous":false
},
"num_ports":4,
"port_allocation":"elastic",
"port_binding":"static",
"port_policy":{
"block_override":true,
"ipfix_override":false,
"live_port_move":false,
"network_rp_override":false,
"port_config_reset_at_disconnect":true,
"security_override":false,
"shaping_override":false,
"traffic_filter_override":false,
"uplink_teaming_override":false,
"vendor_config_override":false,
"vlan_override":false
},
"portgroup_name":"VLAN100",
"standby_uplinks":[
],
"teaming_policy":{
"inbound_policy":true,
"notify_switches":true,
"policy":"loadbalance_srcid",
"rolling_order":false
},
"type":"earlyBinding",
"vlan_info":{
}
}
],
"WIFI-SATURNO":[
{
"active_uplinks":[
"lag2"
],
"description":null,
"dvswitch_name":"WIFI-SATURNO",
"key":"dvportgroup-3001",
"mac_learning":{
"allow_unicast_flooding":null,
"enabled":false,
"limit":null,
"limit_policy":null
},
"network_policy":{
"forged_transmits":true,
"mac_changes":true,
"promiscuous":false
},
"num_ports":4,
"port_allocation":"elastic",
"port_binding":"static",
"port_policy":{
"block_override":true,
"ipfix_override":false,
"live_port_move":false,
"network_rp_override":false,
"port_config_reset_at_disconnect":true,
"security_override":false,
"shaping_override":false,
"traffic_filter_override":false,
"uplink_teaming_override":false,
"vendor_config_override":false,
"vlan_override":false
},
"portgroup_name":"VLAN101",
"standby_uplinks":[
],
"teaming_policy":{
"inbound_policy":true,
"notify_switches":true,
"policy":"loadbalance_srcid",
"rolling_order":false
},
"type":"earlyBinding",
"vlan_info":{
}
}
]
}
}
}
I'm unable to find a way to iterate, loop or only retrieve the portgroup_name
values.
I tried to do this:
- name: Get portgroup_name list
debug:
msg: "{{ dvpg_var.dvs_portgroup_info['WIFI-NEPTUNE'] | json_query('[*].portgroup_name') }}"
It works, but it's not what I need. Instead of specifying dvpg_var.dvs_portgroup_info['WIFI-NEPTUNE']
, I want to iterate over the keys under dvpg_var.dvs_portgroup_info
.