---
- name: Create CNS production VMs on vCenter
  vmware_guest:
    hostname: "{{ vcenter_host }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    validate_certs: False
    name: "{{ item.value.guestname }}"
    cluster: "{{ vcenter_cluster}}"
    datacenter: "{{ vcenter_datacenter }}"
    resource_pool: "{{ vcenter_resource_pool }}"
    template: "{{vcenter_template_name}}"
    state: poweredon
    wait_for_ip_address: true
    folder: "/{{ vcenter_folder }}"
    annotation: "{{ item.value.tag }}"
    disk:
    - size_gb: 60
      datastore: "{{ vcenter_datastore }}"
      type: thin
    - size_gb: 40
      datastore: "{{ vcenter_datastore }}"
      type: thin
    - size_gb: 40
      datastore: "{{ vcenter_datastore }}"
      type: thin
    - size_gb: 300
      datastore: "{{ vcenter_datastore }}"
      type: eagerZeroedThick
    hardware:
      memory_mb: 32768
    networks:
    - name: "{{ vm_network }}"
      ip: "{{ item.value.ip4addr }}"
      netmask: "{{ vm_netmask }}"
      gateway: "{{ vm_gw }}"
    customization:
      domain: "{{public_hosted_zone}}"
      dns_servers:
      - "{{ vm_dns }}"
      dns_suffix: "{{public_hosted_zone}}"
      hostname: "{{ item.value.guestname}}"
  with_dict: "{{host_inventory}}"
  when: "'cns' in item.value.guestname"

- name: Add CNS production VMs to inventory
  add_host: hostname="{{ item.value.guestname }}" ansible_ssh_host="{{ item.value.ip4addr }}" groups="{{ item.value.tag }}, cns, new_nodes"
  with_dict: "{{host_inventory}}"
  when: "'cns' in item.value.guestname"
