community.vmware.vmware_guest_custom_attributes 模块 – 管理指定虚拟机的 VMware 自定义属性

注意

此模块是 community.vmware 集合(版本 5.2.0)的一部分。

如果您正在使用 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.vmware

要在 playbook 中使用它,请指定:community.vmware.vmware_guest_custom_attributes

概要

  • 此模块可用于添加、删除和更新给定虚拟机的自定义属性。

参数

参数

注释

attributes

list / elements=dictionary

需要管理的自定义属性的名称和值的列表。

如果 state=absent,则不需要自定义属性的值,并且将被忽略。

默认: []

name

string / 必选

属性的名称。

value

string

属性的值。

默认: ""

datacenter

string

虚拟机所在的数据中心名称。

folder

string

查找现有虚拟机的绝对路径。

如果提供了 name 并且找到了多个同名的虚拟机,则此为必选参数。

hostname

string

vSphere vCenter 或 ESXi 服务器的主机名或 IP 地址。

如果未在任务中指定该值,则将使用环境变量 VMWARE_HOST 的值。

moid

string

要管理的实例的托管对象 ID(如果已知),这在单个 vCenter 实例中是唯一的标识符。

如果未提供 nameuuid,则此为必选参数。

name

string

虚拟机名称。

如果未提供 uuidmoid,则此为必选参数。

password

别名:pass, pwd

string

vSphere vCenter 或 ESXi 服务器的密码。

如果未在任务中指定该值,则将使用环境变量 VMWARE_PASSWORD 的值。

port

integer

vSphere vCenter 或 ESXi 服务器的端口号。

如果未在任务中指定该值,则将使用环境变量 VMWARE_PORT 的值。

默认: 443

proxy_host

string

将接收所有 HTTPS 请求并转发它们的代理的地址。

格式为主机名或 IP。

如果未在任务中指定该值,则将使用环境变量 VMWARE_PROXY_HOST 的值。

proxy_port

integer

将接收所有 HTTPS 请求并转发它们的 HTTP 代理的端口。

如果未在任务中指定该值,则将使用环境变量 VMWARE_PROXY_PORT 的值。

state

string

要执行的操作。

如果设置为 present,则添加或更新自定义属性。

如果设置为 absent,则删除自定义属性值。

选项

  • "present" ← (默认)

  • "absent"

use_instance_uuid

boolean

是否使用 VMware 实例 UUID 而不是 BIOS UUID。

选项

  • false ← (默认)

  • true

username

别名:admin, user

string

vSphere vCenter 或 ESXi 服务器的用户名。

如果任务中未指定该值,则将使用环境变量 VMWARE_USER 的值代替。

uuid

string

要管理的虚拟机的 UUID(如果已知)。这是 VMware 的唯一标识符。

如果未提供 namemoid,则此为必需参数。

validate_certs

boolean

允许在 SSL 证书无效时进行连接。当证书不受信任时,设置为 false

如果任务中未指定该值,则将使用环境变量 VMWARE_VALIDATE_CERTS 的值代替。

选项

  • false

  • true ← (默认)

备注

注意

  • 所有模块都需要 API 写入访问权限,因此在免费的 ESXi 许可证上不受支持。

  • 所有变量和 VMware 对象名称都区分大小写。

示例

- name: Add virtual machine custom attributes
  community.vmware.vmware_guest_custom_attributes:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    uuid: 421e4592-c069-924d-ce20-7e7533fab926
    state: present
    attributes:
      - name: MyAttribute
        value: MyValue
  delegate_to: localhost
  register: attributes

- name: Add multiple virtual machine custom attributes
  community.vmware.vmware_guest_custom_attributes:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    uuid: 421e4592-c069-924d-ce20-7e7533fab926
    state: present
    attributes:
      - name: MyAttribute
        value: MyValue
      - name: MyAttribute2
        value: MyValue2
  delegate_to: localhost
  register: attributes

- name: Remove virtual machine Attribute
  community.vmware.vmware_guest_custom_attributes:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    uuid: 421e4592-c069-924d-ce20-7e7533fab926
    state: absent
    attributes:
      - name: MyAttribute
  delegate_to: localhost
  register: attributes

- name: Remove virtual machine Attribute using Virtual Machine MoID
  community.vmware.vmware_guest_custom_attributes:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    moid: vm-42
    state: absent
    attributes:
      - name: MyAttribute
  delegate_to: localhost
  register: attributes

返回值

通用返回值记录在此处,以下是此模块特有的字段

描述

custom_attributes

字典

关于虚拟机属性的元数据

返回: 总是

示例: {"mycustom": "my_custom_value", "mycustom_2": "my_custom_value_2", "sample_1": "sample_1_value", "sample_2": "sample_2_value", "sample_3": "sample_3_value"}

作者

  • Jimmy Conner (@cigamit)

  • Abhijeet Kasurde (@Akasurde)