vmware_dvswitch – Create or remove a Distributed Switch

New in version 2.0.

Synopsis

  • This module can be used to create, remove a Distributed Switch.

Requirements

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

  • python >= 2.6

  • PyVmomi

Parameters

Parameter Choices/Defaults Comments
contact
dictionary
added in 2.8
Dictionary which configures administrtor contact name and description for the Distributed Switch.
Valid attributes are:
- name (str): Administrator name.
- description (str): Description or other details.
datacenter_name
- / required
The name of the datacenter that will contain the Distributed Switch.

aliases: datacenter
description
string
added in 2.8
Description of the Distributed Switch.
discovery_operation
-
    Choices:
  • both
  • advertise
  • listen ←
Select the discovery operation.
Required parameter for state both present and absent, before Ansible 2.6 version.
Required only if state is set to present, for Ansible 2.6 and onwards.
discovery_proto
-
    Choices:
  • cdp ←
  • lldp
  • disabled
Link discovery protocol between Cisco and Link Layer discovery.
Required parameter for state both present and absent, before Ansible 2.6 version.
Required only if state is set to present, for Ansible 2.6 and onwards.
cdp: Use Cisco Discovery Protocol (CDP).
lldp: Use Link Layer Discovery Protocol (LLDP).
disabled: Do not use a discovery protocol.

aliases: discovery_protocol
health_check
dictionary
added in 2.8
Default:
{"teaming_failover": false, "teaming_failover_interval": 0, "vlan_mtu": false, "vlan_mtu_interval": 0}
Dictionary which configures Health Check for the Distributed Switch.
Valid attributes are:
- vlan_mtu (bool): VLAN and MTU health check. (default: False)
- teaming_failover (bool): Teaming and failover health check. (default: False)
- vlan_mtu_interval (int): VLAN and MTU health check interval (minutes). (default: 0)
- The default for vlan_mtu_interval is 1 in the vSphere Client if the VLAN and MTU health check is enabled.
- teaming_failover_interval (int): Teaming and failover health check interval (minutes). (default: 0)
- The default for teaming_failover_interval is 1 in the vSphere Client if the Teaming and failover health check is enabled.
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.
mtu
integer
Default:
1500
The switch maximum transmission unit.
Required parameter for state both present and absent, before Ansible 2.6 version.
Required only if state is set to present, for Ansible 2.6 and onwards.
Accepts value between 1280 to 9000 (both inclusive).
multicast_filtering_mode
string
added in 2.8
    Choices:
  • basic ←
  • snooping
The multicast filtering mode.
basic mode: multicast traffic for virtual machines is forwarded according to the destination MAC address of the multicast group.
snooping mode: the Distributed Switch provides IGMP and MLD snooping according to RFC 4541.
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.
state
-
    Choices:
  • present ←
  • absent
If set to present and the Distributed Switch doesn't exists then the Distributed Switch will be created.
If set to absent and the Distributed Switch exists then the Distributed Switch will be deleted.
switch_name
- / required
The name of the distribute vSwitch to create or remove.

aliases: switch, dvswitch
switch_version
-
added in 2.5
    Choices:
  • 5.0.0
  • 5.1.0
  • 5.5.0
  • 6.0.0
  • 6.5.0
  • 6.6.0
The version of the Distributed Switch to create.
Can be 6.0.0, 5.5.0, 5.1.0, 5.0.0 with a vCenter running vSphere 6.0 and 6.5.
Can be 6.6.0, 6.5.0, 6.0.0 with a vCenter running vSphere 6.7.
The version must macht the version of the ESXi hosts you want to connect.
The version of the vCenter server is used if not specified.
Required only if state is set to present.

aliases: version
uplink_prefix
-
added in 2.8
Default:
"Uplink "
The prefix used for the naming of the uplinks.
Only valid if the Distributed Switch will be created. Not used if the Distributed Switch is already present.
Uplinks are created as Uplink 1, Uplink 2, etc. pp. by default.
uplink_quantity
-
Quantity of uplink per ESXi host added to the Distributed Switch.
The uplink quantity can be increased or decreased, but a decrease will only be successfull if the uplink isn't used by a portgroup.
Required parameter for state both present and absent, before Ansible 2.6 version.
Required only if state is set to present, for Ansible 2.6 and onwards.
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
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.5 and 6.7

Examples

- name: Create dvSwitch
  vmware_dvswitch:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter: '{{ datacenter }}'
    switch: dvSwitch
    version: 6.0.0
    mtu: 9000
    uplink_quantity: 2
    discovery_protocol: lldp
    discovery_operation: both
    state: present
  delegate_to: localhost

- name: Create dvSwitch with all options
  vmware_dvswitch:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter: '{{ datacenter }}'
    switch: dvSwitch
    version: 6.5.0
    mtu: 9000
    uplink_quantity: 2
    uplink_prefix: 'Uplink_'
    discovery_protocol: cdp
    discovery_operation: both
    multicast_filtering_mode: snooping
    health_check:
      vlan_mtu: true
      vlan_mtu_interval: 1
      teaming_failover: true
      teaming_failover_interval: 1
    state: present
  delegate_to: localhost

- name: Delete dvSwitch
  vmware_dvswitch:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter: '{{ datacenter }}'
    switch: dvSwitch
    state: absent
  delegate_to: localhost

Return Values

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

Key Returned Description
result
string
always
information about performed operation

Sample:
{'changed': False, 'contact': None, 'contact_details': None, 'description': None, 'discovery_operation': 'both', 'discovery_protocol': 'cdp', 'dvswitch': 'test', 'health_check_teaming': False, 'health_check_teaming_interval': 0, 'health_check_vlan': False, 'health_check_vlan_interval': 0, 'mtu': 9000, 'multicast_filtering_mode': 'basic', 'result': 'DVS already configured properly', 'uplink_quantity': 2, 'uplinks': ['Uplink_1', 'Uplink_2'], 'version': '6.6.0'}


Status

Authors

  • Joseph Callen (@jcpowermac)

  • Abhijeet Kasurde (@Akasurde)

  • Christian Kotte (@ckotte)

Hint

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