简体   繁体   中英

Ansbile VMware VM/Host Groups (DRS groups)

I want to use Ansible to add a new VM to an already existing VMware VM / Host Group (DRS group). With the modules listed below, however, the complete group is always learned and only this one VM is added. How can I add a new VM to the DRS role without removing the VMs already in it?

- name: "Create DRS VM group"
  delegate_to: localhost
  vmware_drs_group:
    hostname: "{{ vcenter_hostname }}"
    password: "{{ vcenter_password }}"
    username: "{{ vcenter_username }}"
    cluster_name: DC0_C0
    datacenter_name: DC0
    group_name: TEST_VM_01
    vms:
      - DC0_C0_RP0_VM0
      - DC0_C0_RP0_VM1
    state: present

That's working:

- name: "Get information about VM/Host groups (DRS VM groups)"
  register: cluster_drs_group_info
  vmware_drs_group_info:
    hostname: "{{ vcenter_hostname }}"
    password: "{{ vcenter_password }}"
    username: "{{ vcenter_username }}"
    validate_certs: False
    cluster_name: "{{ cluster}}"
  delegate_to: localhost

- name: "Create VM list"
  set_fact:
    linux_drs_vms: "{{ cluster_drs_group_info.drs_group_info.Cluster[0].vms }} + ['{{ vm_name }}']"

- name: "Create VM/Host groups (DRS VM groups)"
  delegate_to: localhost
  vmware_drs_group:
    hostname: "{{ vcenter_hostname }}"
    password: "{{ vcenter_password }}"
    username: "{{ vcenter_username }}"
    validate_certs: False
    cluster_name: "{{ cluster }}"
    datacenter_name: "{{ datacenter }}"
    group_name: "VMGroup - LinuxVMs"
    state: present
    vms: "{{ item }}"
  loop:
    - "{{ linux_drs_vms }}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM