0

On Ansible 2.9 I'm using the community.vmware collection in order to deploy VM's and increase resources on existing VMs (CPU,RAM,HDD and NICs) I'm struggling with the last once since I need to specify the first network to add a 2nd one (otherwise it will replace it) I'm using the vmware_guest module because it allows me to add the network configuration, here's an example of the playbook:

- name: Add NIC
  vmware_guest:
    validate_certs: False
    hostname: "{{ hostname }}"
    username: "{{ username }}"
    password: "{{ password }}"
    datacenter: "{{ datacenter }}"
    name: "{{ name_new_vm }}"
    networks:
###First Network, its actual value is just for testing
      - name: "{{ resulta.dvs_portgroups[0].name }}"
###Second Network, it's possible to use either portgroup name or vlan ID
      - vlan: 1001
        start_connected: true
      ###More Data (IP,Netmask,Gat)
  register: deploy_vm

There's also a module called vmware_guest_network_module which can add a 2nd NIC without specifying the previous networks, the problem is I still need to add a network config so vmware_guest and the 1st network are still mandatory

- name: Obtener info de redes previas
  vmware_guest_network:
    validate_certs: False
    hostname: "{{ hostname }}"
    username: "{{ username }}"
    password: "{{ password }}"
    datacenter: "{{ datacenter }}"
    name: "{{ name_new_vm }}"
    networks:
      - name: "{{ network_name }}"
        state: new
  register: results

In addition I found vmware_guest_info and vmware_guest_network(gather_network_info parameter) to gather info about the NICs on the VM but none of them are giving me the portgroup name nor vlanid to get their values

        "network_data": {
            "0": {
                "allow_guest_ctl": true,
                "connected": true,
                "device_type": "VMXNET3",
                "label": "Network adapter 1",
                "mac_addr": "00:50:56:83:7c:b5",
                "name": "DVSwitch: 5d 2e 03 50 b0 18 04 00-40 1c da 92 69 e7 f4 5e",
                "start_connected": true,
                "unit_number": 7,
                "wake_onlan": true
            },

How can I get the portgroup name or the Vlan Id? I know vmware_dvs_portgroup_find exists but there are hundres of VLANS in the dvswitch so it won't help

Greens
  • 3
  • 6

0 Answers0