# ansible vwmare\_guest, cloning Windows Server 2012R2

**URL:** <https://forum.ansible.com/t/ansible-vwmare-guest-cloning-windows-server-2012r2/25738>\
**Category:** Ansible Project\
**Tags:** windows, vmware\
**Created:** [October 12, 2017, 3:51pm UTC](https://forum.ansible.com/t/ansible-vwmare-guest-cloning-windows-server-2012r2/25738 "2017-10-12T15:51:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [October 12, 2017, 3:51pm UTC](https://forum.ansible.com/t/ansible-vwmare-guest-cloning-windows-server-2012r2/25738/1 "2017-10-12T15:51:44Z")

</div>

Hello,

Can anyone tell me the steps I need to go through to get vmware\_guest to successfully clone a template and have the clone join an existing domain?

Once the clone comes up, it never seems to have network access, so domain joining always fails.  
A lot of times I have tried the network connection profile is marked as ‘public’ and isn’t given access to the internet.

I need to allocate a static IP

I found some link suggesting you have to use sysprep, but if you do so, you have to set language, product key etc manually and to be worthwhile the process needs to be fully automatic. Problems seem to start before that with the networking.

All suggestions gratefully received!

Tried with ansible 2.3 and 2.4 and two different windows templates, one created afresh from ISO .

Playbook below.

Jon

- hosts: localhost  
gather\_facts: true

- hosts: new  
gather\_facts: false  
vars:  
template: New2012R2Template  
vars\_prompt:

- name: ‘vmware\_user’  
prompt: ‘Enter VMWare username’  
private: no

- name: ‘vmware\_cred’  
prompt: ‘Enter VMWare password’  
private: yes  
pre\_tasks:

- name: show what we are planning on doing  
debug:  
msg: “ensure vm with hostname {{inventory\_hostname}} and ip {{hostvars[inventory\_hostname][‘ip’]}} exists.”

- name: clone vmware template and customise so it is ready for use as domain member  
vmware\_guest:  
annotation: “Ansible cloned from template ‘{{template}}’ on {{hostvars[‘localhost’][‘ansible\_date\_time’][‘date’]}} by {{vmware\_user}}”  
cluster: Dev Cluster  
datacenter: Dev  
folder: /Development/  
hostname: vsphere6  
name: “{{inventory\_hostname}}”  
password: “{{ vmware\_cred }}”  
resource\_pool: Normal  
state: poweredon  
template: “{{template}}”  
username: ‘{{vmware\_user}}’  
validate\_certs: no  
networks:

- name: VM Network  
devicetype: vmxnet3

# domain: devdomain.local

gateway: redacted\_ip0  
ip: “{{hostvars[inventory\_hostname][‘ip’]}}”  
netmask: 255.255.128.0  
type: static  
dns\_servers:

- redacted\_ip1
- redacted\_ip2  
customization:  
autologon: yes  
autologoncount: 5  
dns\_servers:
- redacted\_ip1
- redacted\_ip2

# domain: devdomain.local

password: “{{setup\_password}}”  
joindomain: [dcmalvern.smcorp.speechmachines.com](http://dcmalvern.smcorp.speechmachines.com)

domainadmin: “{{ dom\_admin\_user }}”  
domainadminpassword: “{{ dom\_admin\_password }}”  
runonce:

- powershell.exe -ExecutionPolicy Unrestricted -File C:\Users\Administrator\Downloads\ConfigureRemotingForAnsible.ps1 -ForceNewSSLCert
- C:\finishsetup.bat  
delegate\_to: localhost

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [October 17, 2017, 7:21am UTC](https://forum.ansible.com/t/ansible-vwmare-guest-cloning-windows-server-2012r2/25738/2 "2017-10-17T07:21:16Z")

</div>

To follow up on this.

Things I have found that help are:

Set up your networking in your template as close as possible to how you want it in your cloned VMs.  
I got a lot further once I set the networking up in my template VM as static (I need my clones to use static IPs).

Remove device drivers from your template for any network devices which are no longer present (You can do this by starting Device Manager (devmgmt.msc) and clicking on ‘Show hidden devices’ on the View menu.

If your VM gets stuck on the windows ‘Getting Ready’ screen, read this, as not only will it make you laugh and realise others have got past this particular hurdle: [http://www.hurryupandwait.io/blog/getting-readytroubleshooting-unattended-windows-installation](http://www.hurryupandwait.io/blog/getting-readytroubleshooting-unattended-windows-installation) but also there’s a tip in there that will help you debug what is going on.

I had more success when I switched away from the virtual network adapters that require vmware tools - so instead of using VMXNet 3, things seemed to work better using device type: ‘e1000e’ - obviously this is somewhat hardware dependent so things may be different elsewhere. Again, set this up in the template as well is in your playbook.

Hope this helps anyone else trying to do this.

Jon
