0

I have 100 VMs, and each of them needs to create 3+ port groups in vmWare vDS with its own VLAN.

lets take for example only 9 VMs.

For each VM needs to be created 3+ port groups with names like:

  • "vDS VM 1 vlan 11"
  • "vDS VM 1 vlan 21"
  • "vDS VM 1 vlan 31"

Numbers in the VLAN 31: 3 = VLAN number, 1 = VM number.

Vlan numbers for each VM can be different, it may be only 1 or even 7

Ive tried to use:

  - name: "vm vars"
    ansible.builtin.include_vars:
      file: new_portgroup_vars.yml
      name: new_portgroup_vars

  - name: Create vlan portgroup for vDS with security policies
    community.vmware.vmware_dvs_portgroup:
      validate_certs: False
      hostname: "{{ secret_vars.vcenter_server }}"
      username: "{{ secret_vars.vcenter_user }}"
      password: "{{ secret_vars.vcenter_pass }}"
      portgroup_name: "vDS vm {{item.vm}} vlan {{item.vlan_id}}"
      switch_name: "vDS_test"
      vlan_id: "{{item.vlan_id}}"
      num_ports: 8
      port_binding: "static"
      port_allocation: "elastic"
      state: present
      network_policy:
        inherited: false
        promiscuous: false
        forged_transmits: true
        mac_changes: true
    delegate_to: localhost
    loop: "{{ new_portgroup_vars.new_portgroup }}"

new_portgroup_vars.yml

new_portgroup:

#vm 1
  - {vm: 1, vlan_id: 11}
  - {vm: 1, vlan_id: 21}
  - {vm: 1, vlan_id: 31}
#vm 2
  - {vm: 2, vlan_id: 12}
  - {vm: 2, vlan_id: 22}
  - {vm: 2, vlan_id: 32}
  - {vm: 2, vlan_id: 42}
  - {vm: 2, vlan_id: 52}

The code is working, but I've stuck by trying to minimize the vars file by using something like:

new_portgroup:
  - {vm: 1, vlan_id: [11, 21, 31]}
  - {vm: 2, vlan_id: [12, 22, 32, 42, 52]}

Any advice?

0 Answers0