Failed to create a virtual machine : Cannot complete customization
You are able to deploy new virtual machine from template and customize settings via Ansible playbook.
To create this playbook I use Ansible module community.vmware.vmware_guest
I also download a script for Configure Remoting For Ansible and add those to customization when new vm is deployed from template.
Source:
ConfigureRemotingForAnsible.ps1 >> LINK
Ansible playbook >> AnsibleCustomDeploy
Implementation Steps.
1. Login to you template server in my case virtual machine it’s call template2016.
2. Create folder C:\Windows\Temp\ and copy you script there ConfigureRemotingForAnsible.ps1
3. Shutdown your server and convert vm to template.
5. Create or download Ansible playbook
6. Run playbook.
7. I had some issues with error “Failed to create a virtual machine : Cannot complete customization.”
So I start looking is Ansible documentation and I found option wait_for_customization.
Lets add this to playbook and test.
8. Back on track so let’s run playbook again.
9. In meantime you can check on vCenter if templates start’s. Looks good.
10. Playbook will run for about 15-20min and you should see log like below.
11. I open the new virtual machine console when the customization was setting up..
12. After 5 min server was ready. I was logon and check the custom settings.
Below more examples with modules vmware_guest
- name: Create a VM from a template with memory reservation vmware_guest: hostname: 192.0.2.44 username: administrator@vsphere.local password: vmware validate_certs: no folder: /testvms name: testvm_2 state: poweredon template: template2016 disk: - size_gb: 10 type: thin datastore: g73_datastore hardware: memory_mb: 512 num_cpus: 6 num_cpu_cores_per_socket: 3 scsi: paravirtual memory_reservation: 512 memory_reservation_lock: True mem_limit: 8096 mem_reservation: 4096 cpu_limit: 8096 cpu_reservation: 4096 max_connections: 5 hotadd_cpu: True hotremove_cpu: True hotadd_memory: False cdrom: type: iso iso_path: "[datastore1] livecd.iso" networks: - name: VM Network mac: aa:bb:dd:aa:00:14 wait_for_ip_address: yes delegate_to: localhost register: deploy Simple Create a VM template - name: Create a VM template vmware_guest: hostname: 192.0.2.88 username: administrator@vsphere.local password: vmware validate_certs: no datacenter: datacenter1 cluster: vmware_cluster_esx resource_pool: highperformance_pool folder: /testvms name: testvm_6 is_template: yes guest_id: debian6_64Guest disk: - size_gb: 10 type: thin datastore: g73_datastore hardware: memory_mb: 512 num_cpus: 1 scsi: lsilogic delegate_to: localhost register: deploy Rename a VM (requires the VM's uuid) - name: Rename a VM (requires the VM's uuid) vmware_guest: hostname: 192.168.1.209 username: administrator@vsphere.local password: vmware uuid: 421e4592-c069-924d-ce20-7e7533fab926 name: new_name state: present delegate_to: localhost Remove a VM by uuid - name: Remove a VM by uuid vmware_guest: hostname: 192.168.1.209 username: administrator@vsphere.local password: vmware uuid: 421e4592-c069-924d-ce20-7e7533fab926 state: absent delegate_to: localhost - name: Create a virtual machine from a template community.vmware.vmware_guest: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" validate_certs: no folder: /testvms name: testvm_2 state: poweredon template: template_el7 disk: - size_gb: 10 type: thin datastore: g73_datastore # Add another disk from an existing VMDK - filename: "[datastore1] testvms/testvm_2_1/testvm_2_1.vmdk" hardware: memory_mb: 512 num_cpus: 6 num_cpu_cores_per_socket: 3 scsi: paravirtual memory_reservation_lock: True mem_limit: 8096 mem_reservation: 4096 cpu_limit: 8096 cpu_reservation: 4096 max_connections: 5 hotadd_cpu: True hotremove_cpu: True hotadd_memory: False version: 12 # Hardware version of virtual machine boot_firmware: "efi" cdrom: - controller_number: 0 unit_number: 0 state: present type: iso iso_path: "[datastore1] livecd.iso" networks: - name: VM Network mac: aa:bb:dd:aa:00:14 wait_for_ip_address: yes delegate_to: localhost register: deploy - name: Manipulate vApp properties community.vmware.vmware_guest: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" validate_certs: no name: vm_name state: present vapp_properties: - id: remoteIP category: Backup label: Backup server IP type: string value: 10.10.10.1 - id: old_property operation: remove delegate_to: localhost Set powerstate of a virtual machine to poweroff by using UUID - name: Set powerstate of a virtual machine to poweroff by using UUID community.vmware.vmware_guest: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" validate_certs: no uuid: "{{ vm_uuid }}" state: poweredoff delegate_to: localhost - name: Deploy a virtual machine in a datastore different from the datastore of the template community.vmware.vmware_guest: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" name: "{{ vm_name }}" state: present template: "{{ template_name }}" # Here datastore can be different which holds template datastore: "{{ virtual_machine_datastore }}" hardware: memory_mb: 512 num_cpus: 2 scsi: paravirtual delegate_to: localhost - name: Create a diskless VM community.vmware.vmware_guest: validate_certs: False hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" datacenter: "{{ dc1 }}" state: poweredoff cluster: "{{ ccr1 }}" name: diskless_vm folder: /Asia-Datacenter1/vm guest_id: centos64Guest datastore: "{{ ds1 }}" hardware: memory_mb: 1024 num_cpus: 2 num_cpu_cores_per_socket: 1 - name: Create a VM with multiple disks of different disk controller types community.vmware.vmware_guest: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" validate_certs: no folder: /DC1/vm/ name: test_vm_multi_disks state: poweredoff guest_id: centos64Guest datastore: datastore1 disk: - size_gb: 10 controller_type: 'nvme' controller_number: 0 unit_number: 0 - size_gb: 10 controller_type: 'paravirtual' controller_number: 0 unit_number: 1 - size_gb: 10 controller_type: 'sata' controller_number: 0 unit_number: 2 hardware: memory_mb: 512 num_cpus: 4 version: 14 networks: - name: VM Network device_type: vmxnet3 delegate_to: localhost register: deploy_vm - name: create new VMs and autoselect datastore vmware_guest: validate_certs: False hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" name: newvm_1 #template: "{{ item|basename }}" guest_id: centos64Guest datacenter: "{{ dc1 }}" hardware: num_cpus: 1 num_cpu_cores_per_socket: 1 memory_mb: 256 hotadd_memory: true hotadd_cpu: false max_connections: 10 disk: - size: 1gb type: thin autoselect_datastore: True state: poweredoff folder: F0
Please Comment and Subscribe