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 }}” }
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.
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.
`
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.
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
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
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.
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.