Site icon UnixArena

Ansible Tower / AWX – Passing Variables using SURVEY (extra-vars)

Ansible Survey - UnixArena

Ansible Survey - UnixArena

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"

 

3. Here is my Ansible Tower/ AWX template configuration.

Creating New Template – Ansible

 

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)

Ansible Tower Template – Extra variable

 

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

Ansible Tower – Enable Survey

 

6. Enter the survey details for our variable – “FS_MOUNTPOINT“.  Selected the “Answer type” as text.

Survey – Select the Answer Type – Ansible

 

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.

Ansible Tower – 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.

 

Multiple Survey variable – Ansible Tower – AWX

 

9. Launch the template to check the configured run time variable.

Launch the template to check Survey – Ansible

 

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.

Survey updates Extra variable – Ansible Tower – AWX

 

Hope this article is informative to you.   Share it! Comment it !! Be Sociable !!!

Exit mobile version