Exercise - Surveys

Read this in other languages:
UK English, Japan 日本語, Brazil Portuguese do Brasil, France Française, Español Español

Table of Contents

Objective

Demonstrate the use of the Ansible Automation Controller survey feature. Surveys allow for setting extra variables for the playbook, similar to ‘Prompt for Extra Variables,’ but in a user-friendly Q&A format. They also allow for validation of user input.

Guide

You’ve installed Apache on all hosts in the job you just ran. Now, let’s build on this:

Additionally, the role will ensure that the Apache configuration is set up correctly for this exercise.

Tip
The survey feature provides a simple query for data but does not support dynamic data queries, nested menus, or four-eye principles.

The Apache-Configuration Role

The playbook and role with the Jinja2 template are located in the GitHub repository https://github.com/ansible/workshop-examples in the rhel/apache directory.

The playbook creates a file (dest) on the managed hosts from the template (src).

Because the playbook and role are located in the same GitHub repo as the apache_install.yml playbook, you don’t need to configure a new project for this exercise.

Create a Template with a Survey

Now, let’s create a new Template that includes a survey.

Create Template

  1. Go to Automation Execution → Templates, click the Create template button, and choose Create job template.

  2. Fill out the following details:

Parameter Value
Name Create index.html
Job Type Run
Inventory Workshop Inventory
Project Workshop Project
Execution Environment Default execution environment
Playbook rhel/apache/apache_role_install.yml
Credentials Workshop Credential
Limit web
Options Privilege Escalation
  1. Click Save.

template details

Warning
Do not run the template yet!

Add the Survey

  1. In the Template, click the Survey tab, then click Create survey question.
  2. Fill out the following for the first survey question:
Parameter Value
Question First Line
Answer Variable Name first_line
Answer Type Text

Survey Q1

  1. Click Save.
  2. Click Create survey question to create a second survey question:
Parameter Value
Question Second Line
Answer Variable Name second_line
Answer Type Text

Survey Q2

  1. Click Save.
  2. Enable the survey by toggling the Survey disabled button to the on positon.

Launch the Template

Now, launch the Create index.html job template by clicking the Launch template button.

Before the job starts, the survey will prompt for First Line and Second Line. Enter your text and click Next. The Preview window shows the values—if all looks good, click Finish to start the job.

Survey Launch

Survey Review

Once the job completes, verify the Apache homepage by running the following curl command in the SSH console on the control host:

$ curl http://node1
<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>

Navigation

Previous Exercise - Next Exercise