- vlanid: vlan1
vlan: 1
dvs: DSwitch1
numports: 128
- vlanid: vlan2
vlan: 2
dvs: DSwitch1
numports: 128
- vlanid: vlan1
vlan: 1
dvs: DSwitch2
numports: 128
- vlanid: vlan2
vlan: 2
dvs: DSwitch2
numports: 128
- vlanid: vlan1
vlan: 1
dvs:
- DSwitch1
- DSwitch2
numports: 128
- vlanid: vlan2
vlan: 2
dvs:
-DSwitch2
numports: 128
Playbook.yml
- name: Create DVS portgroup
vmware_dvs_portgroup:
hostname: "{{secret.vcenter}}"
username: "{{secret.vcusername}}"
password: "{{secret.vcpassword}}"
validate_certs: no
portgroup_name: "{{item.vlanid}}"
vlan_id: "{{item.vlan}}"
portgroup_type: earlyBinding
num_ports: "{{item.numports}}"
state: present
switch_name: "{{item.dvs}}"
loop: "{{config.vlans}}"
Hi Barry,
Ansible 2.7 has subelements filter, which makes this rather easy.
Given your second struct:
vars:
vmds:
- vlanid: vlan1
vlan: 1
dvs:
- DSwitch1
- DSwitch2
numports: 128
- vlanid: vlan2
vlan: 2
dvs:
- DSwitch2
numports: 128
You can loop over the vswitches with the help of the subelements filter:
- debug:
var: vlans
vars:
vlans: "{{ vmds | subelements('dvs', skip_missing=True) }}"
So, you should be able to create the port groups like this:
- name: Create DVS portgroup
vmware_dvs_portgroup:
hostname: "{{secret.vcenter}}"
username: "{{secret.vcusername}}"
password: "{{secret.vcpassword}}"
validate_certs: no
portgroup_name: "{{ item.0.vlanid }}"
vlan_id: "{{item.0.vlan}}"
portgroup_type: earlyBinding
num_ports: "{{item.0.numports}}"
state: present
switch_name: "{{item.1}}"
loop: "{{ vmds | subelements('dvs', skip_missing=True) }}"
--
Eino Tuominen