Ansible Tower’s Survey one of the cool feature which can be used to populate the variables every time the Template is executed. Ansible playbook might contain one more user variable depends on the use cases. If you want to attach such playbook in AWX / Ansible Tower template, you need to pass the variables in the “EXTRA VARIABLES” box. In the newer version of Ansible Tower /AWX offers “Survey”. It’s prompt for Extra Variables in a user-friendly way (Question and answers). Surveys also allow for validation of user input. You could also hide the input variable to mask specific input like security tokens or passwords.
Let’s walk through about Ansible Tower’s Extra variable input & Survey.
1. Login to Ansible Tower / AWX as privileged user.
2. Here is my sample playbook which requires a variable called “FS_MOUNTPOINT”
--- - hosts: all gather_facts: no tasks: - name: Root FS usage shell: df -h {{ FS_MOUNTPOINT }} |awk ' { print $5 } ' |grep -v Use register: dfroot - debug: msg: "System {{ inventory_hostname }}'s root FS utiliation is {{ dfroot.stdout }}"
To run this playbook from ansible engine, you might need to use the following command.
# ansible-playbook -i temp.hosts Unix_Arena_Demo_df.yaml -e "FS_MOUNTPOINT=/boot"
- temp.hosts – inventory
- -e = extra variable. (FS_MOUNTPOINT=/boot)
3. Here is my Ansible Tower/ AWX template configuration.
Option: 1 – Passing Variable in Extra Variable box
4. Here is the one of the method to pass the variable on ansible template. (Older versions)
- Mark extra variable box to prompt on launch
- Update the variable key in the extra variable box.
Option: 2 – Passing Variable using SURVEY
5. On newer version of Ansible Tower/ AWX, you will get “SURVEY” option to configure. Open the template and click on “Add Survey”.
6. Enter the survey details for our variable – “FS_MOUNTPOINT“. Selected the “Answer type” as text.
7. If the variable is mandatory for the template, please mark it as required. Click on “Add” to add the first variable to the survey.
8. Repeat the same steps if you want to add multiple run-time variables. You could also pass token by selecting Answer type as “password”. So that token will be masked on the jobs.
9. Launch the template to check the configured run time variable.
10. Here we can see that ansible survey automatically updates the extra variable box. Once you launch this template, ansible-playbook command will be involved in the backend using an extra variable flag.
Hope this article is informative to you. Share it! Comment it !! Be Sociable !!!
Brian Schonecker says
The links to your Github account are broken.
Ronny says
Thanks! good explanation
Ziaur Khan says
thank you so much
Sounak Choudhury says
Thanks for explaining so simply. Glad that I googled apart from browsing through the docs
Michael says
Is it also possible to apply composite variables to survey prompt values, e.g. enter /opt/{{ mount_point }} in the prompt dialog?
This is very useful to create Workflows that are more specific to a particular use case, but can still contain parameters.
Azure DevOps supports this and it’s a very useful feature to have.
Ivan says
did you got an answer to this?
sam says
Hello,
Excellent article, Is there any way I can automate survey input value.