community.vmware.vmware_tag_manager – Manage association of VMware tags with VMware objects¶
Note
This plugin is part of the community.vmware collection (version 1.7.0).
To install it use: ansible-galaxy collection install community.vmware
.
To use it in a playbook, specify: community.vmware.vmware_tag_manager
.
Synopsis¶
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¶
The below requirements are needed on the host that executes this module.
python >= 2.6
PyVmomi
vSphere Automation SDK
Parameters¶
Examples¶
- 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
- 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
- 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
- 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
- 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
- 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
- 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] }}"
- 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
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Authors¶
Abhijeet Kasurde (@Akasurde)
Frederic Van Reet (@GBrawl)