community.vmware.vmware_guest_network (4.2.0) — module

Manage network adapters of specified virtual machine in given vCenter infrastructure

Authors: Diane Wang (@Tomorrow9) <dianew@vmware.com>

Install collection

Install with ansible-galaxy collection install community.vmware:==4.2.0


Add to requirements.yml

  collections:
    - name: community.vmware
      version: 4.2.0

Description

This module is used to add, reconfigure, remove network adapter of given virtual machine.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: change network for 00:50:56:11:22:33 on vm01.domain.fake
  community.vmware.vmware_guest_network:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    datacenter: "{{ datacenter_name }}"
    name: vm01.domain.fake
    mac_address: 00:50:56:11:22:33
    network_name: admin-network
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: add a nic on network with vlan id 2001 for 422d000d-2000-ffff-0000-b00000000000
  community.vmware.vmware_guest_network:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    datacenter: "{{ datacenter_name }}"
    uuid: 422d000d-2000-ffff-0000-b00000000000
    vlan_id: 2001
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: remove nic with mac 00:50:56:11:22:33 from vm01.domain.fake
  community.vmware.vmware_guest_network:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    datacenter: "{{ datacenter_name }}"
    mac_address: 00:50:56:11:22:33
    name: vm01.domain.fake
    state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: add multiple nics to vm01.domain.fake
  community.vmware.vmware_guest_network:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    datacenter: "{{ datacenter_name }}"
    name: vm01.domain.fake
    state: present
    vlan_id: "{{ item.vlan_id | default(omit) }}"
    network_name: "{{ item.network_name | default(omit) }}"
    connected: "{{ item.connected | default(omit) }}"
  loop:
    - vlan_id: 2000
      connected: false
    - network_name: guest-net
      connected: true

Inputs

    
moid:
    description:
    - Managed Object ID of the instance to manage if known, this is a unique identifier
      only within a single vCenter instance.
    - Required if O(uuid) or O(name) is not supplied.
    type: str

name:
    description:
    - Name of virtual machine
    - Required if O(uuid) or O(moid) is not supplied.
    type: str

port:
    default: 443
    description:
    - The port number of the vSphere vCenter or ESXi server.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_PORT)
      will be used instead.
    type: int

uuid:
    description:
    - vm uuid
    - Required if O(name) or O(moid) is not supplied.
    type: str

force:
    default: false
    description:
    - Force adapter creation even if an existing adapter is attached to the same network.
    type: bool

label:
    description:
    - Label of the NIC that should be altered. O(mac_address) or O(label) should be set
      to get the corresponding device to reconfigure.
    - Alter the name of the network adapter.
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - NIC state.
    - When V(present), a nic will be added if a mac address or label does not previously
      exists or is unset.
    - When V(absent), the O(mac_address) parameter has to be set.
    type: str

folder:
    description:
    - Folder location of given VM, this is only required when there's multiple VM's with
      the same name.
    type: str

switch:
    description:
    - Name of the (dv)switch for destination network, this is only required for dvswitches.
    type: str

cluster:
    description:
    - Name of cluster where VM belongs to.
    type: str

vlan_id:
    description:
    - VLAN id associated with the network.
    type: int

hostname:
    description:
    - The hostname or IP address of the vSphere vCenter or ESXi server.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_HOST)
      will be used instead.
    type: str

password:
    aliases:
    - pass
    - pwd
    description:
    - The password of the vSphere vCenter or ESXi server.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_PASSWORD)
      will be used instead.
    type: str

username:
    aliases:
    - admin
    - user
    description:
    - The username of the vSphere vCenter or ESXi server.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_USER)
      will be used instead.
    type: str

connected:
    default: true
    description:
    - If NIC should be connected to the network.
    type: bool

datacenter:
    default: ha-datacenter
    description:
    - Datacenter the VM belongs to.
    type: str

proxy_host:
    description:
    - Address of a proxy that will receive all HTTPS requests and relay them.
    - The format is a hostname or a IP.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_PROXY_HOST)
      will be used instead.
    required: false
    type: str

proxy_port:
    description:
    - Port of the HTTP proxy that will receive all HTTPS requests and relay them.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_PROXY_PORT)
      will be used instead.
    required: false
    type: int

wake_onlan:
    default: false
    description:
    - Enable wake on LAN.
    type: bool

device_type:
    default: vmxnet3
    description:
    - Type of virtual network device.
    - Valid choices are - V(e1000), V(e1000e), V(pcnet32), V(vmxnet2), V(vmxnet3) (default),
      V(sriov), V(pvrdma).
    type: str

mac_address:
    description:
    - MAC address of the NIC that should be altered, if a MAC address is not supplied
      a new nic will be created.
    - Required when O(state=absent).
    type: str

network_name:
    description:
    - Name of network in vSphere.
    type: str

directpath_io:
    default: false
    description:
    - Enable Universal Pass-through (UPT).
    - Only compatible with the O(device_type=vmxnet3).
    type: bool

esxi_hostname:
    description:
    - The hostname of the ESXi host where the VM belongs to.
    type: str

guest_control:
    default: true
    description:
    - Enables guest control over whether the connectable device is connected.
    type: bool

validate_certs:
    default: true
    description:
    - Allows connection when SSL certificates are not valid. Set to V(false) when certificates
      are not trusted.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_VALIDATE_CERTS)
      will be used instead.
    type: bool

start_connected:
    default: true
    description:
    - If NIC should be connected to network on startup.
    type: bool

use_instance_uuid:
    default: false
    description:
    - Whether to use the VMware instance UUID rather than the BIOS UUID.
    type: bool

gather_network_info:
    aliases:
    - gather_network_facts
    default: false
    description:
    - Return information about current guest network adapters.
    type: bool

pvrdma_device_protocol:
    description:
    - The PVRDMA device protocol used. Valid choices are - V(rocev1), V(rocev2).
    - This parameter is only used on the VM with hardware version >=14 and <= 19.
    type: str
    version_added: 3.3.0
    version_added_collection: community.vmware

virtual_function_backing:
    description:
    - If set, specifies the PCI ID of the physical function to use as backing for a SR-IOV
      network adapter.
    - This option is only compatible for SR-IOV network adapters.
    type: str

allow_guest_os_mtu_change:
    default: true
    description:
    - Allows the guest OS to change the MTU on a SR-IOV network adapter.
    - This option is only compatible for SR-IOV network adapters.
    type: bool

physical_function_backing:
    description:
    - If set, specifies the PCI ID of the physical function to use as backing for a SR-IOV
      network adapter.
    - This option is only compatible for SR-IOV network adapters.
    type: str

Outputs

network_data:
  description: For backwards compatibility, metadata about the virtual machine network
    adapters
  returned: when using gather_network_info parameter
  sample:
    network_data:
      '0':
        allow_guest_ctl: true
        connected: true
        device_type: vmxnet3
        label: Network adapter 2
        mac_addr: 00:50:56:AA:AA:AA
        mac_address: 00:50:56:AA:AA:AA
        name: admin-net
        network_name: admin-net
        start_connected: true
        switch: vSwitch0
        unit_number: 8
        vlan_id: 10
        wake_onlan: false
      '1':
        allow_guest_ctl: true
        connected: true
        device_type: vmxnet3
        label: Network adapter 1
        mac_addr: 00:50:56:BB:BB:BB
        mac_address: 00:50:56:BB:BB:BB
        name: guest-net
        network_name: guest-net
        start_connected: true
        switch: vSwitch0
        unit_number: 7
        vlan_id: 10
        wake_onlan: true
  type: dict
network_info:
  description: metadata about the virtual machine network adapters
  returned: always
  sample:
    network_info:
    - allow_guest_ctl: true
      connected: true
      device_type: vmxnet3
      label: Network adapter 2
      mac_address: 00:50:56:AA:AA:AA
      network_name: admin-net
      start_connected: true
      switch: vSwitch0
      unit_number: 8
      vlan_id: 10
      wake_onlan: false
    - allow_guest_ctl: true
      connected: true
      device_type: vmxnet3
      label: Network adapter 1
      mac_address: 00:50:56:BB:BB:BB
      network_name: guest-net
      start_connected: true
      switch: vSwitch0
      unit_number: 7
      vlan_id: 10
      wake_onlan: true
  type: list