Bookmark this page

Lab: Constructing Job Workflows

  • Create a new workflow job template that uses a survey to set variables, and fact caching to speed up the workflow.

Outcomes

  • Create a workflow job template.

  • Create an associated survey and notification template.

  • Launch the workflow job template from the automation controller web UI.

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 workflow-review

Procedure 6.3. Instructions

Create a workflow job template that deploys your web servers to the test environment, and after approval, to production. As part of this process, rename the existing TEST webservers setup job template to Webservers setup and configure the job template to prompt for an inventory. This allows you to use a single job template for both the test and production environments. The Webservers setup job template needs to use facts cached from earlier in the workflow. The workflow job template also needs to prompt the user with a survey to set some variable values when the workflow job template is launched.

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

  2. Make sure that the per-host Ansible fact cache time-out for automation controller is set for exactly one day (86400 seconds). This ensures that facts are cached for hosts but also expire if those facts have not been refreshed recently.

    1. Click Settings in the left navigation bar.

    2. In the Settings window, on the Jobs tile, click Jobs settings.

    3. Confirm that Per-Host Ansible Fact Cache Timeout is set to 86400 seconds. If the setting is different, click Edit, edit that field to contain the value 86400, and click Save.

  3. Update the TEST webservers setup job template with the following information, leaving the other fields untouched. Make sure to clear the existing inventory entry for the job template.

    FieldValue
    Name Webservers setup
    Description Setup apache webservers
    Inventory Prompt on launch
    Options Enable Fact Storage
    1. Navigate to ResourcesTemplates and click the Edit Template icon for the TEST webservers setup job template.

    2. Rename to Webservers setup and change the description to Setup apache webservers.

    3. Clear the inventory selection and select Prompt on launch for the inventory.

    4. Scroll to the bottom of the page, select Enable Fact Storage in the Options section, and then click Save. Do not change any of the other fields.

  4. Create a workflow job template called From Test to Prod with the following information. In the following steps, you create nodes for the workflow job template.

    Table 6.1. Workflow Template

    FieldValue
    Name From Test to Prod
    Description Deploy to Test and on success deploy to Prod
    Organization Default

    1. Navigate to ResourcesTemplates and click AddAdd workflow template.

    2. Create a workflow template using information from the Workflow Template table. When finished, click Save.

  5. Start the workflow for the From Test to Prod workflow job template by synchronizing the My Webservers project. Create the first node using the following information:

    Table 6.2. Workflow Node #1

    FieldValue
    Node Type Project Sync
    Name My Webservers

    1. Using the workflow visualizer for the From Test to Prod workflow job template, click Start. Create the first node using information from the Workflow Node #1 table and then click Save.

      Synchronizing a project as the first step in the workflow

      Note

      The P symbol under the My Webservers node in the workflow visualizer indicates it is a project sync node.

      The blue line connecting Start and the My Webservers node indicates that this step is always performed.

  6. If the My Webservers node succeeds, then launch the Refresh Fact Cache job template. Create the second node using the following information:

    Table 6.3. Workflow Node #2

    FieldValue
    Node Type Job Template
    Name Refresh Fact Cache
    Node Alias Refresh Fact Cache (Test)
    Inventory Test

    1. Using the workflow visualizer for the From Test to Prod workflow job template, hover over the My Webservers node and then click Add a new node.

    2. Select On Success and click Next.

    3. Create the second node using information from the Workflow Node #2 table and then click Next.

    4. Select the Test inventory and click Next. Click Save.

      Adding a job template node to the workflow

      Note

      The JT symbol under the Refresh Fact Cache (Test) node in the workflow visualizer indicates it is a job template node.

      The green line connecting the My Webservers node and the Refresh Fact Cache (Test) node indicates that this step is performed only on success.

  7. If the Refresh Fact Cache (Test) node succeeds, then launch the Webservers setup job template. Create the third node using the following information:

    Table 6.4. Workflow Node #3

    FieldValue
    Node Type Job Template
    Name Webservers setup
    Node Alias Webservers setup (Test)
    Inventory Test

    1. Using the workflow visualizer for the From Test to Prod workflow job template, hover over the Refresh Fact Cache (Test) node and then click Add a new node.

    2. Select On Success and click Next.

    3. Create the third node using information from the Workflow Node #3 table and then click Next.

    4. Select the Test inventory and click Next. Click Save.

  8. If the Webservers setup (Test) node succeeds, then create an approval node using the following information:

    Table 6.5. Workflow Node #4

    FieldValue
    Node Type Approval
    Name Prod Approval
    Description Pushing to Prod requires approval
    Timeout (min) 60

    1. Using the workflow visualizer for the From Test to Prod workflow job template, hover over the Webservers setup (Test) node and then click Add a new node.

    2. Select On Success and click Next.

    3. Create the fourth node using information from the Workflow Node #4 table and then click Save.

      Requesting an approval in the workflow

      Note

      The pause symbol (||) under the Prod Approval node in the workflow visualizer indicates it is an approval node.

      After a successful launch of job templates in the test environment, the workflow indicates requesting an approval to launch them in production.

  9. If the Prod Approval node succeeds, then launch the Refresh Fact Cache job template. Create the fifth node using the following information:

    Table 6.6. Workflow Node #5

    FieldValue
    Node Type Job Template
    Name Refresh Fact Cache
    Node Alias Refresh Fact Cache (Prod)
    Inventory Prod

    1. Using the workflow visualizer for the From Test to Prod workflow job template, hover over the Prod Approval node and then click Add a new node.

    2. Select On Success and click Next.

    3. Create the fifth node using information from the Workflow Node #5 table and then click Next.

    4. Select the Prod inventory and click Next. Click Save.

  10. If the Refresh Fact Cache (Prod) node succeeds, then launch the Webservers setup job template. Create the sixth node using the following information. This is the final node in the From Test to Prod workflow job template.

    Table 6.7. Workflow Node #6

    FieldValue
    Node Type Job Template
    Name Webservers setup
    Node Alias Webservers setup (Prod)
    Inventory Prod

    1. Using the workflow visualizer for the From Test to Prod workflow job template, hover over the Refresh Fact Cache (Prod) node and then click Add a new node.

    2. Select On Success and click Next.

    3. Create the sixth node using information from the Workflow Node #6 table and then click Next.

    4. Select the Prod inventory and click Next. Click Save.

    5. Click Save to save the workflow and exit the workflow visualizer.

  11. Add a survey to the From Test to Prod workflow job template containing the following information. Make sure you enable the survey.

    Table 6.8. Workflow Job Template Survey

    FieldValue
    Question What version are you deploying?
    Description This version number is displayed at the bottom of the index page.
    Answer variable name deployment_version
    Answer type Text
    Required (selected)
    Minimum length 1
    Maximum length 40
    Default answer v1.0

    1. Navigate to ResourcesTemplates and click the From Test to Prod link.

    2. Click the Survey tab and then click Add.

    3. Add a single question to the survey, using the information in the Workflow Job Template Survey table. When finished, click Save.

    4. Enable the survey by setting the Survey Disabled|Survey Enabled switch to on.

      Important

      The survey is disabled by default. Make sure that you enable it.

  12. Activate the Approval, Success, and Failure notifications for the From Test to Prod workflow job template using the existing Email AAP Admins notification template.

    1. Navigate to ResourcesTemplates and click the From Test to Prod link.

    2. Click the Notifications tab and then select the Approval, Success, and Failure options for the Email AAP Admins notification template.

  13. Launch the From Test to Prod workflow job template. When prompted by the survey, enter v1.3 for the deployment version.

    1. Navigate to ResourcesTemplates and then click the Launch Template icon for the From Test to Prod workflow job template.

    2. Enter v1.3 in the text field for the survey that you just created, and then click Next.

    3. Click Launch to launch the workflow. Observe the running jobs of the workflow.

    4. The workflow stops on the approval node. Notice the notification icon at the top of the page, indicating one pending workflow approval.

  14. Approve the execution of the remaining workflow job template nodes and verify that the workflow triggers an email notification for the approval, when approved, and after completion.

    The Email AAP Admins notification template sends emails to the aap-admins@lab.example.com email alias. The student user can access these emails on the utility server.

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

      [student@workstation ~]$ ssh student@utility
    2. Use the tail command to view incoming messages to the local mailbox file of the student user. You should see the email that was sent for the approval. Your message looks similar to the following:

      [student@utility ~]$ tail -f /var/mail/student
          "id": 10,
          "name": "Prod Approval",
          "url": "https://controller.lab.example.com/#/jobs/workflow/6",
          "created_by": "admin",
          "started": "2022-05-13T21:53:29.886316+00:00",
          "finished": null,
          "status": "pending",
          "traceback": ""
      }
    3. Click the notification icon in the automation controller web UI, select the checkbox for the Prod Approval workflow approval, and then click Approve.

    4. Go to the terminal window running the tail command and wait a few seconds. You should see an approval notification email arrive that looks similar to the following example:

      From system@controller.lab.example.com  Fri May 13 17:57:15 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 E81EA938CEC
      	for <aap-admins@lab.example.com>; Fri, 13 May 2022 17:57:13 -0400 (EDT)
      Received: from controller.lab.example.com (localhost [IPv6:::1])
      	by controller.lab.example.com (Postfix) with ESMTP id CF7DC25D127
      	for <aap-admins@lab.example.com>; Fri, 13 May 2022 17:57:13 -0400 (EDT)
      Content-Type: text/plain; charset="utf-8"
      MIME-Version: 1.0
      Content-Transfer-Encoding: 7bit
      Subject: The approval node "Prod Approval" was approved.
       https://controller.lab.example.com/#/jobs/workflow/6
      From: system@controller.lab.example.com
      To: aap-admins@lab.example.com
      Date: Fri, 13 May 2022 21:57:13 -0000
      Message-ID:
       <165247903382.5344.15434941766628918585@controller.lab.example.com>
      
      The approval node "Prod Approval" was approved. https://controller.lab.example.com/#/jobs/workflow/6
      
      {
          "id": 10,
          "name": "Prod Approval",
          "url": "https://controller.lab.example.com/#/jobs/workflow/6",
          "created_by": "admin",
          "started": "2022-05-13T21:53:29.886316+00:00",
          "finished": "2022-05-13T21:57:13.356070+00:00",
          "status": "successful",
          "traceback": ""
      }
    5. Navigate to ViewsJobs in the automation controller web UI and wait for the 6 — From Test to Prod workflow job to finish.

      The completed workflow job template
    6. Go to the terminal window running the tail command. You should see a new notification email indicating the successful execution of the workflow. The notification looks similar to the following example:

      From system@controller.lab.example.com  Fri May 13 17:57:47 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 53C0C938CEC
      	for <aap-admins@lab.example.com>; Fri, 13 May 2022 17:57:47 -0400 (EDT)
      Received: from controller.lab.example.com (localhost [IPv6:::1])
      	by controller.lab.example.com (Postfix) with ESMTP id 4D82325D127
      	for <aap-admins@lab.example.com>; Fri, 13 May 2022 17:57:47 -0400 (EDT)
      Content-Type: text/plain; charset="utf-8"
      MIME-Version: 1.0
      Content-Transfer-Encoding: 7bit
      Subject: Workflow Job #6 'From Test to Prod' successful:
       https://controller.lab.example.com/#/jobs/workflow/6
      From: system@controller.lab.example.com
      To: aap-admins@lab.example.com
      Date: Fri, 13 May 2022 21:57:47 -0000
      Message-ID:
       <165247906731.5344.18226747658229373298@controller.lab.example.com>
      
      Workflow Job #6 had status successful, view details at https://controller.lab.example.com/#/jobs/workflow/6
      
      {
          "id": 6,
          "name": "From Test to Prod",
          "url": "https://controller.lab.example.com/#/jobs/workflow/6",
          "created_by": "admin",
          "started": "2022-05-13T21:52:53.307159+00:00",
          "finished": "2022-05-13T21:57:46.714992+00:00",
          "status": "successful",
          "traceback": "",
          "body": "Workflow job summary:\n\n- node #1 spawns job #7, \"My Webservers\", which finished with status successful.\n- node #2 spawns job #8, \"Refresh Fact Cache\", which finished with status successful.\n- node #3 spawns job #9, \"Webservers setup\", which finished with status successful.\n- node #6 spawns job #10, \"Prod Approval\", which finished with status successful.\n- node #5 spawns job #11, \"Refresh Fact Cache\", which finished with status successful.\n- node #4 spawns job #12, \"Webservers setup\", which finished with status successful."
      }

      When finished, press Ctrl+C to exit the tail command.

      Note

      If you prefer, you can use the mailx or mutt commands to display mail messages on the utility server. The subject of the emails received includes the following text:

      • The approval node "Prod Approval" needs review.

      • The approval node "Prod Approval" was approved.

      • Workflow Job #6 'From Test to Prod' successful.

    7. Exit the terminal session on the utility system.

      [student@utility ~]$ exit
  15. Verify that the web servers in the Test and Prod inventories (serverc.lab.example.com, serverd.lab.example.com, servere.lab.example.com, and serverf.lab.example.com) display the Deployment Version: v1.3 line.

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

      Deployment Version: v1.3
    2. When ready, log out from the automation controller web UI.

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 workflow-review

This concludes the section.

Revision: do467-2.2-08877c1