Bookmark this page

Creating Job Templates and Launching Jobs

Objectives

  • Create and manage a job template that specifies a project and playbook, an execution environment from a private automation hub, an inventory, and credentials that you can use to launch Red Hat Ansible Automation Platform jobs on managed hosts.

Job Templates

In automation controller, a job template is a predefined collection of settings that you can use to launch jobs that run playbooks. Running a playbook from the command line requires a playbook, inventory, and authentication. Similarly, a job template associates a playbook from a project with an inventory of hosts, credentials for authentication, an automation execution environment, and other parameters used when you launch an Ansible job to run that playbook.

Whether a user can launch jobs or create job templates with particular projects and inventories depends on the roles that you have assigned them. When granted the Use role, users can use a job template to associate projects with inventories.

A job template defines the parameters for the execution of an Ansible job. An Ansible job executes a playbook against a set of managed hosts. Therefore, a job template must define which project provides the playbook and which inventory contains the list of managed hosts.

The job template can also specify an automation execution environment to use when running the playbook. For example, if you are using a playbook that worked with Ansible 2.9, you can specify a compatible automation execution environment to run the playbook.

Additionally, the job template must also define the machine credential to use to authenticate to the managed hosts. Like projects and inventories, users must have the Use role assigned to a machine credential before they can associate it with a job template.

After it has been defined, a job template allows for the repeated execution of a job and is therefore ideal for routine execution of tasks. Because the project, inventory, automation execution environment, and machine credential parameters are part of the job template definition, the job runs the same way each time.

Creating Job Templates

Unlike other automation controller resources, job templates do not directly belong to an organization. Instead, they are used by a project that belongs to an organization. The relationship of a job template to an organization is determined by the project that it uses. Therefore, you do not need the Admin role in an organization to create a job template. Instead, you only need the Use role for the project that you assign to the job template.

Because a job template has to be defined with an inventory, project, automation execution environment, and machine credential, a user can only create a job template if they have Use roles assigned to one or more of each of these three automation controller resources.

The following procedure to create a job template focuses on mandatory parameters; optional parameters are discussed later:

  1. Log in to the automation controller web UI as a user who has been assigned the Use role for the inventory, project, and machine credential resources for the project that you are creating.

  2. Navigate to ResourcesTemplates and then click AddAdd job template to open the Create New Job Template page.

  3. Enter a name for the job template in the Name field.

  4. In the Job type list, choose Run.

  5. Click the search icon for the Inventory field, select the required inventory, and then click Select.

  6. Click the search icon for the Project field, select the desired project, and then click Select.

  7. Click the drop-down menu for the Playbook field and select the desired playbook.

  8. Click the search icon for the Credentials field, select the desired credential, and then click Select.

  9. Scroll to the bottom of the page and click Save.

Figure 4.3: Creating a new job template

Modifying Job Execution

A job template has other settings you can use to adjust how automation controller runs the playbook when you launch the template:

Description

Use this field to specify an optional description of the job template.

Execution Environment

Use this field to specify an automation execution environment for the job template. Click the search icon and select the automation execution environment from the list. This field is available after you have selected a project for the job template. When you specify an automation execution environment, it overrides the one that is used when launching the job template. You can verify the automation execution environment used by the job template in its details page.

Labels

Labels are names that you can attach to job templates to help you group or filter job templates.

Variables

You can use this field to pass extra command-line variables to the playbook executed by a job. You define these extra variables as key-value pairs using either YAML or JSON.

Forks

Use this field to specify the forks setting that controls the number of parallel processes to allow during playbook execution. Set this to 0 to use the default setting from the Ansible configuration file.

Limit

Use this field to restrict the list of managed hosts provided by the inventory that you defined for the job template.

Verbosity

This determines the level of detail generated in the output of the job run.

Job Slicing

Use this field to specify the number of slices into which you want to divide the work done by this job template.

Timeout

Use this field to specify the time in seconds to run the job before it is canceled. A value of 0 causes no job timeout.

Show Changes

Enable this option to show the changes made by Ansible tasks.

Instance Groups

Use this field to specify the instance groups on which you want to run the job template.

Job Tags

This field accepts a comma-separated list of tags that exist in a playbook. Use tags to identify distinct portions of a playbook. By specifying a list of tags in this field, you can selectively execute only certain portions of a playbook.

Skip Tags

This field accepts a comma-separated list of tags that exist in a playbook. By specifying a list of tags in this field, you can selectively skip certain portions of a playbook during its execution.

Enable Privilege Escalation

Select this option to run the playbook with escalated privileges.

Provisioning Callbacks

Select this option to create a provisioning callback URL on automation controller, which hosts can use to request a configuration update using the job template.

Enable Webhook

Select this option to enable the ability to interact with GitHub or GitLab.

Concurrent Jobs

Select this option to allow for multiple, simultaneous executions of this job template.

Enable Fact Storage

Select this option to save the gathered facts to be viewed at the host level.

Prompting for Job Parameters

When executing playbooks from the command line, administrators can modify playbook execution with command-line options. Automation controller provides some of this flexibility by allowing certain parameters in job templates to prompt for user input at the time of job execution. The Prompt on launch option is available for the following parameters:

  • Job Type

  • Inventory

  • Credentials

  • Variables

  • Limit

  • Verbosity

  • Show Changes

  • Job Tags

  • Skip Tags

The flexibility to change job parameters at the time of job execution encourages playbook reuse. For example, rather than creating multiple job templates to run the same playbook on different sets of managed hosts, a single job template that has the Prompt on launch option enabled for the inventory field is sufficient. When the job is launched, the user executing the job is given the option to specify an inventory to execute the playbook on. When prompted, users can only select from inventories that they have been assigned the Use role on.

Figure 4.4: Prompting for inventory on launch

Job Template Roles

Three roles are available to control user access to job templates.

RoleDescription
Admin Users with the Admin role can delete a job template or edit its properties, including its associated permissions. This role also grants permissions associated with the job template Execute and Read roles.
Execute Users with the Execute role can execute a job using the job template. The users can also schedule a job using the job template. This role also grants permissions associated with the job template Read role.
Read Users with the Read role have read-only access to the properties of a job template. They can also view other information related to the job template, such as the list of jobs executed using the job template, as well as its associated permissions and notifications.

Important

A job template makes use of other automation controller resources such as projects, inventories, and credentials. For a user to execute a job using a job template, they only need the Execute role on the job template; they do not need the Use roles on any of these associated automation controller resources.

Managing Job Template Access

When you create a job template, it is only accessible to you or users with either an Admin or Auditor role in the organization where the project was created. Additional access must be specifically configured if desired.

The assignment of the previously discussed job template roles to users or teams dictates who has permissions to a job template.

You cannot assign these permissions when you create the job template; create the job template first and then assign any required permissions.

You can assign roles through the Access section of the job template page. Use the following procedure to grant permissions to a job template:

  1. Log in as a user with the Admin role in the organization that the job template is associated with or as the user who created the job template.

  2. Navigate to ResourcesTemplates and click the name of the job template.

  3. On the Access page, click Add to start adding permissions.

  4. Click either Users or Teams and then click Next.

  5. Select the users or teams to be granted permissions, and then click Next to display the list of job template roles and their definitions.

  6. Select the desired job template role for the user or team and then click Save to finalize the changes to permissions.

    Figure 4.5: Assigning job template roles to users

Launching Jobs

Use the following procedure to launch a job after you have created a job template:

  1. Log in as a user with the Execute role on the desired job template.

  2. Navigate to ResourcesTemplates to display the list of templates.

  3. Click the Launch Template icon under the Actions column of the desired job template to launch the job.

  4. If any of the job template parameters have the Prompt on launch option enabled, then you are prompted for input prior to job execution. Enter the desired input for each parameter and then click Launch.

    Figure 4.6: Launching a job

Evaluating the Results of a Job

After you have launched a job from a job template in the automation controller web UI, you are automatically redirected to the job page. Alternatively, navigate to ViewsJobs to see the list of executed jobs and click the link for the job of interest.

The job page has two tabs. The Details tab displays the details of the job parameters. The Output tab displays the output of the playbook executed by the job.

The job output tab displays information similar to that seen when you run the playbook from the command line, but includes additional information as well. This page includes the number of plays and tasks that were executed, the number of hosts that the job was executed against, and the time it took for the job to execute. It also includes three icons: to launch the job, to download the output, and to delete the job.

Figure 4.7: Job run results

Revision: do467-2.2-08877c1