community.vmware.vmware_host (4.2.0) — module

Add, remove, or move an ESXi host to, from, or within vCenter

Authors: Joseph Callen (@jcpowermac), Russell Teague (@mtnbikenc), Maxime de Roucy (@tchernomax), Christian Kotte (@ckotte)

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 can be used to add, reconnect, or remove an ESXi host to or from vCenter.

This module can also be used to move an ESXi host to a cluster or folder, or vice versa, within the same datacenter.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Add ESXi Host to vCenter
  community.vmware.vmware_host:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter: datacenter_name
    cluster: cluster_name
    esxi_hostname: '{{ esxi_hostname }}'
    esxi_username: '{{ esxi_username }}'
    esxi_password: '{{ esxi_password }}'
    state: present
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Add ESXi Host to vCenter under a specific folder
  community.vmware.vmware_host:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter: datacenter_name
    folder: '/Site2/Asia-Cluster/host'
    esxi_hostname: '{{ esxi_hostname }}'
    esxi_username: '{{ esxi_username }}'
    esxi_password: '{{ esxi_password }}'
    state: present
    add_connected: true
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Reconnect ESXi Host (with username/password set)
  community.vmware.vmware_host:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter: datacenter_name
    cluster: cluster_name
    esxi_hostname: '{{ esxi_hostname }}'
    esxi_username: '{{ esxi_username }}'
    esxi_password: '{{ esxi_password }}'
    state: reconnect
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Reconnect ESXi Host (with default username/password)
  community.vmware.vmware_host:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter: datacenter_name
    cluster: cluster_name
    esxi_hostname: '{{ esxi_hostname }}'
    state: reconnect
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Add ESXi Host with SSL Thumbprint to vCenter
  community.vmware.vmware_host:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter: datacenter_name
    cluster: 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
  delegate_to: localhost

Inputs

    
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

state:
    choices:
    - present
    - absent
    - add_or_reconnect
    - reconnect
    - disconnected
    default: present
    description:
    - If set to V(present), add the host if host is absent.
    - If set to V(present), update the location of the host if host already exists.
    - If set to V(absent), remove the host if host is present.
    - If set to V(absent), do nothing if host already does not exists.
    - If set to V(add_or_reconnect), add the host if it's absent else reconnect it and
      update the location.
    - If set to V(reconnect), then reconnect the host if it's present and update the location.
    - If set to V(disconnected), disconnect the host if the host already exists.
    type: str

folder:
    aliases:
    - folder_name
    description:
    - Name of the folder under which host to add.
    - If O(cluster_name) is not set, then this parameter is required.
    - For example, if there is a datacenter 'dc1' under folder called 'Site1' then, this
      value will be '/Site1/dc1/host'.
    - Here 'host' is an invisible folder under VMware Web Client.
    - Another example, if there is a nested folder structure like '/myhosts/india/pune'
      under datacenter 'dc2', then O(folder) value will be '/dc2/host/myhosts/india/pune'.
    - 'Other Examples: ''/Site2/dc2/Asia-Cluster/host'' or ''/dc3/Asia-Cluster/host'''
    type: str

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

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

cluster_name:
    aliases:
    - cluster
    description:
    - Name of the cluster to add the host.
    - If O(folder) is not set, then this parameter is required.
    type: str

add_connected:
    default: true
    description:
    - If set to V(true), then the host should be connected as soon as it is added.
    - This parameter is ignored if not O(state=present).
    type: bool

esxi_hostname:
    description:
    - ESXi hostname to manage.
    required: true
    type: str

esxi_password:
    description:
    - ESXi password.
    - Required for adding a host.
    - Optional for reconnect.
    - Unused for removing.
    - No longer a required parameter from version 2.5.
    type: str

esxi_username:
    description:
    - ESXi username.
    - Required for adding a host.
    - Optional for reconnect. If both O(esxi_username) and O(esxi_password) are used
    - Unused for removing.
    - No longer a required parameter from version 2.5.
    type: str

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

datacenter_name:
    aliases:
    - datacenter
    description:
    - Name of the datacenter to add the host.
    required: true
    type: str

force_connection:
    default: true
    description:
    - Force the connection if the host is already being managed by another vCenter server.
    type: bool

esxi_ssl_thumbprint:
    aliases:
    - ssl_thumbprint
    default: ''
    description:
    - Specifying the hostsystem certificate's thumbprint.
    - 'Use following command to get hostsystem certificate''s thumbprint - '
    - '# openssl x509 -in /etc/vmware/ssl/rui.crt -fingerprint -sha1 -noout'
    type: str

fetch_ssl_thumbprint:
    default: true
    description:
    - Fetch the thumbprint of the host's SSL certificate.
    - This basically disables the host certificate verification (check if it was signed
      by a recognized CA).
    - Disable this option if you want to allow only hosts with valid certificates to be
      added to vCenter.
    - If this option is set to V(false) and the certificate can't be verified, an add
      or reconnect will fail.
    - Unused when O(esxi_ssl_thumbprint) is set.
    - Optional for reconnect, but only used if O(esxi_username) and O(esxi_password) are
      used.
    - Unused for removing.
    type: bool

reconnect_disconnected:
    default: true
    description:
    - Reconnect disconnected hosts.
    - This is only used if O(state=present) and if the host already exists.
    type: bool

Outputs

result:
  description: metadata about the new host system added
  returned: on successful addition
  sample: Host already connected to vCenter 'vcenter01' in cluster 'cluster01'
  type: str