---
- name: Deploy a VM from a library "Linux_Templates"
hosts: localhost
gather_facts: yes
vars:
hostname: "{{ lookup('env', 'VMWARE_HOST') }}" # vCenter Server hostname or IP address
username: "{{ lookup('env', 'VMWARE_USER') }}" # vCenter Server username
password: "{{ lookup('env', 'VMWARE_PASSWORD') }}" # vCenter Server password
vm_name: "{{new_name}}" # Name to give to the new VM
esxi_hostname: "esx node name" #ESX node name
datastore: "datastore name" # Name of the datastore to use
cluster_ID: "cluster name" # Cluster name
folder_path: "folder path name" # Name of the folder to place the new VM in
content_library: "content library id"
library_item: "item id"
AD_Domain: "domain name" # Domain name
AD_Domain_alt: "alt domain name" # Alternative domain name
sudo_users: "{{sudo_user_add}}" # Sudo users to add to vm
tasks:
- name: get the list of items of the NFS library
vmware.vmware_rest.content_library_item_info:
vcenter_hostname: "{{hostname}}"
vcenter_username: "{{username}}"
vcenter_password: "{{password}}"
library_id: "{{content_library}}"
library_item_id: "{{library_item}}"
register: content_library_result
- name: Create a new VM based on the template
vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
vcenter_hostname: "{{hostname}}"
vcenter_username: "{{username}}"
vcenter_password: "{{password}}"
name: "{{vm_name}}"
vcenter_validate_certs: false
library: "{{content_library}}"
template_library_item: "{{library_item}}"
placement:
cluster: "{{cluster_ID}}"
folder: "{{folder_path}}"
#resource_pool: "{{ lookup('vmware.vmware_rest.resource_pool_moid', '/my_dc/host/my_cluster/Resources')}}"
state: deploy
powered_on: True
register: my_new_vm
- name: Pause for 1 minutes for server to boot up
ansible.builtin.pause:
seconds: 30
also when using the community collection i was able to just also add a task you use bash shell,
timeout 60s echo '{{vcenter_password}}' | sudo realm join --verbose exsample.COM -U 'user' --install=/
any help would be appreciated here