Bookmark this page

Creating Job Template Surveys to Set Variables for Jobs

Objectives

  • Create a job template survey to help users more easily launch a job with custom variable settings.

Managing Variables

You should write playbooks that you can reuse in similar situations. For example, you might write a playbook that deploys an application to a managed host. If you need to deploy that same application to a different managed host, but need to make minor changes to its configuration, perhaps by setting IP addresses unique to that host in the application’s setting, it would save time if you could just run that playbook on the new host with settings specific to that run. One way to accomplish this is by using variables to specify those configuration 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:

  1. 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.

  2. 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.

These extra variables are exactly like the variables specified by the -e or --extra-vars options for ansible-navigator or ansible-playbook, and their values override any values set for those variables. In other words, if a variable is set with a value in some other way, and it has the same name as an extra variable, the value set for it as an extra variable is the one that is used by automation controller.

If you select Prompt on launch for the Variables field, a dialog box opens where you can edit the extra variables for the job.

Figure 5.3: 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 of 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 a user responds to a question. 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 the name of a service to restart and then the multiple choice answers could define some system services, such as sshd, httpd, and postfix.

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, then 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 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 required choices.

    5. If you are not using a multiple choice answer type, then you can specify the minimum and maximum character length for the response in the Minimum length and Maximum 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 additional questions to the survey. After adding all of 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 and drop 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 5.4: 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 5.5: Preview page

Revision: do467-2.2-08877c1