Bookmark this page

Using Surveys to Set Variables

Objectives

  • Create and use surveys in automation controller to provide information to Ansible Playbook jobs.

Managing Variables

You should write playbooks that you can reuse in similar situations. For example, you might start by writing a playbook that configures a single managed network node. Later, you might want to use that same playbook to configure additional managed network nodes with slightly different configurations. One way to apply different configuration settings is by using variables to specify those settings.

You can set variables with specific values in many different ways, and you can override them depending on how you set the variables. For example, a role or collection can provide a default value for a variable that you might override with the value set in the inventory that you are using, or in the playbook itself.

In automation controller, you can interactively set variables in two ways:

  • Automation controller can prompt you to enter extra variables when you launch a job from a job template.

  • You can create a survey that presents you with a form to help you set variables when you launch a job from a job template or a workflow template.

Important

Automation controller does not support playbooks that use vars_prompt to interactively set variables.

Defining Extra Variables

In automation controller, you can use a job template to directly set extra variables, using either of the following two methods:

  • Define the variables in YAML or JSON format in the Variables field of the job template. This sets the specific values for extra variables used by the job template.

  • Select Prompt on launch for the Variables field of the job template. This causes automation controller to prompt you to interactively specify and modify extra variables and their values when you use the job template to launch a job.

    Figure 4.1: Prompt for variables when launching a job

Both methods are the same as using the -e or --extra-vars options for the ansible-navigator command. These variables have a high precedence. Except for variables set by a survey, these variable values override any other variables that might have the same name.

If you select Prompt on launch for the Variables field of a job template, then when you launch the job template, automation controller opens a dialog box where you can edit extra variables for the job.

Figure 4.2: Adjusting extra variables on job launch

Important

If you relaunch a job that ran earlier (for example, by clicking the Relaunch Job icon for a job from the Jobs page), then you use the same values for its extra variables that the preceding job used. The extra variables for a job cannot be changed when you relaunch it.

Launch the job from its job template, not by relaunching a previous job, if you want to use different values for its extra variables.

Job Template Surveys

Modifying playbooks with extra variables can be challenging because you need to understand what variables are available and how the job template uses the variables. For example, misspelling the name of an extra variable does not generate an error, but it does not override the intended variable. Even if you wrote a playbook recently, you might not remember the names of all the variables used by the playbook by the time you launch the job template.

Rather than relying on remembering variable names, you can configure a job template or workflow template with a survey. When you launch a job that contains a survey, the web UI displays the survey to prompt you for information that automation controller uses to set values for extra variables. Surveys provide clearer guidance and control for setting extra variables.

Job template surveys offer several advantages over other ways to set extra variables. Users who launch the job do not need to have detailed knowledge about how extra variables work and do not need to know the names of the extra variables used by the playbook.

Important

A survey sets extra variables. The values set by surveys for variables take precedence over all other ways that value might be set.

This includes values set in the job template's Variables field or by using its Prompt on launch setting.

Managing Answers to Survey Questions

Survey questions and their descriptions can provide meaningful context to the user who launches the job template. Surveys allow you to configure how users respond to questions. If a question can only have a defined set of answers, then you might choose one of the multiple choice answer types. For example, a survey could prompt for a logging severity level. The multiple choice answers could include items such as critical, warning, and info.

Other survey questions might expect arbitrary text or numbers, and you can restrict the entered values by defining the minimum and the maximum number of characters that can be used. If desired, you can also provide default answers and decide which questions require an answer.

The responses to a survey question must use one of the following answer types:

TypeDescription
Text Single-line text.
Textarea Multiline text.
Password Data is treated as sensitive information.
Multiple Choice (single select) A list of options from which only one option can be chosen as a response.
Multiple Choice (multiple select) A list of options from which one or more options can be chosen as a response.
Integer Integer number.
Float Floating point decimal number.

Creating a Job Template Survey

When you create a job template, you cannot add a survey at the same time. You can only add a survey after you create the job template.

Use the following procedure to add a survey to an existing job template:

  1. Navigate to ResourcesTemplates and click the desired job template.

  2. Click the Survey tab and then click Add to open the Add Question page.

  3. To add a question to the survey:

    1. In the Question field, enter the question to display. You can add an optional description in the Description field to provide more information about the question.

    2. In the Answer variable name field, enter the name of the extra variable that stores the response. You might need to consult the playbook to identify the exact variable name.

    3. From the Answer type list, select the answer type that you want to use for the response.

    4. If you use a multiple choice answer type, then define the list by entering the first choice in the Multiple Choice Options field, and then press Enter to display a new blank row. Continue until you have entered all desired choices.

    5. If you are not using a multiple choice answer type, then you can specify the maximum and minimum response lengths by using the Maximum length and Minumum length fields, respectively.

    6. You can also define a default value for the extra variable in the Default answer field. The survey starts with this value, but the user responding to the survey can choose a different value.

    7. Select Required to specify that a response is mandatory. Clear this field if a response is optional.

    8. Click Save to add the question to the survey. The survey now lists the new question.

  4. Repeat the previous steps to add more questions to the survey. After adding all your questions, scroll to the top of the screen.

  5. New surveys are disabled by default. To enable the survey, click Survey Disabled so that its label changes to Survey Enabled.

  6. If you need to change the order of the survey questions, click Edit Order and drag the questions as required.

When you launch a job template that includes a survey, automation controller presents the survey before running the job. A question mark icon appears next to a question if you added a description for the survey question. Clicking the question mark icon displays the description.

Figure 4.3: Survey prompt

After completing the survey, click Next. The Preview page displays variables and the values that the survey configures. If you are satisfied with your responses, then click Launch to start the job. Otherwise, click Back to change a response to a survey question.

Figure 4.4: Preview page

Revision: do457-2.3-7cfa22a