# Create one with the defaults
- name: create new VM with default resource pool
  vmware_guest:
    validate_certs: False
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    name: test_vm1
    #template: "{{ item|basename }}"
    guest_id: centos64Guest
    datacenter: "{{ dc1 }}"
    hardware:
        num_cpus: 1
        memory_mb: 512
    disk:
        - size: 1gb
          type: thin
          autoselect_datastore: True
    state: poweredoff
    folder: F0
  register: clone_rp_d1_c1_f0

- debug: var=clone_rp_d1_c1_f0

- name: assert that changes were made
  assert:
    that:
      - clone_rp_d1_c1_f0 is changed

- name: delete the new VMs
  vmware_guest:
    validate_certs: False
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    name: test_vm1
    #template: "{{ item|basename }}"
    #guest_id: centos64Guest
    datacenter: "{{ dc1 }}"
    state: absent
    folder: F0
  register: clone_rp_d1_c1_f0_delete

- debug: var=clone_rp_d1_c1_f0_delete

- name: assert that changes were made with deletion
  assert:
    that:
        - clone_rp_d1_c1_f0_delete is changed

# now create with just a cluster
- name: create new VM with default resource pool in cluster
  vmware_guest:
    validate_certs: False
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    name: test_vm1
    #template: "{{ item|basename }}"
    guest_id: centos64Guest
    datacenter: "{{ dc1 }}"
    cluster: "{{ ccr1 }}"
    hardware:
        num_cpus: 1
        memory_mb: 512
    disk:
        - size: 1gb
          type: thin
          autoselect_datastore: True
    state: poweredoff
    folder: F0
  register: clone_rpc_d1_c1_f0

- debug: var=clone_rpc_d1_c1_f0

- name: assert that changes were made
  assert:
    that:
      - clone_rpc_d1_c1_f0 is changed

- name: delete the new VMs
  vmware_guest:
    validate_certs: False
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    name: test_vm1
    #template: "{{ item|basename }}"
    #guest_id: centos64Guest
    datacenter: "{{ dc1 }}"
    cluster: "{{ ccr1 }}"
    state: absent
    folder: F0
  register: clone_rpc_d1_c1_f0_delete

- debug: var=clone_rpc_d1_c1_f0_delete

- name: assert that changes were made with deletion
  assert:
    that:
        - clone_rpc_d1_c1_f0_delete is changed

# now create with a specific resource pool
- name: create new VM with specific resource pool in cluster
  vmware_guest:
    validate_certs: False
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    name: test_vm1
    #template: "{{ item|basename }}"
    guest_id: centos64Guest
    datacenter: "{{ dc1 }}"
    cluster: "{{ ccr1 }}"
    resource_pool: DC0_C0_RP1
    hardware:
        num_cpus: 1
        memory_mb: 512
    disk:
        - size: 1gb
          type: thin
          autoselect_datastore: True
    state: poweredoff
    folder: F0
  register: clone_rpcp_d1_c1_f0

- debug: var=clone_rpcp_d1_c1_f0

- name: assert that changes were made
  assert:
    that:
      - clone_rpcp_d1_c1_f0 is changed

- name: delete the new VMs
  vmware_guest:
    validate_certs: False
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    name: test_vm1
    #template: "{{ item|basename }}"
    #guest_id: centos64Guest
    datacenter: "{{ dc1 }}"
    cluster: "{{ ccr1 }}"
    state: absent
    folder: F0
  register: clone_rpcp_d1_c1_f0_delete

- debug: var=clone_rpcp_d1_c1_f0_delete

- name: assert that changes were made with deletion
  assert:
    that:
        - clone_rpcp_d1_c1_f0_delete is changed

# now create with a specific host
- name: create new VM with specific host
  vmware_guest:
    validate_certs: False
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    name: test_vm1
    #template: "{{ item|basename }}"
    guest_id: centos64Guest
    datacenter: "{{ dc1 }}"
    esxi_hostname: '{{ esxi1 }}'
    hardware:
        num_cpus: 1
        memory_mb: 512
    disk:
        - size: 1gb
          type: thin
          autoselect_datastore: True
    state: poweredoff
    folder: F0
  register: clone_rph_d1_c1_f0

- debug: var=clone_rph_d1_c1_f0

- name: assert that changes were made
  assert:
    that:
      - clone_rph_d1_c1_f0 is changed

- name: delete the new VMs
  vmware_guest:
    validate_certs: False
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    name: test_vm1
    #template: "{{ item|basename }}"
    #guest_id: centos64Guest
    datacenter: "{{ dc1 }}"
    state: absent
    folder: F0
  register: clone_rph_d1_c1_f0_delete

- debug: var=clone_rph_d1_c1_f0_delete

- name: assert that changes were made with deletion
  assert:
    that:
        - clone_rph_d1_c1_f0_delete is changed
