Surveys

Surveys in Ansible Automation Controller let you collect extra variables for a playbook through a user-friendly Q&A form, with built-in input validation. In this exercise you will create a job template that uses a Jinja2 role to deploy a custom index.html, attach a survey to collect the template values, and launch the job.

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-tmm/RHEL-workshop-examples in the apache directory.

  • Have a look at the playbook apache_role_install.yml, which references the role.

  • The role is located in the roles/role_apache subdirectory.

  • Inside the role, note the two variables in the templates/index.html.j2 template file marked by {{…​}}.

  • The tasks/main.yml file deploys the template.

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 dropdown, 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

    Playbook

    apache/apache_role_install.yml

    Execution Environment

    Default execution environment

    Credentials

    Workshop Credential

    Limit

    web

    Options

    ✓ Privilege Escalation

  3. Click Create job template.

    template details
Do not run the template yet!

Add the Survey

  1. In the Template, click the Survey tab, then select Create survey question.

  2. Fill out the following for the first survey question:

    Parameter Value

    Question

    What would you like as the headline of your web page?

    Answer Variable Name

    first_line

    Answer Type

    Text

  3. Click Create survey question.

  4. Click Create survey question to create a second survey question:

    Parameter Value

    Question

    What would you like as the subheading of your web page?

    Answer Variable Name

    second_line

    Answer Type

    Text

  5. Click Create survey question.

  6. Enable the survey by toggling the Survey enabled switch to the on position.

    Survey enabled

Launch the Template

Now, launch the Create index.html job template by selecting Launch template from the template’s kebab menu (⋮) on the Templates list page.

Before the job starts, the survey will prompt you for a headline and subheading for your web page. Enter your text and click Next. The Review page shows the values—if all looks good, click Finish to start the job.

Survey Launch
Survey Review

Verify the Result

Once the job completes, verify the Apache homepage is serving your custom content by running a curl command via Run Command:

  1. Go to Automation Execution → Infrastructure → Inventories → Workshop Inventory and open the Hosts tab.

  2. Select node01 and node02, then click Run Command.

  3. In the Details window, set Module to command and Arguments to curl http://localhost. Click Next.

  4. In the Execution Environment window, select Default execution environment. Click Next.

  5. In the Credential window, select Workshop Credentials. Click Next.

  6. Review your inputs and click Finish.

Verify that the output contains the headline and subheading you entered in the survey.

curl output

Summary

In this exercise you:

  • Explored the Apache-configuration role and its Jinja2 template

  • Created a job template for deploying a custom index.html

  • Attached a survey to collect user input for template variables

  • Launched the job and verified the deployed web page