vmware_host - Add / Remove ESXi host to / from vCenter

New in version 2.0.

Synopsis

  • This module can be used to add / remove / reconnect an ESXi host to / from vCenter.

Requirements

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

  • python >= 2.6
  • PyVmomi

Parameters

Parameter Choices/Defaults Comments
cluster_name
required
Name of the cluster to add the host.
Required parameter from version 2.5.
datacenter_name
required
Name of the datacenter to add the host.
esxi_hostname
required
ESXi hostname to manage.
esxi_password
ESXi password.
Required for adding a host.
Optional for reconnect.
Unused for removing.
No longer required parameter from version 2.5.
esxi_ssl_thumbprint
(added in 2.5)
Default:
Specifying the hostsystem's certificate's thumbprint.
Use following command to get hostsystem's certificate's thumbprint -
# openssl x509 -in /etc/vmware/ssl/rui.crt -fingerprint -sha1 -noout
esxi_username
ESXi username.
Required for adding a host.
Optional for reconnect.
Unused for removing.
No longer required parameter from version 2.5.
hostname
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 supported added in version 2.6.
password
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 supported added in version 2.6.

aliases: pass, pwd
port
(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 supported added in version 2.6.
state
    Choices:
  • present
  • absent
  • add_or_reconnect
  • reconnect
present: add the host if it's absent else do nothing.
absent: remove the host if it's present else do nothing.
add_or_reconnect: add the host if it's absent else reconnect it.
reconnect: reconnect the host if it's present else fail.
username
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 supported added in version 2.6.

aliases: user, admin
validate_certs
    Choices:
  • no
  • yes
Default:
True
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 supported added in version 2.6.

Notes

Note

  • Tested on vSphere 5.5

Examples

- name: Add ESXi Host to vCenter
  vmware_host:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter_name: datacenter_name
    cluster_name: cluster_name
    esxi_hostname: '{{ esxi_hostname }}'
    esxi_username: '{{ esxi_username }}'
    esxi_password: '{{ esxi_password }}'
    state: present

- name: Reconnect ESXi Host (with username/password set)
  vmware_host:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter_name: datacenter_name
    cluster_name: cluster_name
    esxi_hostname: '{{ esxi_hostname }}'
    esxi_username: '{{ esxi_username }}'
    esxi_password: '{{ esxi_password }}'
    state: reconnect

- name: Reconnect ESXi Host (with default username/password)
  vmware_host:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter_name: datacenter_name
    cluster_name: cluster_name
    esxi_hostname: '{{ esxi_hostname }}'
    state: reconnect

- name: Add ESXi Host with SSL Thumbprint to vCenter
  vmware_host:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter_name: datacenter_name
    cluster_name: cluster_name
    esxi_hostname: '{{ esxi_hostname }}'
    esxi_username: '{{ esxi_username }}'
    esxi_password: '{{ esxi_password }}'
    esxi_ssl_thumbprint: "3C:A5:60:6F:7A:B7:C4:6C:48:28:3D:2F:A5:EC:A3:58:13:88:F6:DD"
    state: present

Status

This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

Author

  • Joseph Callen (@jcpowermac)
  • Russell Teague (@mtnbikenc)
  • Maxime de Roucy (@tchernomax)

Hint

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

© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.5/modules/vmware_host_module.html