# Stuck on with\_items and trying to pass specific value from 1 task to the next

**URL:** <https://forum.ansible.com/t/stuck-on-with-items-and-trying-to-pass-specific-value-from-1-task-to-the-next/26647>\
**Category:** Ansible Project\
**Created:** [February 2, 2018, 4:43pm UTC](https://forum.ansible.com/t/stuck-on-with-items-and-trying-to-pass-specific-value-from-1-task-to-the-next/26647 "2018-02-02T16:43:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![davros1984](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@davros1984](https://forum.ansible.com/u/davros1984)\
**Post date:** [February 2, 2018, 4:43pm UTC](https://forum.ansible.com/t/stuck-on-with-items-and-trying-to-pass-specific-value-from-1-task-to-the-next/26647/1 "2018-02-02T16:43:51Z")

</div>

Hi,

I’ve spent the past few days trying to find a solution to a challenge I have. Hopefully someone here has the answer.

Here is a slimmed down version, which hopefully will help me move forwards.  
`

- hosts: satellite  
gather\_facts: False  
remote\_user: root  
tasks:

- name: test  
vmware\_guest\_facts:  
hostname: vcenter  
username: me  
password:   
datacenter: DC1  
folder: /DC1/vm  
validate\_certs: no  
name: “{{ item }}”  
register: facts  
delegate\_to: localhost  
with\_items:

- ltdrob002

- ltdrob003

- debug: msg=“{{ facts.results[0].instance.hw\_eth0.macaddress }}”  
with\_items: “{{ facts.results }}”

`

The above works, it goes to vcenter and prints the MAC address of the first server (in reference to item [0]). However it prints the MAC address of the first VM when its getting the facts of the second VM. What I am trying to achieve is to get the MAC address printed for the relevant VM as it loops through. So in the debug area… I want it to resemble something like:

`

- debug: msg=“{{ item.facts.results.instance.hw\_eth0.macaddress }}”

with\_items: “{{ facts.results }}”

`

The above code doesn’t work and the error…  
“The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘facts’” is seen.

A bit of background… this is optional, help on the above is great for now.  
The challenge I have is that I need to provision a group of VMs, via the use of with\_list (I have a seperate vars file with required vm info in, i.e. vmName: ltdrob003). Currently I have this working fine with just a single VM. I need to pass the MAC address of the VM to Satellite (Hammer) so that Satellite is able to PXE boot/configure the VM.

The MAC address gets generated when the VM is created so this needs to be passed to Hammer. As stated, I have this working for 1 VM at a time, but it would be nice to pass to Ansible a list of VMs to create and have it create them in 1-run. I achieve this currently with the below and the hammer command just references “{{ vm\_mac }}”.

`

- set\_fact:  
vm\_mac: “{{ results.instance.hw\_eth0.macaddress }}”  
`

My plan will be to alter the name of the fact to match the name of the vm, i.e… “{{ vmName }}\_mac”:   
and then have Hammer reference the MAC via lookup:

`mac="{{ vars[vmName + '_mac'] }}":`

I can add further detail, but initially I wanted to try and put a simple example in the hope that this will get some responses.

Many thanks in advance.

---

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [February 5, 2018, 6:10pm UTC](https://forum.ansible.com/t/stuck-on-with-items-and-trying-to-pass-specific-value-from-1-task-to-the-next/26647/2 "2018-02-05T18:10:26Z")

</div>

# The answer in [Ansible lookup values from complex structure?](https://stackoverflow.com/questions/39685255/ansible-lookup-values-from-complex-structure) may give you and idea.
