Ansible deploy VMware a Windows VM Template

Hi experts,

One question please,

Actually I working and testing Ansible for deploy a specified VM in a VMware infrastructure (Windows Server 2016) and I heve a problem when this VM is deployed and started,
I not have idea automate “press Next” and specify the Administrator password. I attach the images, (the Accept the language keyboard, License rights, and administrator password),

Any idea for help me please?. Thank you!!!

/Xavi

Hello,

You have two options (from my point of view) to do that

  • Create a Windows 2016 template with all infos already in it and deploy your VM with this template. Warning; deployment with ansible module vsphere_guest and vmware_guest will result in a “clone” meaning all your VMs deployed with this template will have the same SSID
  • You create a generic Windows 2016 template (with VMTools installed), and after deployment through ansible modules, you use ansible to execute a powercli script to do a sysprep through the VMTools.

Example of the powercli script (this assume that you have Linux Powercli installed on your ansible server and that you have generated a unattended.xml file with the adequate Windows tool)
The unattended.xml file will have all the info to skip the screens that aare bloking you.

#Connect to the vCenter
connect-VIServer $vCenter -user $vCenterUser -password $vCenterPassword

#Building the credential object - Credentials of the Guest OS.
$SafeModePassword = ConvertTo-SecureString $VMPassword -AsPlainText -Force
$GuestCredentials = New-Object System.Management.Automation.PSCredential ($VMUser, $SafeModePassword)

#Delete the unattended file if it exists
#Need to be sure even if we delete it after sysprep
Invoke-VMScript -ScriptText “del C:\windows\temp\unattended.xml” -VM $VM -GuestCredential $GuestCredentials | out-null

#Creates setupcomplete.cmd file to delete sysprep XML file post-sysprep. File must not already exist.
#if the folder exist already, not a problem
$completescript = “mkdir c:\windows\setup\scripts; echo "del c:\windows\temp\unattended.xml” | out-file -force -encoding ASCII c:\windows\setup\scripts\setupcomplete.cmd"
Invoke-VMScript -ScriptText $completescript -VM $VM -GuestCredential $GuestCredentials

#Modify unattend file to change the default password in it
#Needed because in Windows 2016, the sysprep reinitiliaze the admin password…
$xml = [xml](Get-Content $xmlpath)
$node = $xml.unattend.settings.component.useraccounts.AdministratorPassword
$node.value = $VMPassword
$node.PlainText = “true”
$xml.Save($xmlpath)

#Copy the unattended file on the Windows server through the VMTools
copy-vmguestfile -source $xmlpath -destination c:\windows\temp -VM $VM -localtoguest -GuestCredential $GuestCredentials

#Builing Script
$Script = “C:\Windows\System32\Sysprep\Sysprep.exe /generalize /oobe /reboot /quiet /unattend:C:\windows\temp\unattended.xml”

#Running script on the VM through VMTools
Invoke-VMScript -ScriptText $Script -VM $VM -GuestCredential $GuestCredentials -runasync

Start-Sleep -s 120

#disconnect from vCenter
disconnect-VIServer -confirm:$false

Hope this can help you.

Best Regards,

Sebastien