vmware_guest_network – Manage network adapters of specified virtual machine in given vCenter infrastructure — Ansible Documentation

- AnsibleFest
- Products
- Community
- Webinars & Training
- Blog

Documentation

# vmware_guest_network – Manage network adapters of specified virtual machine in given vCenter infrastructure

New in version 2.9.

- Synopsis
- Requirements
- Parameters
- Notes
- Examples
- Return Values
- Status

## Synopsis

- This module is used to add, reconfigure, remove network adapter of given virtual machine.
- All parameters and VMware object names are case sensitive.

## Requirements

The below requirements are needed on the host that executes this module.

- python >= 2.6
- PyVmomi

## Parameters

Parameter | Choices/Defaults | Comments
--- | --- | ---
cluster string |  | The name of cluster where the virtual machine will run. This is a required parameter, if `esxi_hostname` is not set. `esxi_hostname` and `cluster` are mutually exclusive parameters.
datacenter string | Default: "ha-datacenter" | The datacenter name to which virtual machine belongs to.
esxi_hostname string |  | The ESXi hostname where the virtual machine will run. This is a required parameter, if `cluster` is not set. `esxi_hostname` and `cluster` are mutually exclusive parameters.
folder string |  | Destination folder, absolute or relative path to find an existing guest. This is a required parameter, only if multiple VMs are found with same name. The folder should include the datacenter. ESXi server's datacenter is ha-datacenter. Examples: folder: /ha-datacenter/vm folder: ha-datacenter/vm folder: /datacenter1/vm folder: datacenter1/vm folder: /datacenter1/vm/folder1 folder: datacenter1/vm/folder1 folder: /folder1/datacenter1/vm folder: folder1/datacenter1/vm folder: /folder1/datacenter1/vm/folder2
gather_network_info boolean | Choices: no ← yes | If set to `True`, return settings of all network adapters, other parameters are ignored. If set to `False`, will add, reconfigure or remove network adapters according to the parameters in `networks`. aliases: gather_network_facts
hostname string |  | 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 `VMWARE_HOST` will be used instead. Environment variable support added in Ansible 2.6.
moid string |  | Managed Object ID of the instance to manage if known, this is a unique identifier only within a single vCenter instance. This is required if `name` or `uuid` is not supplied.
name string |  | Name of the virtual machine. This is a required parameter, if parameter `uuid` or `moid` is not supplied.
networks list |  | A list of network adapters. `mac` or `label` or `device_type` is required to reconfigure or remove an existing network adapter. If there are multiple network adapters with the same `device_type`, you should set `label` or `mac` to match one of them, or will apply changes on all network adapters with the `device_type` specified. `mac`, `label`, `device_type` is the order of precedence from greatest to least if all set. Valid attributes are: - `mac` (string): MAC address of the existing network adapter to be reconfigured or removed. - `label` (string): Label of the existing network adapter to be reconfigured or removed, e.g., "Network adapter 1". - `device_type` (string): Valid virtual network device types are: `e1000`, `e1000e`, `pcnet32`, `vmxnet2`, `vmxnet3` (default), `sriov`. Used to add new network adapter, reconfigure or remove the existing network adapter with this type. If `mac` and `label` not specified or not find network adapter by `mac` or `label` will use this parameter. - `name` (string): Name of the portgroup or distributed virtual portgroup for this interface. When specifying distributed virtual portgroup make sure given `esxi_hostname` or `cluster` is associated with it. - `vlan` (integer): VLAN number for this interface. - `dvswitch_name` (string): Name of the distributed vSwitch. This value is required if multiple distributed portgroups exists with the same name. - `state` (string): State of the network adapter. If set to `present`, then will do reconfiguration for the specified network adapter. If set to `new`, then will add the specified network adapter. If set to `absent`, then will remove this network adapter. - `manual_mac` (string): Manual specified MAC address of the network adapter when creating, or reconfiguring. If not specified when creating new network adapter, mac address will be generated automatically. When reconfigure MAC address, VM should be in powered off state. - `connected` (bool): Indicates that virtual network adapter connects to the associated virtual machine. - `start_connected` (bool): Indicates that virtual network adapter starts with associated virtual machine powers on.
password string |  | The password of the vSphere vCenter or ESXi server. If the value is not specified in the task, the value of environment variable `VMWARE_PASSWORD` will be used instead. Environment variable support added in Ansible 2.6. aliases: pass, pwd
port integer added in 2.5 | Default: 443 | The port number of the vSphere vCenter or ESXi server. If the value is not specified in the task, the value of environment variable `VMWARE_PORT` will be used instead. Environment variable support added in Ansible 2.6.
proxy_host string added in 2.9 |  | 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 `VMWARE_PROXY_HOST` will be used instead. This feature depends on a version of pyvmomi greater than v6.7.1.2018.12
proxy_port integer added in 2.9 |  | 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 `VMWARE_PROXY_PORT` will be used instead.
username string |  | The username of the vSphere vCenter or ESXi server. If the value is not specified in the task, the value of environment variable `VMWARE_USER` will be used instead. Environment variable support added in Ansible 2.6. aliases: admin, user
uuid string |  | UUID of the instance to gather info if known, this is VMware's unique identifier. This is a required parameter, if parameter `name` or `moid` is not supplied.
validate_certs boolean | Choices: no yes ← | Allows connection when SSL certificates are not valid. Set to `false` when certificates are not trusted. If the value is not specified in the task, the value of environment variable `VMWARE_VALIDATE_CERTS` will be used instead. Environment variable support added in Ansible 2.6. If set to `yes`, please make sure Python >= 2.7.9 is installed on the given machine.

## Notes

Note

- Tested on vSphere 6.0, 6.5 and 6.7

## Examples

    - name: Change network adapter settings of virtual machine
      vmware_guest_network:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        datacenter: "{{ datacenter_name }}"
        validate_certs: no
        name: test-vm
        gather_network_info: false
        networks:
          - name: "VM Network"
            state: new
            manual_mac: "00:50:56:11:22:33"
          - state: present
            device_type: e1000e
            manual_mac: "00:50:56:44:55:66"
          - state: present
            label: "Network adapter 3"
            connected: false
          - state: absent
            mac: "00:50:56:44:55:77"
      delegate_to: localhost
      register: network_info

    - name: Change network adapter settings of virtual machine using MoID
      vmware_guest_network:
        hostname: "{{ vcenter_hostname }}"
        username: "{{ vcenter_username }}"
        password: "{{ vcenter_password }}"
        datacenter: "{{ datacenter_name }}"
        validate_certs: no
        moid: vm-42
        gather_network_info: false
        networks:
          - state: absent
            mac: "00:50:56:44:55:77"
      delegate_to: localhost

## Return Values

Common return values are documented here, the following are the fields unique to this module:

Key | Returned | Description
--- | --- | ---
network_data dictionary | always | metadata about the virtual machine's network adapter after managing them Sample: {'0': {'label': 'Network Adapter 1', 'name': 'VM Network', 'device_type': 'E1000E', 'mac_addr': '00:50:56:89:dc:05', 'unit_number': 7, 'wake_onlan': False, 'allow_guest_ctl': True, 'connected': True, 'start_connected': True}}

## Status

- This module is not guaranteed to have a backwards compatible interface. [preview]
- This module is maintained by the Ansible Community. [community]

### Authors

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

Hint

If you notice any issues in this documentation, you can edit this document to improve it.