Hi, here is my playbook for windows vm deployment with ansible and vsphere community.
community.vmware.vmware_guest_tools_wait waiting for tools installation but after next tasks they are not starts again. Why?
---
- name : To test VM creation on vSphere
hosts : localhost
gather_facts : True
vars:
WinIso: 'server-2019.iso'
Datastore: 'DS9-1-NVME'
DatastoreDir: 'iso'
autounattend: 'unattend.iso'
vcenter_username: 'vc...@vsphere.local'
vcenter_password: 'vsca2021!'
src: '/mnt/win/unattend.iso'
vm_name: 'test_vm_009'
become_user: root
tasks :
- name: Print all available facts
ansible.builtin.debug:
var: ansible_facts
- name: Repack XML to iso
shell: |
cd mnt/win
FILE="{{src}}"
if test -f "$FILE"; then
rm "$FILE"
fi
genisoimage -o "{{src}}" -J /mnt/autounattend.xml
- name: Copy file to datastore
community.vmware.vsphere_copy:
hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}'
password: '{{ vcenter_password }}'
validate_certs: no
src: /mnt/win/unattend.iso
datastore: DS9-1-NVME
path: /iso/unattend.iso
delegate_to: localhost
- name: Create a virtual machine on given ESXi hostname
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
folder: ESXI9
name: test_vm_009
state: powered-on
guest_id: windows9Server64Guest
# This is hostname of particular ESXi server on which user wants VM to be deployed
esxi_hostname: "{{ esxi_hostname }}"
disk:
- size_gb: 30
controller_number: 0
disk_mode: persistent
unit_number: 0
controller_type: 'sata'
type: thin
datastore: DS9-1-NVME
hardware:
memory_mb: 4096
num_cpus: 4
scsi: paravirtual
networks:
- name: VM Network
ip: 10.10.4.166
netmask: 255.255.255.0
device_type: e1000
type: static
wait_for_ip_address: true
# wait_for_ip_address_timeout: 600
cdrom:
- controller_number: 0
unit_number: 0
type: iso
iso_path: "[{{ Datastore }}] {{ DatastoreDir }}/{{ WinIso }}"
state: present
- controller_number: 0
unit_number: 1
type: iso
iso_path: "[{{ Datastore }}] {{ DatastoreDir }}/{{ autounattend }}"
state: present
delegate_to: localhost
register: deploy_vm
- name: Wait for VMware tools to become available by name
community.vmware.vmware_guest_tools_wait:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
name: test_vm_009
folder: ESXI9
delegate_to: localhost
- name: Sleep for 30 seconds and continue with play
wait_for:
timeout: 30
delegate_to: localhost
- name: Set the state of a virtual machine to restart
community.vmware.vmware_guest_powerstate:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
name: test_vm_009
folder: ESXI9
state: restarted
delegate_to: localhost
- name: Sleep for 5 seconds and continue with play
wait_for:
timeout: 5
delegate_to: localhost
- name: Set the state of a virtual machine to poweroff
community.vmware.vmware_guest_powerstate:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
name: test_vm_009
folder: ESXI9
state: powered-off
delegate_to: localhost
register: deploy
- name: Change video card settings of virtual machine
community.vmware.vmware_guest_video:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
datacenter: "{{ datacenter }}"
name: '{{ vm_name }}'
validate_certs: no
gather_video_facts: false
use_auto_detect: false
display_number: 1
video_memory_mb: 128.0
enable_3D: false
delegate_to: localhost
register: video_facts
- name: Sleep for 3 seconds and continue with play
wait_for:
timeout: 3
delegate_to: localhost
- name: Unattach the ISO mount from the VM
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
folder: ESXI9
name: '{{ vm_name }}'
state: powered-off
guest_id: windows9Server64Guest
esxi_hostname: "{{ esxi_hostname }}"
cdrom:
- controller_number: 0
unit_number: 0
type: none
state: absent
- controller_number: 0
unit_number: 1
type: none
state: absent
delegate_to: localhost
- name: Sleep for 3 seconds and continue with play
wait_for:
timeout: 3
delegate_to: localhost
- name: Set the state of a virtual machine to poweron
community.vmware.vmware_guest_powerstate:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
folder: ESXI9
name: test_vm_009
state: powered-on
delegate_to: localhost
register: deploy