vmware_host_datastore - Manage a datastore on ESXi host

New in version 2.5.

Synopsis

  • This module can be used to mount/umount datastore on ESXi host.
  • This module only support NFS/VMFS type of datastores.
  • For VMFS datastore, available device must already be connected on ESXi host.
  • 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
datacenter_name
required
Name of the datacenter to add the datastore.
datastore_name
required
Name of the datastore to add/remove.
datastore_type
required
    Choices:
  • nfs
  • vmfs
Type of the datastore to configure (nfs/vmfs).
esxi_hostname
required
ESXi hostname to manage the datastore.
hostname
str
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 version 2.6.
nfs_path
Resource path on NFS host.
Required if datastore type is set to nfs and state is set to present, else unused.
nfs_ro
bool
    Choices:
  • no
  • yes
ReadOnly or ReadWrite mount.
Unused if datastore type is not set to nfs and state is not set to present.
nfs_server
NFS host serving nfs datastore.
Required if datastore type is set to nfs and state is set to present, else unused.
password
str
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 version 2.6.

aliases: pass, pwd
port
int

(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 version 2.6.
state
    Choices:
  • present
  • absent
present: Mount datastore on host if datastore is absent else do nothing.
absent: Umount datastore if datastore is present else do nothing.
username
str
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 version 2.6.

aliases: admin, user
validate_certs
bool
    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 version 2.6.
If set to yes, please make sure Python >= 2.7.9 is installed on the given machine.
vmfs_device_name
Name of the device to be used as VMFS datastore.
Required for VMFS datastore type and state is set to present, else unused.
vmfs_version
VMFS version to use for datastore creation.
Unused if datastore type is not set to vmfs and state is not set to present.

Notes

Note

  • Tested on vSphere 6.0 and 6.5

Examples

- name: Mount VMFS datastores to ESXi
  vmware_host_datastore:
      hostname: '{{ vcenter_hostname }}'
      username: '{{ vcenter_user }}'
      password: '{{ vcenter_pass }}'
      datacenter_name: '{{ datacenter }}'
      datastore_name: '{{ item.name }}'
      datastore_type: '{{ item.type }}'
      vmfs_device_name: 'naa.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
      vmfs_version: 6
      esxi_hostname: '{{ inventory_hostname }}'
      state: present
  delegate_to: localhost

- name: Mount NFS datastores to ESXi
  vmware_host_datastore:
      hostname: '{{ vcenter_hostname }}'
      username: '{{ vcenter_user }}'
      password: '{{ vcenter_pass }}'
      datacenter_name: '{{ datacenter }}'
      datastore_name: '{{ item.name }}'
      datastore_type: '{{ item.type }}'
      nfs_server: '{{ item.server }}'
      nfs_path: '{{ item.path }}'
      nfs_ro: no
      esxi_hostname: '{{ inventory_hostname }}'
      state: present
  delegate_to: localhost
  with_items:
      - { 'name': 'NasDS_vol01', 'server': 'nas01', 'path': '/mnt/vol01', 'type': 'nfs'}
      - { 'name': 'NasDS_vol02', 'server': 'nas01', 'path': '/mnt/vol02', 'type': 'nfs'}

- name: Remove/Umount Datastores from ESXi
  vmware_host_datastore:
      hostname: '{{ vcenter_hostname }}'
      username: '{{ vcenter_user }}'
      password: '{{ vcenter_pass }}'
      datacenter_name: '{{ datacenter }}'
      datastore_name: NasDS_vol01
      esxi_hostname: '{{ inventory_hostname }}'
      state: absent
  delegate_to: localhost

Status

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

Maintenance

This module is flagged as community which means that it is maintained by the Ansible Community. See Module Maintenance & Support for more info.

For a list of other modules that are also maintained by the Ansible Community, see here.

Author

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.6/modules/vmware_host_datastore_module.html