vmware.vmware_rest.vcenter_vm_storage_policy module – Manage the storage policies associated with a virtual machine.

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_vm_storage_policy.

New in vmware.vmware_rest 5.0.0

Synopsis

  • Update the storage policy configuration of a virtual machine’s home directory and/or its virtual hard disks.

  • Assign a specific storage policy, or fall back to the default storage policy of the datastore.

  • Only entities that are supplied are reconfigured; entities left unset retain their current storage policy.

Parameters

Parameter

Comments

disks

dictionary

The storage policies to apply to the virtual machine’s virtual disks.

A map keyed by the disk MOID, where each value is a storage policy specification for that disk.

Each key must be an identifier (MOID) for the resource type com.vmware.vcenter.vm.hardware.Disk.

Any disk that is not listed retains its current storage policy.

When this option is specified, the module can never be idempotent. A change will always be reported.

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.

Choices:

  • "present" ← (default)

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)

vm

string / required

Identifier of the vm to manage.

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

vm_home

dictionary

The storage policy to apply to the virtual machine’s home directory.

If omitted, the current storage policy of the VM home directory is retained.

When this option is specified, the module can never be idempotent. A change will always be reported.

policy

string

The storage policy to assign to the VM home directory.

Only used, and required, when vm_home.type is USE_SPECIFIED_POLICY.

Must be an identifier (MOID) for the resource type com.vmware.vcenter.StoragePolicy.

type

string / required

How to select the storage policy for the VM home directory.

Use USE_SPECIFIED_POLICY to assign the storage policy given in vm_home.policy.

Use USE_DEFAULT_POLICY to assign the default storage policy of the datastore.

Choices:

  • "USE_SPECIFIED_POLICY"

  • "USE_DEFAULT_POLICY"

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: Look up the VM called test_vm1 in the inventory
  register: search_result
  vmware.vmware_rest.vcenter_vm_info:
    filter_names:
      - test_vm1

- name: Assign a specific storage policy to the VM home directory
  vmware.vmware_rest.vcenter_vm_storage_policy:
    vm: '{{ search_result.value[0].vm }}'
    vm_home:
      type: USE_SPECIFIED_POLICY
      policy: aa6d5a82-1c88-45da-85d3-3d74b91a5bad
    state: present

- name: Assign storage policies to the VM home directory and a virtual disk
  vmware.vmware_rest.vcenter_vm_storage_policy:
    vm: '{{ search_result.value[0].vm }}'
    vm_home:
      type: USE_DEFAULT_POLICY
    disks:
      '2000':
        type: USE_SPECIFIED_POLICY
        policy: aa6d5a82-1c88-45da-85d3-3d74b91a5bad
    state: present

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 virtual machine.

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

Sample: "vm-1009"

value

any

The raw API response body from the vCenter storage policy update operation.

Returned: On success

Sample: {"disks": {"2000": "aa6d5a82-1c88-45da-85d3-3d74b91a5bad"}, "vm_home": "aa6d5a82-1c88-45da-85d3-3d74b91a5bad"}

Authors

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