Bookmark this page

Guided Exercise: Scheduling Jobs and Configuring Notifications

  • Create an email notification template, configure a job template to use the notification template, and launch a job to confirm that the notification works.

Outcomes

  • Create a notification template.

  • Use the notification template with a job template to generate email notifications of job results.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command ensures that automation controller is installed and configured with any necessary resources created in previous exercises.

[student@workstation ~]$ lab start job-notification

Procedure 5.3. Instructions

  1. Navigate to https://controller.lab.example.com and log in as the admin user with redhat as the password.

  2. Create a new notification template.

    1. Navigate to AdministrationNotifications and then click Add.

    2. Create the new notification template using the following information. When finished, click Save.

      FieldValue
      Name Email AAP Admins
      Description Sends an email to notify the status of the Job
      Organization Default
      Type E-mail
      Host localhost
      Recipient list aap-admins@lab.example.com
      Sender e-mail system@controller.lab.example.com
      Port 25
      Timeout 30
  3. Validate the new notification template.

    1. Navigate to AdministrationNotifications.

    2. Click the Test notification icon for the Email AAP Admins job template to test the notification process.

    3. After several seconds, the Status column displays the Successful message.

  4. Configure the DEV webservers setup job template to use the new Email AAP Admins notification template. Trigger the notification when jobs using the DEV webservers setup job template either succeed or fail.

    1. Navigate to ResourcesTemplates and then click the DEV webservers setup link.

    2. Click the Notifications tab and then set the Success and Failure switches to on for the Email AAP Admins notification.

  5. Verify that the DEV webservers setup job template triggers a notification email after job completion.

    1. Open a terminal and connect to the utility server.

      [student@workstation ~]$ ssh student@utility
    2. Use the tail command to read incoming messages to the local mailbox file of the student user. You should see the email that was sent by the test notification launched from a previous step. Your message looks similar to the following:

      [student@utility ~]$ tail -f /var/mail/student
      MIME-Version: 1.0
      Content-Transfer-Encoding: 7bit
      Subject: Notification Test 1 https://controller.lab.example.com
      From: system@controller.lab.example.com
      To: aap-admins@lab.example.com
      Date: Fri, 22 Apr 2022 19:39:31 -0000
      Message-ID: <165065637197.1384.7900890983573152025@controller.lab.example.com>
      
      Test Notification 1 https://controller.lab.example.com

      Note

      If you prefer, then use the mailx or mutt commands to display mail messages on the utility server.

    3. From the automation controller web UI, navigate to ResourcesTemplates and then click the Launch Template icon for the DEV webservers setup job template.

    4. In the survey window, enter v1.2 for the deployment version, click Next, and then click Launch.

    5. Go to the terminal window running the tail command and wait. After about one minute, you should see a notification email arrive that looks similar to the following example. When finished, press Ctrl+C to exit the tail command.

      From system@controller.lab.example.com  Fri Apr 22 15:44:03 2022
      Return-Path: <system@controller.lab.example.com>
      X-Original-To: aap-admins@lab.example.com
      Delivered-To: aap-admins@lab.example.com
      Received: from controller.lab.example.com (controller.lab.example.com [172.25.250.7])
              by utility.lab.example.com (Postfix) with ESMTPS id EDB3418BB563
              for <aap-admins@lab.example.com>; Fri, 22 Apr 2022 15:44:03 -0400 (EDT)
      Received: from controller.lab.example.com (localhost [IPv6:::1])
              by controller.lab.example.com (Postfix) with ESMTP id CF64D195822E
              for <aap-admins@lab.example.com>; Fri, 22 Apr 2022 15:44:03 -0400 (EDT)
      Content-Type: text/plain; charset="utf-8"
      MIME-Version: 1.0
      Content-Transfer-Encoding: 7bit
      Subject: Job #10 'DEV webservers setup' successful:
       https://controller.lab.example.com/#/jobs/playbook/10
      From: system@controller.lab.example.com
      To: aap-admins@lab.example.com
      Date: Fri, 22 Apr 2022 19:44:03 -0000
      Message-ID:
       <165065664382.1385.10783097240459901012@controller.lab.example.com>
      
      Job #10 had status successful, view details at https://controller.lab.example.com/#/jobs/playbook/10
      
      {
          "id": 10,
          "name": "DEV webservers setup",
          "url": "https://controller.lab.example.com/#/jobs/playbook/10",
          "created_by": "admin",
          "started": "2022-04-22T19:43:40.383371+00:00",
          "finished": "2022-04-22T19:44:02.979429+00:00",
          "status": "successful",
          "traceback": "",
          "inventory": "Dev",
          "project": "My Webservers DEV",
          "playbook": "apache-setup.yml",
          "credential": "Developers",
          "limit": "",
          "extra_vars": "{\"deployment_version\": \"v1.2\"}",
          "hosts": {
              "serverb.lab.example.com": {
                  "failed": false,
                  "changed": 6,
                  "dark": 0,
                  "failures": 0,
                  "ok": 7,
                  "processed": 1,
                  "skipped": 0,
                  "rescued": 0,
                  "ignored": 0
              },
              "servera.lab.example.com": {
                  "failed": false,
                  "changed": 6,
                  "dark": 0,
                  "failures": 0,
                  "ok": 7,
                  "processed": 1,
                  "skipped": 0,
                  "rescued": 0,
                  "ignored": 0
              }
          }
      }
      ^C
    6. Exit the terminal session on the utility system.

      [student@utility ~]$ exit
  6. Verify that the web servers have been updated successfully on servera.lab.example.com and serverb.lab.example.com.

    1. Open a web browser and navigate to http://servera.lab.example.com and http://serverb.lab.example.com in separate tabs. You should see this line at the bottom of each page:

      Deployment Version: v1.2
  7. Based on the DEV webservers setup job template, schedule a new job at three minutes from the current time.

    1. From a terminal window, display the current date, time, and time zone used by the controller server. Your environment might display a different date and time than this example. Use the identified time zone when you create your new schedule.

      [student@workstation ~]$ ssh controller timedatectl
                     Local time: Fri 2022-04-22 16:14:45 EDT
                 Universal time: Fri 2022-04-22 20:14:45 UTC
                       RTC time: Fri 2022-04-22 20:14:44
                      Time zone: America/New_York (EDT, -0400)
      System clock synchronized: yes
                    NTP service: active
                RTC in local TZ: no
    2. Navigate to ResourcesTemplates and then click the DEV webservers setup link.

    3. Click the Schedules tab and then click Add.

    4. Schedule the job using the following information. The date defaults to the current date. If necessary, adjust the time zone to match the one used by the controller server. When finished, click Save to create the new schedule.

      FieldValue
      Name Automatic job run
      Start date/time (Set the execution of the job to +3 minutes from the current time.)
      Local time zone (The time zone that you just determined for the automation controller, America/New_York in the preceding example.)
      Run frequency None (run once)
    5. Navigate to ViewsJobs and wait for the scheduled job to be executed. The scheduled job succeeds.

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish job-notification

This concludes the section.

Revision: do467-2.2-08877c1