# Trying to capture value from with\_lines loop

**URL:** <https://forum.ansible.com/t/trying-to-capture-value-from-with-lines-loop/26895>\
**Category:** Ansible Project\
**Created:** [March 5, 2018, 3:46am UTC](https://forum.ansible.com/t/trying-to-capture-value-from-with-lines-loop/26895 "2018-03-05T03:46:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Evan](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@Evan](https://forum.ansible.com/u/Evan)\
**Post date:** [March 5, 2018, 3:46am UTC](https://forum.ansible.com/t/trying-to-capture-value-from-with-lines-loop/26895/1 "2018-03-05T03:46:27Z")

</div>

I’m trying to loop through a list (file) of powervc regions, delegating a command to them, and if that command (find a vm) is successful (ie: the vm is on that region) I want to record the region name. I’m using delegate\_to because I have other commands to run that are not on that region.

`

---

<div class="post-metadata">

**Author:** ![flowerysong1](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@flowerysong1](https://forum.ansible.com/u/flowerysong1)\
**Post date:** [March 5, 2018, 4:50am UTC](https://forum.ansible.com/t/trying-to-capture-value-from-with-lines-loop/26895/2 "2018-03-05T04:50:48Z")

</div>

You should look more closely at the contents of the `vm_exist` variable. It contains a list of results, and each result includes the value of `item` for that iteration of the loop.

---

<div class="post-metadata">

**Author:** ![Evan](https://avatars.discourse-cdn.com/v4/letter/e/54ee81/32.png) [@Evan](https://forum.ansible.com/u/Evan)\
**Post date:** [March 5, 2018, 6:27am UTC](https://forum.ansible.com/t/trying-to-capture-value-from-with-lines-loop/26895/3 "2018-03-05T06:27:57Z")

</div>

> > You should look more closely at the contents of the `vm_exist` variable. It contains a list of results, and each result includes the value of `item` for that iteration of the loop.

Hi flowerysong,  
The only reference that I can find in the output of that command is the hypervisor name, which is just the node it’s located on, rather than the powervc region (my powervc region controls several nodes). Unless you mean a reference to the way register stores the values returned?
