vmware.vmware_rest.vcenter_datacenter module – Manage vCenter datacenters.

Note

This module is part of the vmware.vmware_rest collection (version 5.0.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install vmware.vmware_rest.

To use it in a playbook, specify: vmware.vmware_rest.vcenter_datacenter.

New in vmware.vmware_rest 5.0.0

Synopsis

  • Create and delete VMware vCenter datacenters.

  • A datacenter is the top-level organizational container in vCenter that holds clusters, hosts, virtual machines, datastores, and networks.

  • Use this module to provision new datacenters or remove existing ones from the vCenter inventory.

Parameters

Parameter

Comments

datacenter

string

Identifier of the datacenter to manage.

Must be an identifier (MOID) for a Datacenter resource.

folder

string

The inventory folder in which the datacenter should be created.

Must be the MOID (managed object identifier) of an existing Folder resource.

Required when creating a datacenter.

force

boolean

Whether to delete the datacenter even if it contains child resources such as clusters, hosts, or virtual machines.

When set to false or omitted, the delete operation will fail if the datacenter is not empty.

Choices:

  • false

  • true

name

string

The name of the datacenter to be created.

session_timeout

float

Timeout in seconds for the whole operation including connection establishment, request sending, and response.

Default: 300.0

state

string

The desired state of the resource.

Use present to create or update the resource.

Use absent to delete the resource.

Choices:

  • "present" ← (default)

  • "absent"

vcenter_hostname

string / required

The hostname or IP address of the vSphere vCenter.

If the value is not specified in the task, the value of environment variable VMWARE_HOST will be used instead.

vcenter_password

string / required

The vSphere vCenter password.

If the value is not specified in the task, the value of environment variable VMWARE_PASSWORD will be used instead.

vcenter_port

integer

The port number of the vSphere vCenter.

If the value is not specified in the task, the value of environment variable VMWARE_PORT will be used instead.

vcenter_rest_log_file

string

Optional path to a log file for HTTP REST interaction.

If the value is not specified in the task, the value of environment variable VMWARE_REST_LOG_FILE will be used instead.

vcenter_username

string / required

The vSphere vCenter username.

If the value is not specified in the task, the value of environment variable VMWARE_USER will be used instead.

vcenter_validate_certs

boolean

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.

Choices:

  • false

  • true ← (default)

Notes

Note

  • Generated from vSphere API spec 9.1.0.

  • Compatible with vSphere API 7.0.3.

  • Compatible with vSphere API 8.0.2.

Examples

- name: Lookup the datacenter folder
  vmware.vmware_rest.vcenter_folder_info:
    filter_type: DATACENTER
  register: datacenter_folders

- name: Create a datacenter
  vmware.vmware_rest.vcenter_datacenter:
    name: my_datacenter
    folder: '{{ datacenter_folders.value[0].folder }}'
    state: present
  register: my_datacenter

- name: Delete a datacenter
  vmware.vmware_rest.vcenter_datacenter:
    datacenter: '{{ my_datacenter.id }}'
    state: absent

- name: Force delete a datacenter that contains resources
  vmware.vmware_rest.vcenter_datacenter:
    datacenter: '{{ my_datacenter.id }}'
    force: true
    state: absent

Return Values

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

Key

Description

id

string

MOID of the managed datacenter.

Returned: When state is present, or when a resource is deleted, or when state is set to a supported action.

Sample: "datacenter-1001"

value

any

The raw API response body from the vCenter operation.

Returned: On success

Sample: {"name": "my-datacenter"}

Authors

  • Ansible Eco Content Team (@eco-ansible-content)