Skip to content
Apr 12 / Greg

Ansible Tower/Ansible Control Survey To Template Demo

I recently had a customer ask about how you could present a user with a form they fill out, then that info would be used to complete a template for say a webserver; the simple answer is to use the survey feature in Tower(also sometimes called control in the Ansible Automation Platform).

Demo Video

Resources:

First, my playbook and template can be found here.

The template file is pretty straight forward:

There’s three variables serv_name, option1, and option2 that will be replaced at runtime with the results of the survey.

The playbook is equally simple:

There is really only a single task that really does anything and it is the template task. It calls the survey-template.conf.j2 file, does variable replacement, and then sticks it in the file_loc path.
The remaining two tasks read the file into a variable, then display it. In a real scenario the template file would push the configuration to a server, then perform a restart of the service in question.

Tower/Control:

From the templates section I create a new job template with info to my inventory, credentials, project, and playbook:

Next I click the “add survey” button:

Last I create three entries, each corresponding to a different variable. The survey info is passed at runtime as extra variables.

Now the template can be launched and the info filled out:

I can now see the output of the run in all its glory:

Conclusion:

I hope you can see how info can be gathered via a survey and easily injected into your playbooks to perform any kind of automation you can dream up.

Thanks and happy surveying.

Leave a Comment

 

*