community.vmware.vmware_tag_manager (4.2.0) — module

Manage association of VMware tags with VMware objects

Authors: Abhijeet Kasurde (@Akasurde), Frederic Van Reet (@GBrawl)

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 assign / remove VMware tags from the given VMware objects.

Tag feature is introduced in vSphere 6 version, so this module is not supported in the earlier versions of vSphere.

All variables and VMware object names are case sensitive.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Add tags to a virtual machine
  community.vmware.vmware_tag_manager:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    tag_names:
      - Sample_Tag_0002
      - Category_0001:Sample_Tag_0003
    object_name: Fedora_VM
    object_type: VirtualMachine
    state: add
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Specify tag and category as dict
  community.vmware.vmware_tag_manager:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    tag_names:
      - tag: tag_0001
        category: cat_0001
      - tag: tag_0002
        category: cat_0002
    object_name: Fedora_VM
    object_type: VirtualMachine
    state: add
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Remove a tag from a virtual machine
  community.vmware.vmware_tag_manager:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    tag_names:
      - Sample_Tag_0002
    object_name: Fedora_VM
    object_type: VirtualMachine
    state: remove
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Add tags to a distributed virtual switch
  community.vmware.vmware_tag_manager:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    tag_names:
      - Sample_Tag_0003
    object_name: Switch_0001
    object_type: DistributedVirtualSwitch
    state: add
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Add tags to a distributed virtual portgroup
  community.vmware.vmware_tag_manager:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    tag_names:
      - Sample_Tag_0004
    object_name: Switch_0001:Portgroup_0001
    object_type: DistributedVirtualPortgroup
    state: add
  delegate_to: localhost
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

- name: Get information about folders
  community.vmware.vmware_folder_info:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter: 'Asia-Datacenter1'
  delegate_to: localhost
  register: r
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Set Managed object ID for the given folder
  ansible.builtin.set_fact:
    folder_mo_id: "{{ (r.flat_folder_info | selectattr('path', 'equalto', '/Asia-Datacenter1/vm/tier1/tier2') | map(attribute='moid'))[0] }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Add tags to a Folder using managed object id
  community.vmware.vmware_tag_manager:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    tag_names:
      - Sample_Cat_0004:Sample_Tag_0004
    object_type: Folder
    moid: "{{ folder_mo_id }}"
    state: add
  delegate_to: localhost

Inputs

    
moid:
    description:
    - Managed object ID for the given object.
    - Required if O(object_name) is not set.
    required: false
    type: str

port:
    default: 443
    description:
    - The port number of the vSphere vCenter.
    - 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
    - remove
    - set
    default: add
    description:
    - If set to V(add) or V(present) will add the tags to the existing tag list of the
      given object.
    - If set to V(remove) or V(absent) will remove the tags from the existing tag list
      of the given object.
    - If set to V(set) will replace the tags of the given objects with the user defined
      list of tags.
    type: str

hostname:
    description:
    - The hostname or IP address of the vSphere vCenter 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 server.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_PASSWORD)
      will be used instead.
    type: str

protocol:
    choices:
    - http
    - https
    default: https
    description:
    - The connection to protocol.
    type: str

username:
    aliases:
    - admin
    - user
    description:
    - The username of the vSphere vCenter server.
    - If the value is not specified in the task, the value of environment variable E(VMWARE_USER)
      will be used instead.
    type: str

tag_names:
    description:
    - List of tag(s) to be managed.
    - User can also specify category name by specifying colon separated value. For example,
      "category_name:tag_name".
    - User can also specify tag and category as dict, when tag or category contains colon.
      See example for more information.
    - User can skip category name if you have unique tag names.
    elements: raw
    required: true
    type: list

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

object_name:
    description:
    - Name of the object to work with.
    - For DistributedVirtualPortgroups the format should be "switch_name:portgroup_name"
    - Required if O(moid) is not set.
    required: false
    type: str

object_type:
    choices:
    - VirtualMachine
    - Datacenter
    - ClusterComputeResource
    - HostSystem
    - DistributedVirtualSwitch
    - DistributedVirtualPortgroup
    - Datastore
    - DatastoreCluster
    - ResourcePool
    - Folder
    description:
    - Type of object to work with.
    required: true
    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

Outputs

tag_status:
  description: metadata about tags related to object configuration
  returned: on success
  sample:
    attached_tags:
    - urn:vmomi:InventoryServiceCategory:76f69e84-f6b9-4e64-954c-fac545d2c0ba:GLOBAL:security
    current_tags:
    - urn:vmomi:InventoryServiceCategory:927f5ff8-62e6-4364-bc94-23e3bfd7dee7:GLOBAL:backup
    - urn:vmomi:InventoryServiceCategory:76f69e84-f6b9-4e64-954c-fac545d2c0ba:GLOBAL:security
    detached_tags: []
    previous_tags:
    - urn:vmomi:InventoryServiceCategory:927f5ff8-62e6-4364-bc94-23e3bfd7dee7:GLOBAL:backup
  type: list