# Processing compound list using with\_items

**URL:** <https://forum.ansible.com/t/processing-compound-list-using-with-items/30788>\
**Category:** AWX Project\
**Created:** [July 15, 2019, 5:06pm UTC](https://forum.ansible.com/t/processing-compound-list-using-with-items/30788 "2019-07-15T17:06:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darrin\_Miskiewicz](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@Darrin\_Miskiewicz](https://forum.ansible.com/u/Darrin_Miskiewicz)\
**Post date:** [July 15, 2019, 5:06pm UTC](https://forum.ansible.com/t/processing-compound-list-using-with-items/30788/1 "2019-07-15T17:06:59Z")

</div>

Hello,  
I am trying to figure out how to create a multi element list via Survey and iterate through the list using _with\_item_ or _loop_. I can figure out how to create a list for each element (i.e name, app pool, ip etc. ) but can’t figure out how to have Ansible then iterate through those lists. I assume I need to some how define that the var is a list but how? Relatively new to Ansible but I am not having luck finding any documentation on this.

- name: create new website  
win\_iis\_website:  
name: “{{ item.name }}”  
state: “{{ state }}”  
ip: “{{ item.ip }}”

# hostname: “{{ item.hostname }}”

application\_pool: “{{ item.application\_pool }}”  
physical\_path: “{{ item.physical\_path }}”  
with\_items:

- { name: “{{ sites }}” , application\_pool: “{{ app\_pools }}”, ip: “{{ ip }}”, physical\_path: “{{ Path }}” }

---

<div class="post-metadata">

**Author:** ![shivharsh.nec](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@shivharsh.nec](https://forum.ansible.com/u/shivharsh.nec)\
**Post date:** [July 19, 2019, 6:44am UTC](https://forum.ansible.com/t/processing-compound-list-using-with-items/30788/2 "2019-07-19T06:44:24Z")

</div>

Hi,

In order to create a list using survey, you need to use the “Answer Type” as “Multiple Choice (multiple select)” when you are adding details in ADD SURVEY PROMPT form. As shown in the screenshot, each element of the list has to be added in a new line.

 ![survey_form.PNG](https://us1.discourse-cdn.com/ansible/original/2X/e/e5d3887874b87acb5456a1fb429b78fc03a3b10e.png)

Once the survey is added as shown in the screenshot, a variable of list type is created as shown below:

`  
vars:  
ip:

- x.x.x.x
- y.y.y.y
- z.z.z.z  
`

This list can then be iterated over using loop or with\_item keyword.

`

---

<div class="post-metadata">

**Author:** ![Darrin\_Miskiewicz](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@Darrin\_Miskiewicz](https://forum.ansible.com/u/Darrin_Miskiewicz)\
**Post date:** [July 23, 2019, 3:20pm UTC](https://forum.ansible.com/t/processing-compound-list-using-with-items/30788/3 "2019-07-23T15:20:22Z")

</div>

Thanks you Shivharsh that does help a good bit. That being said, my ultimate goal is to survey for values that will be varying as requests are presented. Essentially each run of this playbook will contain dynamic quantities and values of items. would like to be able to supply that list via survey and not have to edit the survey list or var file each time. It doesn’t appear to me that AWX offers an option to accomplish this via survey yet.

---

<div class="post-metadata">

**Author:** ![shivharsh.nec](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@shivharsh.nec](https://forum.ansible.com/u/shivharsh.nec)\
**Post date:** [July 25, 2019, 11:31am UTC](https://forum.ansible.com/t/processing-compound-list-using-with-items/30788/4 "2019-07-25T11:31:10Z")

</div>

Hi Darrin,

Survey in AWX is simply a replacement for “vars\_prompt” section in Ansible playbook. vars\_prompt section is used to interactively prompt users for input when they run a playbook and is not supported in Ansible Tower and AWX. Therefore, i don’t think you would be able to use Surveys to supply the list of values those are generated during playbook execution.

As mentioned by you :

> Essentially each run of this playbook will contain dynamic quantities and values of items. would like to be able to supply that list via survey and not have to edit the survey list or var file each time

I believe you should be able to fulfill this requirement using the “register” keyword and then accordingly traverse the registered variable for a list of values. It might involve making use of Jinja.  
Could you please be a little more specific on you requirement for me to help you further?

Thanks,  
Shivharsh

---

<div class="post-metadata">

**Author:** ![Darrin\_Miskiewicz](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@Darrin\_Miskiewicz](https://forum.ansible.com/u/Darrin_Miskiewicz)\
**Post date:** [August 8, 2019, 4:02pm UTC](https://forum.ansible.com/t/processing-compound-list-using-with-items/30788/5 "2019-08-08T16:02:39Z")

</div>

Sorry it took so long to get back to you, I really appreciate your help!  
An example use would be:  
A team member wants to add DNS records via playbook. I would like them to launch an AWX template and be prompted for the record names and IPs in a survey. It could be 2 records one time and 10 the next.

I can do this now via lists in the extra vars but I was hoping to make it accessible to other support staff via survey

Thanks again,  
Darrin

---

<div class="post-metadata">

**Author:** ![Darrin\_Miskiewicz](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@Darrin\_Miskiewicz](https://forum.ansible.com/u/Darrin_Miskiewicz)\
**Post date:** [August 12, 2019, 8:18pm UTC](https://forum.ansible.com/t/processing-compound-list-using-with-items/30788/6 "2019-08-12T20:18:04Z")

</div>

I believe I figured it out! I needed to use with\_dict: and then format the Extra vars file as a dictionary. Thanks for your help!! You got me thinking in the correct direction.

---

<div class="post-metadata">

**Author:** ![Dean\_Clark](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@Dean\_Clark](https://forum.ansible.com/u/Dean_Clark)\
**Post date:** [August 13, 2019, 8:50am UTC](https://forum.ansible.com/t/processing-compound-list-using-with-items/30788/7 "2019-08-13T08:50:21Z")

</div>

Hi Darrin, I have a similar problem that I’m attempting to resolve using survey in AWX. Are you able to elaborate a little further on how you were able to come up with a solution using with\_dict.
