View on GitHub

ansible

Ansible Lab exercises

Exercise - Surveys

Read this in other languages:
uk English, japan日本語, brazil Portugues do Brasil, france Française, Español Español.

Table Contents

Objective

Demonstrate the use of Ansible Tower survey feature. Surveys set extra variables for the playbook similar to ‘Prompt for Extra Variables’ does, but in a user-friendly question and answer way. Surveys also allow for validation of user input.

Guide

You have installed Apache on all hosts in the job you just run. Now we’re going to extend on this:

Additionally, the role will also make sure that the Apache configuration is properly set up - in case it got mixed up during the other exercises.

Tip

The survey feature only provides a simple query for data - it does not support four-eye principles, queries based on dynamic data or nested menus.

The Apache-configuration Role

The Playbook and the role with the Jinja template already exist in the Github repository https://github.com/ansible/workshop-examples in the directory rhel/apache.

Head over to the Github UI and have a look at the content: the playbook apache_role_install.yml merely references the role. The role can be found in the roles/role_apache subdirectory.

What is this Playbook doing? It creates a file (dest) on the managed hosts from the template (src).

The role also deploys a static configuration for Apache. This is to make sure that all changes done in the previous chapters are overwritten and your examples work properly.

Because the Playbook and role is located in the same Github repo as the apache_install.yml Playbook you don’t have to configure a new project for this exercise.

Create a Template with a Survey

Now you create a new Template that includes a survey.

Create Template

Parameter Value
NAME Create index.html
JOB TYPE Run
INVENTORY Workshop Inventory
Project Workshop Project
PLAYBOOK rhel/apache/apache_role_install.yml
CREDENTIAL Workshop Credentials
LIMIT web
OPTIONS Enable Privilege Escalation

Warning

Do not run the template yet!

Add the Survey

Parameter Value
PROMPT First Line
ANSWER VARIABLE NAME first_line
ANSWER TYPE Text
Parameter Value
PROMPT Second Line
ANSWER VARIABLE NAME second_line
ANSWER TYPE Text

Launch the Template

Now launch Create index.html job template.

Before the actual launch the survey will ask for First Line and Second Line. Fill in some text and click Next. The next window shows the values, if all is good run the Job by clicking Launch.

Tip

Note how the two survey lines are shown to the left of the Job view as Extra Variables.

After the job has completed, check the Apache homepage. In the SSH console on the control host, execute curl against the IP address of your node1:

$ curl http://22.33.44.55
<body>
<h1>Apache is running fine</h1>
<h1>This is survey field "First Line": line one</h1>
<h1>This is survey field "Second Line": line two</h1>
</body>

Note how the two variables where used by the playbook to create the content of the index.html file.


Navigation

Previous Exercise - Next Exercise



Click here to return to the Ansible for Red Hat Enterprise Linux Workshop