Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Ansible Deploy a VMware vSphere Virtual Machine from a Template

One of my teammates from another project had a requirement of deploying a clone VMware Virtual Machine from a template using Ansible. In the last hour additional requirements they wanted to process clones of multiple VMs with different types of operating system such as Linux and Microsoft Windows.

For this test in the vSphere vCenter Server environment I already created two VM Templates - one for linux and another for Windows machine. Below is the screenshot after deployment from Ansible script. Two new VMs cloned and created in /testvms folder on the given Virtual Datacenter >> Cluster >> Esxi server with required specification.

VMware vSPhere vcenter esxi powershell vsphere client redhat ansible automation devops deploy template virtual machine clone copy network disconnected connected pyvmomi python yaml yml vm create.jpg

Download this vm_clone ansible yaml here or it is also available on github.com/janviudapi.

I wrote 3 yaml files. In this Ansible script, first file contains information regarding authentication to VMware vCenter Server. Add vCenter server hostname, username and password details in this file.

# secrets.yml  >> Add vCenter server and Authentication information.

1
2
3
4
---
vcenter_hostname: 192.168.34.20
vcenter_username: administrator@vsphere.local
vcenter_password: 123456

In the next file feed data related to existing Template, its datacenter. Also feed respective new Virtual Machine details such as where it will be created, hardware size etc. (For New VM Datacenter, Cluster, VM and Template Folder, Datastore and PortGroup Network, make sure these resources are already created in the infrastructure). 

newvm_data.yml  >> Provide New Virtual Machine details.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
newvms:
- {
    template_name: Wakanda_Forever_Win_01,
    template_datacenter: Asgard,
    #template_disksize: 90,
    new_vm_name: win01-deadpool,
    new_vm_datacenter: Asgard,
    new_vm_cluster : Bifrost,
    new_vm_folder: /testvms,
    new_vm_datastore: StarLord_Datastore01,
    new_vm_cpu: 2,
    new_vm_cpu_cores_per_socket: 1,
    new_vm_memory_mb: 2048,
    new_vm_network: VM Network
  }
- {
    template_name: Wakanda_Ubuntu_01,
    template_datacenter: Asgard,
    #template_disksize: 100,
    new_vm_name: lin01-deadpool,
    new_vm_datacenter: Asgard,
    new_vm_cluster : Bifrost,
    new_vm_folder: /testvms,
    new_vm_datastore: StarLord_Datastore01,
    new_vm_cpu: 1,
    new_vm_cpu_cores_per_socket: 1,    
    new_vm_memory_mb: 1024,
    new_vm_network: VM Network
  }

Related Blogs
Using terraform to clone a virtual machine on VMware vSphere infrastructure
Terraform module clone VMware vSphere Linux and Windows virtual machine

This is the main file which will use Ansible collections' library plugin from community.vmware, I have downloaded this module from ansible-galaxy. This contains the entire code to clone Template to VM. Once Virtual Machines are deployed it will enable ethernet adapter connected and start connected checkboxes in the new virtual machines settings.

# vm_clone.yaml  >> Runbook yaml code to clone/deploy VM from vCenter Template.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
---
- name: Vmware Virtual Machine Creation from Template
  hosts: localhost
  connection: local
  gather_facts: false

  # vars:
  #   varname: Wakanda_Ubuntu_01

  collections:
    - community.vmware

  tasks:
    - name: Include Secret Environment Items
      ansible.builtin.include_vars:
        file: secrets.yml
        name: secret

    - name: Include new vm data
      ansible.builtin.include_vars:
        file: newvm_data.yml
        name: newvm_data

    - name: Gather disk info from virtual machine using name
      community.vmware.vmware_guest_disk_info:
        hostname: "{{ secret.vcenter_hostname }}"
        username: "{{ secret.vcenter_username }}"
        password: "{{ secret.vcenter_password }}"
        validate_certs: false
        name: "{{ item.template_name }}"
        datacenter: "{{ item.template_datacenter }}"
      delegate_to: localhost
      register: template_disk_info
      loop: "{{ newvm_data.newvms }}"

    - name: Set facts VM template disk info (Added spaces in jinja)
      ansible.builtin.set_fact:
        diskinfo: "{{ diskinfo | default([]) + \
            [{ \
              'name': item.invocation.module_args.name, \
               'capacity_in_bytes': item.guest_disk_info['0'].capacity_in_bytes, \
               'capacity_in_kb': item.guest_disk_info['0'].capacity_in_kb \
            }] \
          }}"
      loop: "{{ template_disk_info.results }}"

    # - name: Print disk info
    #   ansible.builtin.debug:
    #   # msg: "{{ diskinfo | json_query('@[?name==`%s`].capacity_in_kb' % (varname)) }}" 
    #     msg: "{{ (diskinfo | json_query('@[?name==`{}`].capacity_in_kb'.format(varname)))[0] }}" # | int

    - name: Create a virtual machine from a template
      community.vmware.vmware_guest:
        hostname: "{{ secret.vcenter_hostname }}"
        username: "{{ secret.vcenter_username }}"
        password: "{{ secret.vcenter_password }}"
        validate_certs: false
        template: "{{ item.template_name }}"
        name: "{{ item.new_vm_name }}"
        state: poweredon
        datacenter: "{{ item.new_vm_datacenter }}"
        cluster: "{{ item.new_vm_cluster }}"
        folder: "{{ item.new_vm_folder }}"
        disk:
          - datastore: "{{ item.new_vm_datastore }}"
            size_kb: "{{ (diskinfo | json_query('@[?name==`{}`].capacity_in_kb'.format(item.template_name)))[0] }}"
            type: thin
        hardware:
          memory_mb: "{{ item.new_vm_memory_mb }}"
          num_cpus: "{{ item.new_vm_cpu }}"
          num_cpu_cores_per_socket: "{{ item.new_vm_cpu_cores_per_socket }}"
        networks:
          - name: "{{ item.new_vm_network }}"
            connected: true
            start_connected: true
        wait_for_ip_address: true
      delegate_to: localhost
      register: deploy
      loop: "{{ newvm_data.newvms }}"

    - name: Gather information of Virtual Machine
      community.vmware.vmware_guest_info:
        hostname: "{{ secret.vcenter_hostname }}"
        username: "{{ secret.vcenter_username }}"
        password: "{{ secret.vcenter_password }}"
        validate_certs: false
        datacenter: "{{ item.new_vm_datacenter }}"
        name: "{{ item.new_vm_name }}"
        # schema: "vsphere"
        # properties: ["config.hardware.memoryMB", "guest.disk", "overallStatus"]
      delegate_to: localhost
      register: vm_info
      loop: "{{ newvm_data.newvms }}"

    - name: Set facts VM info
      ansible.builtin.set_fact:
        eth_info: "{{ eth_info | default([]) + \
            [{ \
              'name': item.invocation.module_args.name, \
              'eth0_name': item.instance.hw_eth0.label, \
              'eth0_mac': item.instance.hw_eth0.macaddress, \
              'eth0_mac_dash': item.instance.hw_eth0.macaddress_dash \
            }] \
          }}"
      loop: "{{ vm_info.results }}"

    - name: Set ethernet adapter to connected and start_connected on new VM
      community.vmware.vmware_guest_network:
        hostname: "{{ secret.vcenter_hostname }}"
        username: "{{ secret.vcenter_username }}"
        password: "{{ secret.vcenter_password }}"
        validate_certs: false
        datacenter: "{{ item.new_vm_datacenter }}"
        name: "{{ item.new_vm_name }}"
        mac_address: "{{ (eth_info | json_query('@[?name==`{}`].eth0_mac'.format(item.new_vm_name)))[0] }}"
        state: present
        start_connected: true
        connected: true
      loop: "{{ newvm_data.newvms }}"

To use these files, Put all the 3 files under one directory and run below ansible-playbook command to start deployment. It will take a while to clone depending on the size of the template vm disk size. You can track the progress of the tasks on vSphere Client on the browser. All the task are showing successful in Ansible console.

ubuntu@ansible:~/Documents/vmware$ ansible-playbook vm_clone.yaml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Vmware Virtual Machine Creation from Template] ******************************************************************************************************************************

TASK [Include Secret Environment Items] *******************************************************************************************************************************************
ok: [localhost]

TASK [Include new vm data] ********************************************************************************************************************************************************
ok: [localhost]

TASK [Gather disk info from virtual machine using name] ***************************************************************************************************************************
ok: [localhost] => (item={'template_name': 'Wakanda_Forever_Win_01', 'template_datacenter': 'Asgaurd', 'template_disksize': 90, 'new_vm_name': 'win01-deadpool', 'new_vm_datacenter': 'Asgard', 'new_vm_cluster': 'Bifrost', 'new_vm_folder': '/testvms', 'new_vm_datastore': 'StarLord_Datastore01', 'new_vm_cpu': 2, 'new_vm_cpu_cores_per_socket': 1, 'new_vm_memory_mb': 2048, 'new_vm_network': 'VM Network'})
ok: [localhost] => (item={'template_name': 'Wakanda_Ubuntu_01', 'template_datacenter': 'Asgard', 'template_disksize': 100, 'new_vm_name': 'lin01-deadpool', 'new_vm_datacenter': 'Asgard', 'new_vm_cluster': 'Bifrost', 'new_vm_folder': '/testvms', 'new_vm_datastore': 'StarLord_Datastore01', 'new_vm_cpu': 1, 'new_vm_cpu_cores_per_socket': 1, 'new_vm_memory_mb': 1024, 'new_vm_network': 'VM Network'})

TASK [Set facts VM template disk info (Added spaces in jinja)] ********************************************************************************************************************
ok: [localhost] => (item={'guest_disk_info': {'0': {'key': 2000, 'label': 'Hard disk 1', 'summary': '94,371,840 KB', 'backing_filename': '[StarLord_Datastore01] Wakanda_Forever_Win_01/Wakanda_Forever_Win_01-000001.vmdk', 'backing_datastore': 'StarLord_Datastore01', 'controller_key': 1000, 'unit_number': 0, 'capacity_in_kb': 94371840, 'capacity_in_bytes': 96636764160, 'backing_type': 'FlatVer2', 'backing_writethrough': False, 'backing_thinprovisioned': True, 'backing_eagerlyscrub': False, 'backing_diskmode': 'persistent', 'backing_disk_mode': 'persistent', 'backing_uuid': '6000C29c-0644-23dd-8b99-5c6361f04022', 'controller_bus_number': 0, 'controller_type': 'lsilogicsas'}}, 'invocation': {'module_args': {'hostname': '192.168.34.20', 'username': 'administrator@vsphere.local', 'password': 'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER', 'validate_certs': False, 'name': 'Wakanda_Forever_Win_01', 'datacenter': 'Asgaurd', 'port': 443, 'use_instance_uuid': False, 'proxy_host': None, 'proxy_port': None, 'uuid': None, 'moid': None, 'folder': None}}, 'failed': False, 'changed': False, 'item': {'template_name': 'Wakanda_Forever_Win_01', 'template_datacenter': 'Asgaurd', 'template_disksize': 90, 'new_vm_name': 'win01-deadpool', 'new_vm_datacenter': 'Asgard', 'new_vm_cluster': 'Bifrost', 'new_vm_folder': '/testvms', 'new_vm_datastore': 'StarLord_Datastore01', 'new_vm_cpu': 2, 'new_vm_cpu_cores_per_socket': 1, 'new_vm_memory_mb': 2048, 'new_vm_network': 'VM Network'}, 'ansible_loop_var': 'item'})
ok: [localhost] => (item={'guest_disk_info': {'0': {'key': 2000, 'label': 'Hard disk 1', 'summary': '104,857,600 KB', 'backing_filename': '[StarLord_Datastore01] Wakanda_Ubuntu_01/Wakanda_Ubuntu_01.vmdk', 'backing_datastore': 'StarLord_Datastore01', 'controller_key': 1000, 'unit_number': 0, 'capacity_in_kb': 104857600, 'capacity_in_bytes': 107374182400, 'backing_type': 'FlatVer2', 'backing_writethrough': False, 'backing_thinprovisioned': True, 'backing_eagerlyscrub': False, 'backing_diskmode': 'persistent', 'backing_disk_mode': 'persistent', 'backing_uuid': '6000C290-1cc6-742d-24b2-16ae83f0bc6b', 'controller_bus_number': 0, 'controller_type': 'lsilogic'}}, 'invocation': {'module_args': {'hostname': '192.168.34.20', 'username': 'administrator@vsphere.local', 'password': 'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER', 'validate_certs': False, 'name': 'Wakanda_Ubuntu_01', 'datacenter': 'Asgard', 'port': 443, 'use_instance_uuid': False, 'proxy_host': None, 'proxy_port': None, 'uuid': None, 'moid': None, 'folder': None}}, 'failed': False, 'changed': False, 'item': {'template_name': 'Wakanda_Ubuntu_01', 'template_datacenter': 'Asgard', 'template_disksize': 100, 'new_vm_name': 'lin01-deadpool', 'new_vm_datacenter': 'Asgard', 'new_vm_cluster': 'Bifrost', 'new_vm_folder': '/testvms', 'new_vm_datastore': 'StarLord_Datastore01', 'new_vm_cpu': 1, 'new_vm_cpu_cores_per_socket': 1, 'new_vm_memory_mb': 1024, 'new_vm_network': 'VM Network'}, 'ansible_loop_var': 'item'})

TASK [Create a virtual machine from a template] ***********************************************************************************************************************************
changed: [localhost] => (item={'template_name': 'Wakanda_Forever_Win_01', 'template_datacenter': 'Asgaurd', 'template_disksize': 90, 'new_vm_name': 'win01-deadpool', 'new_vm_datacenter': 'Asgard', 'new_vm_cluster': 'Bifrost', 'new_vm_folder': '/testvms', 'new_vm_datastore': 'StarLord_Datastore01', 'new_vm_cpu': 2, 'new_vm_cpu_cores_per_socket': 1, 'new_vm_memory_mb': 2048, 'new_vm_network': 'VM Network'})
changed: [localhost] => (item={'template_name': 'Wakanda_Ubuntu_01', 'template_datacenter': 'Asgard', 'template_disksize': 100, 'new_vm_name': 'lin01-deadpool', 'new_vm_datacenter': 'Asgard', 'new_vm_cluster': 'Bifrost', 'new_vm_folder': '/testvms', 'new_vm_datastore': 'StarLord_Datastore01', 'new_vm_cpu': 1, 'new_vm_cpu_cores_per_socket': 1, 'new_vm_memory_mb': 1024, 'new_vm_network': 'VM Network'})

TASK [Gather information of Virtual Machine] **************************************************************************************************************************************
ok: [localhost] => (item={'template_name': 'Wakanda_Forever_Win_01', 'template_datacenter': 'Asgaurd', 'template_disksize': 90, 'new_vm_name': 'win01-deadpool', 'new_vm_datacenter': 'Asgard', 'new_vm_cluster': 'Bifrost', 'new_vm_folder': '/testvms', 'new_vm_datastore': 'StarLord_Datastore01', 'new_vm_cpu': 2, 'new_vm_cpu_cores_per_socket': 1, 'new_vm_memory_mb': 2048, 'new_vm_network': 'VM Network'})
ok: [localhost] => (item={'template_name': 'Wakanda_Ubuntu_01', 'template_datacenter': 'Asgard', 'template_disksize': 100, 'new_vm_name': 'lin01-deadpool', 'new_vm_datacenter': 'Asgard', 'new_vm_cluster': 'Bifrost', 'new_vm_folder': '/testvms', 'new_vm_datastore': 'StarLord_Datastore01', 'new_vm_cpu': 1, 'new_vm_cpu_cores_per_socket': 1, 'new_vm_memory_mb': 1024, 'new_vm_network': 'VM Network'})

TASK [Set facts VM info] **********************************************************************************************************************************************************
ok: [localhost] => (item={'instance': {'module_hw': True, 'hw_name': 'win01-deadpool', 'hw_power_status': 'poweredOn', 'hw_guest_full_name': 'Microsoft Windows Server 2019 (64-bit)', 'hw_guest_id': 'windows2019srv_64Guest', 'hw_product_uuid': '4202c1b0-9a71-d9a6-6e49-679aa5479fcf', 'hw_processor_count': 2, 'hw_cores_per_socket': 1, 'hw_memtotal_mb': 2048, 'hw_interfaces': ['eth0'], 'hw_datastores': ['StarLord_Datastore01'], 'hw_files': ['[StarLord_Datastore01] win01-deadpool/win01-deadpool.vmx', '[StarLord_Datastore01] win01-deadpool/win01-deadpool.nvram', '[StarLord_Datastore01] win01-deadpool/win01-deadpool.vmsd', '[StarLord_Datastore01] win01-deadpool/win01-deadpool.vmxf', '[StarLord_Datastore01] win01-deadpool/win01-deadpool_2.vmdk'], 'hw_esxi_host': 'thor.vcloud-lab.com', 'hw_guest_ha_state': None, 'hw_is_template': False, 'hw_folder': '/Asgard/vm/testvms', 'hw_version': 'vmx-19', 'instance_uuid': '5002965e-0517-ebeb-3b11-c87bf069eccb', 'guest_tools_status': 'guestToolsRunning', 'guest_tools_version': '11365', 'guest_question': None, 'guest_consolidation_needed': False, 'ipv4': None, 'ipv6': 'fe80::f9f9:614b:a68d:6111', 'annotation': '', 'customvalues': {}, 'snapshots': [], 'current_snapshot': None, 'vnc': {}, 'moid': 'vm-17027', 'vimref': 'vim.VirtualMachine:vm-17027', 'advanced_settings': {'tools.guest.desktop.autolock': 'FALSE', 'nvram': 'win01-deadpool.nvram', 'svga.present': 'TRUE', 'pciBridge0.present': 'TRUE', 'pciBridge4.present': 'TRUE', 'pciBridge4.virtualDev': 'pcieRootPort', 'pciBridge4.functions': '8', 'pciBridge5.present': 'TRUE', 'pciBridge5.virtualDev': 'pcieRootPort', 'pciBridge5.functions': '8', 'pciBridge6.present': 'TRUE', 'pciBridge6.virtualDev': 'pcieRootPort', 'pciBridge6.functions': '8', 'pciBridge7.present': 'TRUE', 'pciBridge7.virtualDev': 'pcieRootPort', 'pciBridge7.functions': '8', 'hpet0.present': 'TRUE', 'sched.cpu.latencySensitivity': 'normal', 'disk.EnableUUID': 'TRUE', 'viv.moid': '7423dbca-d696-4631-88a6-e1b1b9e794e3:vm-17027:0xIXnp1EzcW6yxh0EbtEi/FzWUxENt4FmOaL4g/7pOw=', 'ethernet0.pciSlotNumber': '192', 'monitor.phys_bits_used': '45', 'numa.autosize.cookie': '20012', 'numa.autosize.vcpu.maxPerVirtualNode': '2', 'pciBridge0.pciSlotNumber': '17', 'pciBridge4.pciSlotNumber': '21', 'pciBridge5.pciSlotNumber': '22', 'pciBridge6.pciSlotNumber': '23', 'pciBridge7.pciSlotNumber': '24', 'sata0.pciSlotNumber': '32', 'scsi0.pciSlotNumber': '160', 'scsi0.sasWWID': '50 05 05 60 9a 71 d9 a0', 'softPowerOff': 'FALSE', 'usb_xhci.pciSlotNumber': '224', 'usb_xhci:4.deviceType': 'hid', 'usb_xhci:4.parent': '-1', 'usb_xhci:4.port': '4', 'usb_xhci:4.present': 'TRUE', 'vm.genidX': '2048100120919612395', 'vmotion.checkpointFBSize': '4194304', 'vmotion.checkpointSVGAPrimarySize': '8388608', 'vmotion.svga.graphicsMemoryKB': '8192', 'vmotion.svga.mobMaxSize': '8388608', 'toolsInstallManager.lastInstallError': '0', 'svga.guestBackedPrimaryAware': 'TRUE', 'tools.remindInstall': 'FALSE', 'toolsInstallManager.updateCounter': '1', 'guestInfo.detailed.data': "architecture='X86' bitness='64' buildNumber='17763' distroName='Windows' distroVersion='10.0' familyName='Windows' kernelVersion='17763.737' prettyName='Windows Server 2019, 64-bit (Build 17763.737)'", 'vmware.tools.internalversion': '11365', 'vmware.tools.requiredversion': '11365', 'migrate.hostLogState': 'none', 'migrate.migrationId': '0', 'migrate.hostLog': 'win01-deadpool-3993a10a.hlog', 'sched.swap.derivedName': '/vmfs/volumes/6157d890-878ae980-677d-c81f66ea874d/win01-deadpool/win01-deadpool-36cbef6c.vswp', 'scsi0:0.redo': '', 'vm.genid': '-9119633699624726574', 'guestinfo.driver.vmci.version': '9.8.18.0', 'guestinfo.driver.vsock.version': '9.8.17.0', 'guestinfo.driver.pvscsi.version': '1.3.17.0', 'guestinfo.vmtools.buildNumber': '18557794', 'guestinfo.vmtools.description': 'VMware Tools 11.3.5 build 18557794', 'guestinfo.vmtools.versionNumber': '11365', 'guestinfo.vmtools.versionString': '11.3.5', 'guestinfo.Cb.InstallStatus': '3013', 'guestinfo.Cb.LauncherVersion': '1.1.0', 'guestinfo.gc.notification': 'WinMgmt : ', 'guestinfo.driver.wddm.version': '8.17.03.0005', 'guestinfo.appInfo': ''}, 'hw_cluster': 'Bifrost', 'hw_eth0': {'addresstype': 'assigned', 'label': 'Network adapter 1', 'macaddress': '00:50:56:82:11:4a', 'ipaddresses': ['fe80::f9f9:614b:a68d:6111', '169.254.97.17'], 'macaddress_dash': '00-50-56-82-11-4a', 'summary': 'VM Network', 'portgroup_portkey': None, 'portgroup_key': None}, 'tpm_info': {'tpm_present': False, 'provider_id': None}}, 'invocation': {'module_args': {'hostname': '192.168.34.20', 'username': 'administrator@vsphere.local', 'password': 'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER', 'validate_certs': False, 'datacenter': 'Asgard', 'name': 'win01-deadpool', 'port': 443, 'name_match': 'first', 'use_instance_uuid': False, 'tags': False, 'schema': 'summary', 'tag_details': False, 'proxy_host': None, 'proxy_port': None, 'uuid': None, 'moid': None, 'folder': None, 'properties': None}}, 'failed': False, 'changed': False, 'item': {'template_name': 'Wakanda_Forever_Win_01', 'template_datacenter': 'Asgaurd', 'template_disksize': 90, 'new_vm_name': 'win01-deadpool', 'new_vm_datacenter': 'Asgard', 'new_vm_cluster': 'Bifrost', 'new_vm_folder': '/testvms', 'new_vm_datastore': 'StarLord_Datastore01', 'new_vm_cpu': 2, 'new_vm_cpu_cores_per_socket': 1, 'new_vm_memory_mb': 2048, 'new_vm_network': 'VM Network'}, 'ansible_loop_var': 'item'})
ok: [localhost] => (item={'instance': {'module_hw': True, 'hw_name': 'lin01-deadpool', 'hw_power_status': 'poweredOn', 'hw_guest_full_name': '', 'hw_guest_id': None, 'hw_product_uuid': '42029779-e410-09b6-65f1-d6aa4fd3c2dd', 'hw_processor_count': 1, 'hw_cores_per_socket': 1, 'hw_memtotal_mb': 1024, 'hw_interfaces': ['eth0'], 'hw_datastores': ['StarLord_Datastore01'], 'hw_files': ['[StarLord_Datastore01] lin01-deadpool/lin01-deadpool.vmx', '[StarLord_Datastore01] lin01-deadpool/lin01-deadpool.vmsd', '[StarLord_Datastore01] lin01-deadpool/lin01-deadpool.nvram', '[StarLord_Datastore01] lin01-deadpool/lin01-deadpool.vmdk'], 'hw_esxi_host': 'thor.vcloud-lab.com', 'hw_guest_ha_state': None, 'hw_is_template': False, 'hw_folder': '/Asgard/vm/testvms', 'hw_version': 'vmx-14', 'instance_uuid': '5002116d-94e3-926b-9359-4bfcdfa83e2b', 'guest_tools_status': 'guestToolsRunning', 'guest_tools_version': '11296', 'guest_question': None, 'guest_consolidation_needed': False, 'ipv4': '192.168.1.177', 'ipv6': None, 'annotation': '', 'customvalues': {}, 'snapshots': [], 'current_snapshot': None, 'vnc': {}, 'moid': 'vm-17028', 'vimref': 'vim.VirtualMachine:vm-17028', 'advanced_settings': {'sched.cpu.latencySensitivity': 'normal', 'tools.guest.desktop.autolock': 'FALSE', 'pciBridge0.present': 'TRUE', 'svga.present': 'TRUE', 'pciBridge4.present': 'TRUE', 'pciBridge4.virtualDev': 'pcieRootPort', 'pciBridge4.functions': '8', 'pciBridge5.present': 'TRUE', 'pciBridge5.virtualDev': 'pcieRootPort', 'pciBridge5.functions': '8', 'pciBridge6.present': 'TRUE', 'pciBridge6.virtualDev': 'pcieRootPort', 'pciBridge6.functions': '8', 'pciBridge7.present': 'TRUE', 'pciBridge7.virtualDev': 'pcieRootPort', 'pciBridge7.functions': '8', 'hpet0.present': 'TRUE', 'sound.pciSlotNumber': '34', 'mks.enable3d': 'TRUE', 'sata0:1.autodetect': 'TRUE', 'serial0.autodetect': 'TRUE', 'ethernet0.pciSlotNumber': '33', 'virtualHW.productCompatibility': 'hosted', 'nvram': 'lin01-deadpool.nvram', 'viv.moid': '7423dbca-d696-4631-88a6-e1b1b9e794e3:vm-17028:WkEB/hcbIqIgA5rtahi8xMwqjQY0TWK5MkQpI68LMr0=', 'vmware.tools.internalversion': '11296', 'vmware.tools.requiredversion': '11365', 'migrate.hostLogState': 'none', 'migrate.migrationId': '0', 'migrate.hostLog': 'lin01-deadpool-3581e9bf.hlog', 'ehci.pciSlotNumber': '35', 'monitor.phys_bits_used': '43', 'pciBridge0.pciSlotNumber': '17', 'pciBridge4.pciSlotNumber': '21', 'pciBridge5.pciSlotNumber': '22', 'pciBridge6.pciSlotNumber': '23', 'pciBridge7.pciSlotNumber': '24', 'sata0.pciSlotNumber': '36', 'sched.swap.derivedName': '/vmfs/volumes/6157d890-878ae980-677d-c81f66ea874d/lin01-deadpool/lin01-deadpool-ab097581.vswp', 'scsi0.pciSlotNumber': '16', 'scsi0:0.redo': '', 'softPowerOff': 'FALSE', 'usb.pciSlotNumber': '32', 'usb:0.deviceType': 'hid', 'usb:0.parent': '-1', 'usb:0.port': '0', 'usb:0.present': 'TRUE', 'usb:1.deviceType': 'hub', 'usb:1.parent': '-1', 'usb:1.port': '1', 'usb:1.present': 'TRUE', 'usb:1.speed': '2', 'vmotion.checkpointFBSize': '134217728', 'vmotion.checkpointSVGAPrimarySize': '268435456', 'guestinfo.vmtools.buildNumber': '16036546', 'guestinfo.vmtools.description': 'open-vm-tools 11.1.0 build 16036546', 'guestinfo.vmtools.versionNumber': '11296', 'guestinfo.vmtools.versionString': '11.1.0', 'svga.guestBackedPrimaryAware': 'TRUE', 'guestinfo.appInfo': ''}, 'hw_cluster': 'Bifrost', 'hw_eth0': {'addresstype': 'assigned', 'label': 'Network adapter 1', 'macaddress': '00:50:56:aa:35:29', 'ipaddresses': None, 'macaddress_dash': '00-50-56-aa-35-29', 'summary': 'VM Network', 'portgroup_portkey': None, 'portgroup_key': None}, 'tpm_info': {'tpm_present': False, 'provider_id': None}}, 'invocation': {'module_args': {'hostname': '192.168.34.20', 'username': 'administrator@vsphere.local', 'password': 'VALUE_SPECIFIED_IN_NO_LOG_PARAMETER', 'validate_certs': False, 'datacenter': 'Asgard', 'name': 'lin01-deadpool', 'port': 443, 'name_match': 'first', 'use_instance_uuid': False, 'tags': False, 'schema': 'summary', 'tag_details': False, 'proxy_host': None, 'proxy_port': None, 'uuid': None, 'moid': None, 'folder': None, 'properties': None}}, 'failed': False, 'changed': False, 'item': {'template_name': 'Wakanda_Ubuntu_01', 'template_datacenter': 'Asgard', 'template_disksize': 100, 'new_vm_name': 'lin01-deadpool', 'new_vm_datacenter': 'Asgard', 'new_vm_cluster': 'Bifrost', 'new_vm_folder': '/testvms', 'new_vm_datastore': 'StarLord_Datastore01', 'new_vm_cpu': 1, 'new_vm_cpu_cores_per_socket': 1, 'new_vm_memory_mb': 1024, 'new_vm_network': 'VM Network'}, 'ansible_loop_var': 'item'})

TASK [Set ethernet adapter to connected and start_connected on new VM] ************************************************************************************************************
changed: [localhost] => (item={'template_name': 'Wakanda_Forever_Win_01', 'template_datacenter': 'Asgaurd', 'template_disksize': 90, 'new_vm_name': 'win01-deadpool', 'new_vm_datacenter': 'Asgard', 'new_vm_cluster': 'Bifrost', 'new_vm_folder': '/testvms', 'new_vm_datastore': 'StarLord_Datastore01', 'new_vm_cpu': 2, 'new_vm_cpu_cores_per_socket': 1, 'new_vm_memory_mb': 2048, 'new_vm_network': 'VM Network'})
changed: [localhost] => (item={'template_name': 'Wakanda_Ubuntu_01', 'template_datacenter': 'Asgard', 'template_disksize': 100, 'new_vm_name': 'lin01-deadpool', 'new_vm_datacenter': 'Asgard', 'new_vm_cluster': 'Bifrost', 'new_vm_folder': '/testvms', 'new_vm_datastore': 'StarLord_Datastore01', 'new_vm_cpu': 1, 'new_vm_cpu_cores_per_socket': 1, 'new_vm_memory_mb': 1024, 'new_vm_network': 'VM Network'})

PLAY RECAP ************************************************************************************************************************************************************************
localhost                  : ok=8    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Useful Articles
Using Ansible for Managing VMware vSphere Infrastructure
Ansible for VMwary Using vmware_vm_inventory dynamic inventory plugin
How to install Ansible on Linux for vSphere configuration
Ansible selectattr The error was TemplateRuntimeError no test named 'equalto'
ansible create an array with set_fact
Ansible get information from esxi advanced settings nested dictionary with unique keynames
Install Ansible AWX Tower on Ubuntu Linux
Ansible AWX installation error Cannot have both the docker-py and docker python modules
Ansible AWX installation error docker-compose run --rm --service-ports task awx-manage migrate --no-input
docker: Got permission denied while trying to connect to the Docker daemon socket
Ansible AWX Tower create Manual SCM (Source Control Credential Type) project
Reset Ansible AWX Tower admin password
Install Ansible AWX on Microsoft Windows OS

Go Back

Comment

Blog Search

Page Views

11374179

Follow me on Blogarama