# vmware\_guest Trying to deploy 2 VM simulteaneously.  One will almost always fail

**URL:** <https://forum.ansible.com/t/vmware-guest-trying-to-deploy-2-vm-simulteaneously-one-will-almost-always-fail/28228>\
**Category:** Ansible Project\
**Tags:** windows, vmware\
**Created:** [August 1, 2018, 8:17pm UTC](https://forum.ansible.com/t/vmware-guest-trying-to-deploy-2-vm-simulteaneously-one-will-almost-always-fail/28228 "2018-08-01T20:17:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sylvain\_Martel](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@Sylvain\_Martel](https://forum.ansible.com/u/Sylvain_Martel)\
**Post date:** [August 1, 2018, 8:17pm UTC](https://forum.ansible.com/t/vmware-guest-trying-to-deploy-2-vm-simulteaneously-one-will-almost-always-fail/28228/1 "2018-08-01T20:17:51Z")

</div>

Hi,

We are experimenting with Ansible to deploy VM and, I am not sure what is the problem, but when I try to deploy 2 VM at the same time, one will fails 99% of the time, while the other will complete.

The one that has the problem is actually stuck in the customization phase, and then the playbook will fail as Ansible tries to continue with the following plays, but of course those fails since the OS is stuck in la-la land. The OS is Windows 2016.

Strangely, I didn’t have this problem 3 weeks ago, but in the meantime we updated to Ansible 2.6.1. I downgraded to 2.5 but the problem stayed.

Also, if I try to deploy one Vm, then the other, it works fine, so the problem is really when they are deployed at the same time.

The initial deployment from the Template works, but the customization, where the VM is given it’s true IP, DNS and joins the domain, is the place where it fails.

And now, the real kicker: If I try 3 vm at the same time, it goes through without problem and all 3 completes succesfully…(!)

I’m baffled.

When it fails, in Vmware, there is always an alert on the problematic VM about a VM MAC conflict. But when I look at it’s MAC address, it’s not a duplicate.

Any leads?

Here is the playbook

- hosts: all  
gather\_facts: false

vars\_prompt:

- name: “notes”  
prompt: “VM notes”  
private: no  
default: “Deployed with ansible”

roles:

- deploy\_vmware\_guest
- activate\_winrm
- config\_lcm

Here is the main task.

# get date

- set\_fact: creationdate=“{{lookup(‘pipe’,‘date “+%Y/%m/%d %H:%M”’)}}”

- name: Create a VM from a template  
delegate\_to: localhost  
vmware\_guest:  
hostname: ‘{{ vsphere\_host }}’  
username:   
password: “{{ admin\_pass }}”  
validate\_certs: no  
esxi\_hostname:   
datacenter: SECURSANTE-TECNO  
folder: testvm  
name: ‘{{ inventory\_hostname }}’  
annotation: “{{ notes }} - {{ creationdate }} - {{ inventory\_hostname }}”  
state: poweredon  
template: TMPL-W2016-STD-18-02-07\_L12018  
disk:

- size\_gb: 80  
type: thin  
datastore: ‘{{ datastore\_1 }}’

- size\_gb: 20  
type: thin  
datastore: ‘{{ datastore\_1 }}’

- size\_gb: 4  
type: thin  
datastore: ‘{{ datastore\_1 }}’

- size\_gb: 4  
type: thin  
datastore: ‘{{ datastore\_1 }}’

- size\_gb: 4  
type: thin  
datastore: ‘{{ datastore\_1 }}’

- size\_gb: 4  
type: thin  
datastore: ‘{{ datastore\_1 }}’  
hardware:  
memory\_mb: 2048  
num\_cpus: 2  
networks:

- name: DVSTECA-531-S4-TECNOA-EXP-ACC  
ip: ‘{{ vm\_ip }}’  
netmask: 255.255.255.0  
gateway: 172.24.131.254  
dns\_servers:

- 172.24.134.8

- 172.24.134.9  
#mac: ‘{{ vm\_mac }}’  
customization:  
dns\_servers:

- 172.24.134.8

- 172.24.134.9  
dns\_suffix: “{{ domain\_t\_suffix }}”  
domain: “{{ domain\_t }}”  
password: “{{ admin\_pass }}”  
joindomain: “{{ domain\_t }}”  
domainadmin:   
domainadminpassword: “{{ admin\_pass }}”  
hostname: ‘{{ inventory\_hostname }}’  
wait\_for\_ip\_address: yes

vars:  
admin\_pass:

- name: sleep for 300 seconds and continue with play #to give enough time to join the domain since Ansible doesn’t wait for that  
wait\_for: timeout=300  
delegate\_to: localhost

---

<div class="post-metadata">

**Author:** ![Sylvain\_Martel](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@Sylvain\_Martel](https://forum.ansible.com/u/Sylvain_Martel)\
**Post date:** [August 2, 2018, 12:34pm UTC](https://forum.ansible.com/t/vmware-guest-trying-to-deploy-2-vm-simulteaneously-one-will-almost-always-fail/28228/2 "2018-08-02T12:34:26Z")

</div>

To anyone else that might encounter this problem, I found this thread: [https://groups.google.com/forum/#!searchin/ansible-project/vm$20stuck|sort:date/ansible-project/H\_0FhXkm2ns/-TvY5Fc1AgAJ](https://groups.google.com/forum/#!searchin/ansible-project/vm$20stuck%7Csort:date/ansible-project/H_0FhXkm2ns/-TvY5Fc1AgAJ)

which mention this article : [http://www.hurryupandwait.io/blog/getting-readytroubleshooting-unattended-windows-installation](http://www.hurryupandwait.io/blog/getting-readytroubleshooting-unattended-windows-installation)

It helped me to debug the problem and it’s not related to ansible.

My best guest is that the MAC conflict happens at the worst of time and prevent the correct domain discovery. Maybe if there was a way to include a small delay in task to ensure the MAC address change happens before, but that would be though.

Thanks.

---

<div class="post-metadata">

**Author:** ![Sylvain\_Martel](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@Sylvain\_Martel](https://forum.ansible.com/u/Sylvain_Martel)\
**Post date:** [August 2, 2018, 3:53pm UTC](https://forum.ansible.com/t/vmware-guest-trying-to-deploy-2-vm-simulteaneously-one-will-almost-always-fail/28228/3 "2018-08-02T15:53:41Z")

</div>

After reading what seemed like a bazillions support thread on Vmware, I managed to make the sequence work with this workaround:

1- Make sure the NIC in the template is “disabled”  
2- In the playbook, in your vmware\_guest task, under networks, make sure to add start\_connected: yes  
networks:  
start\_connected: yes

The sequence should work fine after that. The slight delay to reactivate the NIC seems enough to make sure the guestOs won’t start trying to join the domain at the same time there are changes made to the networking parts of the guest.
