Sometimes you might need to launch a job template automatically at a particular time, or on a particular schedule. You can use automation controller to configure schedules that launch job templates on a customizable schedule.
If you have the Execute role on a job template, then you can schedule the job template to run at a specific date, time, and frequency. To create a new job template schedule, navigate to → and click the job template that you want to schedule. Click the tab and then click to create a new schedule for that job template.
Enter the required details:
The name of the schedule.
The date and time that the job schedule starts.
You can use the timedatectl command to determine your local time zone in this format.
How often to repeat the associated job. You can choose , , , , , , or .
Depending on the chosen frequency, you might need to provide additional information (for example, to launch a job every two days, or on the first Sunday of every month).
When finished, click to save the schedule. You can activate or deactivate a schedule by setting the switch at the top of the page for the schedule.
Navigate to → in the automation controller web UI to open the page. This page lists all job schedules. Set the switch under the column of the desired schedule name to activate or deactivate the schedule.
You can also edit or delete any schedule, assuming you have sufficient privileges to do so, from this page.
Automation controller ships with four scheduled management jobs by default. These schedules run built-in management jobs to perform periodic maintenance on the automation controller.
| Management job | Description |
|---|---|
Cleanup Job Schedule
| Removes information about jobs that are more than 120 days old. It runs weekly on Sundays. |
Cleanup Activity Schedule
| Removes information from the activity stream that is more than 355 days old. It runs weekly on Tuesdays. |
Cleanup Expired OAuth 2 Tokens
| Deletes the expired OAuth 2 access and refresh tokens. It runs weekly. |
Cleanup Expired Sessions
| Removes expired browser sessions. It runs weekly. |
You can change the frequency of these management jobs by editing their schedules.
Red Hat Ansible Automation Platform provides centralized logging and auditing. When you execute a job, details about the job execution are logged in the automation controller database. You can use this database to review job execution history.
Historical job execution details are helpful for confirming the success or failure of scheduled and delegated job executions. The ability to retrieve historical job execution details is helpful, but for jobs related to critical functions, you might prefer immediate notification of when a job starts, as well as the success or failure of its execution.
Automation controller can send notifications when a job starts, as well as the job execution results. You need to create notification templates that specify how to send notifications to take advantage of this feature. Automation controller supports many mechanisms for sending notifications. Some are based on open protocols, such as email and IRC, and others are based on proprietary solutions, such as Slack and Twilio.
Notification templates help you to send notifications on job start, job success, and job failure, even in events related to approvals, or any combination thereof.
Notification templates specify how to send notifications. The following notification types are supported:
Grafana
IRC
Mattermost
PagerDuty
Rocket.Chat
Slack
Twilio
Webhook
Use the following procedure to create a notification template:
Navigate to → in the automation controller web UI.
Click to create a notification template, and enter the required details:
The name of the notification template.
Enter a description for the notification template. (Optional)
The organization within which to create the notification template.
The mechanism to be used by the notification template for generating notifications.
Enter the required details for the notification template type in the section.
For example, for the E-mail notification template type, the following fields are displayed in the section:
Specifies the username when using SMTP authentication. (Optional)
Specifies the password for the username when using SMTP authentication. (Optional)
Specifies which SMTP server to use.
Specifies the email addresses of the recipients for the notification email, one per line.
Specifies the email address of the sender when composing the notification.
Specifies the port to connect to on the SMTP server.
Specifies the maximum time in seconds (from 1 to 120) that the automation controller attempts connecting to the SMTP server.
You can enable SSL or TLS to secure email communications by selecting the respective checkbox. (Optional)
Set the switch to on if you want to customize the content of the notification messages.
For each of the notification types, preconfigured messages are available that use Jinja2 expressions to provide information about the job. The preconfigured messages use variables related to the job variable (such as job_friendly_name for the friendly name of the job, job_metadata for the job metadata, and so on), and some of its attributes (such as name for the name of the job, status for the status of the job, and so on).
For example, for the E-mail notification template type, the preconfigured start message body uses the friendly name of the job, the id and status job attributes, as well as the URL and all metadata information for the job:
{{ job_friendly_name }} #{{ job.id }} had status {{ job.status }}, view details at {{ url }}
{{ job_metadata }}You can create custom notifications by modifying the preconfigured messages. A link to a complete list of supported attributes and variables is available in the references at the end of this section.
Click to finalize the creation of the notification template.
You can send a test notification for each notification template after creating or editing them. Click the icon in the column of the desired notification template. The column should display Successful.
When you create a notification template, it becomes available for use by the following automation controller resources:
Job templates
Projects
Inventory sources
Workflow templates
Organizations
For job templates, projects, and inventory source, the available notifications are Start, Success and Failure. For workflow templates and organizations, you can also get Approval notifications for events with approvals. This is discussed later in the course.
Use the following procedure to enable notifications for a job template:
Navigate to → in the automation controller web UI.
Click the name of the required job template and then click the tab to display the list of notification templates.
Each listed notification template has switches for controlling , , and notifications. Set the corresponding switches to configure the desired notifications for the job template.
Under some circumstances, you might encounter an issue in which automation controller fails to send a notification. This is a known issue at the time of writing, caused by a race condition related to https://github.com/ansible/awx/issues/11422.
One symptom, besides missing notification messages, is content similar to the following in the /var/log/tower/task_system.log file:
2022-02-17 06:54:54,645 WARNING [b8c34f2e75d2430c8874f3f8feb557cc] awx.main.tasks Failed to even try to send notifications for job '2022-02-17 06:37:20.281267+00:00-56302-running' due to job not being in finished state.
Automation controller in Red Hat Ansible Automation Platform 2.1.2 and later includes a setting that you can adjust to work around the issue.
By default, automation controller uses the setting AWX_NOTIFICATION_JOB_FINISH_MAX_RETRY = 5. If automation controller fails to send a notification, then you can change this variable to have a higher value, such as 20. Modify the /var/lib/awx/venv/awx/lib/python3.9/site-packages/awx/settings/defaults.py file on the automation controller. After making this change, run the automation-controller-service restart command.