community.vmware.vmware_vm_storage_policy module – Create vSphere storage policies

Note

This module is part of the community.vmware collection (version 4.8.1).

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 community.vmware.

To use it in a playbook, specify: community.vmware.vmware_vm_storage_policy.

Synopsis

  • A vSphere storage policy defines metadata that describes storage requirements for virtual machines and storage capabilities of storage providers.

  • Currently, only tag-based storage policy creation is supported.

Parameters

Parameter

Comments

description

string

Description of the storage policy to create or update.

This parameter is ignored when state=absent.

hostname

string

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.

name

string / required

Name of the storage policy to create, update, or delete.

password

aliases: pass, pwd

string

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.

port

integer

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.

Default: 443

proxy_host

string

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 VMWARE_PROXY_HOST will be used instead.

proxy_port

integer

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 VMWARE_PROXY_PORT will be used instead.

state

string

State of storage policy.

If set to present, the storage policy is created.

If set to absent, the storage policy is deleted.

Choices:

  • "absent"

  • "present" ← (default)

tag_affinity

boolean

If set to true, the storage policy enforces that virtual machines require the existence of a tag for datastore placement.

If set to false, the storage policy enforces that virtual machines require the absence of a tag for datastore placement.

This parameter is ignored when state=absent.

Choices:

  • false

  • true ← (default)

tag_category

string

Name of the pre-existing tag category to assign to the storage policy.

This parameter is ignored when state=absent.

This parameter is required when state=present.

tag_name

string

Name of the pre-existing tag to assign to the storage policy.

This parameter is ignored when state=absent.

This parameter is required when state=present.

username

aliases: admin, user

string

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.

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

  • All modules requires API write access and hence is not supported on a free ESXi license.

  • All variables and VMware object names are case sensitive.

Examples

- name: Create or update a vSphere tag-based storage policy
  community.vmware.vmware_vm_storage_policy:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    name: "vSphere storage policy"
    description: "vSphere storage performance policy"
    tag_category: "performance_tier"
    tag_name: "gold"
    tag_affinity: true
    state: "present"
  delegate_to: localhost

- name: Remove a vSphere tag-based storage policy
  community.vmware.vmware_vm_storage_policy:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    name: "vSphere storage policy"
    state: "absent"
  delegate_to: localhost

Return Values

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

Key

Description

vmware_vm_storage_policy

dictionary

dictionary of information for the storage policy

Returned: success

Sample: {"vmware_vm_storage_policy": {"description": "Storage policy for gold-tier storage", "id": "aa6d5a82-1c88-45da-85d3-3d74b91a5bad", "name": "gold"}}

Authors

  • Dustin Scott (@scottd018)