# Help with with\_items and vmware\_guest

**URL:** <https://forum.ansible.com/t/help-with-with-items-and-vmware-guest/30652>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [June 25, 2019, 9:06pm UTC](https://forum.ansible.com/t/help-with-with-items-and-vmware-guest/30652 "2019-06-25T21:06:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_Pole](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@Simon\_Pole](https://forum.ansible.com/u/Simon_Pole)\
**Post date:** [June 25, 2019, 9:06pm UTC](https://forum.ansible.com/t/help-with-with-items-and-vmware-guest/30652/1 "2019-06-25T21:06:06Z")

</div>

Hi,

I’m trying to do something that I thought would be very straghtfoward.  
I’m deploying 3 vms (VMware) on a DHCP network - I then want to get the IP address of the VM and connect to it, just a simple ping.

`

- name: Create stack  
hosts: localhost  
connection: local  
gather\_facts: no  
tasks:
- name: Create Master  
vmware\_guest:  
hostname: “{{hostname}}”  
username: administrator@vsphere.local  
password: “{{password}}”  
validate\_certs: False  
name: testansible2  
template: T-CentOS-7.5-Server-x64  
datacenter: US  
folder: /DC/vm/Deploy  
state: poweredon  
wait\_for\_ip\_address: yes  
register: vm\_master

# - debug: var=vm\_master

- name: Add Master to inventory  
add\_host:  
name: “{{ vm\_master.instance.ipv4 }}”  
groups: master

- name: Create Workers  
vmware\_guest:  
hostname: “{{hostname}}”  
username: administrator@vsphere.local  
password: “{{password}}”  
validate\_certs: False  
name: “{{item.vmname}}”  
template: T-CentOS-7.5-Server-x64  
datacenter: US  
folder: /DC/vm/Deploy  
state: poweredon  
wait\_for\_ip\_address: yes  
with\_items:

- { vmname: “worker1”}

- { vmname: “worker2”}  
register: vm\_workers

# - debug: var=vm\_workers

- name: Add Workers to inventory  
add\_host:  
name: “{{ item.instance.ipv4 }}”  
groups: workers  
with\_items: “{{ vm\_workers.instances }}”

- hosts: workers  
tasks:

- name: Check connection  
ping:

`

The add master works - the add worker with\_items loop doesn’t. I’ve tried vm\_workers.instance / vm\_workers.results but all result is sort of errror.

Any help much appreicated!
