Bookmark this page

Lab: Running Playbooks with Automation Controller

Create resources within the automation controller web UI so that you can launch job templates and workflow job templates.

Outcomes

  • Create automation controller source control and machine credentials.

  • Create an automation controller project and then create an inventory that uses files stored in the project.

  • Create automation controller job templates and workflow templates.

  • Launch jobs from the automation controller web UI.

As the student user on the workstation machine, use the lab command to prepare your environment for this exercise, and to ensure that all required resources are available:

[student@workstation ~]$ lab start compreview-cr4

Specifications

You can log in to your automation controller at https://controller.lab.example.com as the admin user with redhat as the password.

  • Create a source control credential resource that automation controller can use to download files from the git.lab.example.com Git server. Create the credential with the following settings:

    FieldValue
    Name GitLab Projects
    Organization Default
    Credential Type Source Control
    Username student
    SCM Private Key Content of the /home/student/.ssh/gitlab_rsa file.
  • Create a machine credential resource that automation controller can use to access the managed nodes in your environment. Create the credential with the following settings:

    FieldValue
    Name Managed Nodes
    Organization Default
    Credential Type Machine
    Username student
    SSH Private Key Content of the /home/student/.ssh/lab_rsa file.
  • Create a project resource so that automation controller can download files from the git@git.lab.example.com:student/compreview Git repository. Create the project with the following settings:

    FieldValue
    Name Comprehensive Review
    Organization Default
    Source Control Type Git
    Source Control URL git@git.lab.example.com:student/compreview
    Source Control Branch/Tag/Commit main
    Source Control Credential GitLab Projects
    Options Delete
    Allow Branch Override
  • Create an inventory resource that contains the same hosts and host groups that you used in the previous comprehensive review exercises. Create the inventory with the following settings:

    FieldValue
    Name Common Nodes
    Organization Default

    Add an inventory source to the Common Nodes inventory with the following settings:

    FieldValue
    Name Project Inventory
    Source Sourced from a Project
    Project Comprehensive Review
    Inventory file inventory-controller.yaml

    Important

    Although the inventory-controller.yaml file does not appear in the Inventory file list, you can type the name of the file. After typing the file name, press the Enter key rather than the Tab key.

    After you synchronize the inventory source, you should see that the following hosts and host groups belong to the Common Nodes inventory.

    HostHost group
    arista1.lab.example.com eos
    arista2.lab.example.com eos
    iosxe1.lab.example.com ios
    iosxe2.lab.example.com ios
    junos1.lab.example.com junos
    junos2.lab.example.com junos
    workstation.lab.example.com Ungrouped

    Important

    The Common Nodes inventory does not define the ansible_user and ansible_ssh_private_key_file variables.

  • Create a job template named Configure Interfaces that uses the config_interfaces.yml playbook to add interface descriptions. Create the job template with the following settings:

    FieldValue
    Name Configure Interfaces
    Inventory Common Nodes
    Project Comprehensive Review
    Playbook config_interfaces.yml
    Credentials Managed Nodes
  • Create a job template named Deploy DNS, NTP, & Syslog that uses the deploy.yml playbook to add DNS, NTP, and Syslog servers. Create the job template with the following settings:

    FieldValue
    Name Deploy DNS, NTP, & Syslog
    Inventory Common Nodes
    Project Comprehensive Review
    Playbook deploy.yml
    Credentials Managed Nodes
  • Create a job template named Create Backups that uses the net_backup.yml playbook to generate new backup files. Create the job template with the following settings:

    FieldValue
    Name Create Backups
    Inventory Common Nodes
    Project Comprehensive Review
    Playbook net_backup.yml
    Credentials Managed Nodes
  • Create a workflow template named Configure & Back up that belongs to the Default organization and uses the Common Nodes inventory. Configure the workflow to satisfy the following criteria:

    • Start the workflow by synchronizing the Comprehensive Review project. Use Project Sync as the node alias.

    • If the Project Sync node succeeds, then synchronize the Project Inventory source. Use Inventory Sync as the node alias.

    • If the Inventory Sync node succeeds, then run both the Configure Interfaces and Deploy DNS, NTP, & Syslog job templates.

    • If both the Configure Interfaces and Deploy DNS, NTP, & Syslog nodes succeed, then run the Create Backups job template.

    The completed workflow template should appear as follows:

    Figure 8.1: Completed workflow template
  • Add a survey to the Configure & Back up workflow template that prompts for a location to store the backup files. Create the survey question with the following settings:

    FieldValue
    Question Enter an absolute path to the backup directory:
    Answer variable name backup_store
    Answer type Text
    Required (selected)
    Minimum length 2
    Maximum length 100
    Default Answer /backups

    Note

    The net_backup.yml playbook (used by the Create Backups node) includes the net_backup role. This role creates the directory defined by the value of the backup_store variable.

  • Launch the Configure & Back up workflow template. Enter /compreview as the response to the survey question.

  • After the jobs launched by the Configure & Back up workflow template complete, verify that the /compreview directory exists and that the directory contains a configuration file for each of the Junos and IOS managed nodes.

  1. From the automation controller web UI, create the GitLab Projects source control credential resource. Configure the credential to use authentication information for the git.lab.example.com server.

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

    2. Navigate to ResourcesCredentials and click Add. If you do not see the Resources menu, then click the main menu icon at the upper left of the page. Create the credential with the following settings:

      FieldValue
      Name GitLab Projects
      Organization Default
      Credential Type Source Control
      Username student
      SCM Private Key Content of the /home/student/.ssh/gitlab_rsa file.

      Note

      If you choose to browse for the file, then right-click anywhere in the directory navigation and select Show Hidden Files. With this option enabled you can see the .ssh directory in the /home/student directory.

    3. Click Save.

  2. Create the Managed Nodes machine credential such that it contains authentication information for the devices in the lab environment.

    1. Navigate to ResourcesCredentials and click Add. Create the credential with the following settings and then click Save:

      FieldValue
      Name Managed Nodes
      Organization Default
      Credential Type Machine
      Username student
      SSH Private Key Content of the /home/student/.ssh/lab_rsa file.
  3. Create the Comprehensive Review project resource and configure the project to pull files from the git@git.lab.example.com:student/compreview Git repository.

    1. Navigate to ResourcesProjects and click Add. Create the project with the following settings and then click Save:

      FieldValue
      Name Comprehensive Review
      Organization Default
      Source Control Type Git
      Source Control URL git@git.lab.example.com:student/compreview
      Source Control Branch/Tag/Commit main
      Source Control Credential GitLab Projects
      Options Delete
      Allow Branch Override
    2. After you click Save, automation controller immediately attempts to synchronize the project. Verify that the Last Job Status field updates to indicate that the project synchronization succeeded.

  4. Create the Common Nodes inventory resource and add the Project Inventory source to the inventory. Synchronize the inventory source and verify that the inventory contains the expected hosts and host groups.

    1. Navigate to ResourcesInventories and then click AddAdd inventory. Create the inventory with the following settings:

      FieldValue
      Name Common Nodes
      Organization Default
    2. Click Save.

    3. From the Sources tab, click Add. Create the inventory source with the following settings:

      FieldValue
      Name Project Inventory
      Source Sourced from a Project
      Project Comprehensive Review
      Inventory file inventory-controller.yaml

      Important

      Although the inventory-controller.yaml file does not appear in the Inventory file list, you can type the name of the file. After typing the file name, press the Enter key rather than the Tab key.

    4. Click Save.

    5. Click Sync to synchronize the inventory source. The Last Job Status field updates to indicate that the synchronization succeeded.

    6. Click the Back to Sources tab and then click the Details tab. The Details page for the Common Nodes inventory does not define the ansible_user and ansible_ssh_private_key_file variables.

      Important

      If the Common Nodes inventory defines the ansible_user and ansible_ssh_private_key_file variables, then you entered the inventory.yaml file as the source. Update the Project Inventory source so that it uses the inventory-controller.yaml file. You might also need to update the variables defined for the Common Nodes inventory to remove the undesired variables.

    7. From the Details page for the Common Nodes inventory, click the Hosts tab to display the imported hosts. Click the Groups tab to display the imported groups. The inventory source imported the following hosts and host groups:

      HostHost group
      arista1.lab.example.com eos
      arista2.lab.example.com eos
      iosxe1.lab.example.com ios
      iosxe2.lab.example.com ios
      junos1.lab.example.com junos
      junos2.lab.example.com junos
      workstation.lab.example.com Ungrouped
  5. Create a job template named Configure Interfaces that uses the config_interfaces.yml playbook to configure interface descriptions.

    1. Navigate to ResourcesTemplates and then click AddAdd job template. Create the job template with the following settings and then click Save:

      FieldValue
      Name Configure Interfaces
      Inventory Common Nodes
      Project Comprehensive Review
      Playbook config_interfaces.yml
      Credentials Managed Nodes
  6. Create a job template named Deploy DNS, NTP, & Syslog that uses the deploy.yml playbook to add DNS, NTP, and Syslog servers.

    1. Navigate to ResourcesTemplates and then click AddAdd job template. Create the job template with the following settings and then click Save:

      FieldValue
      Name Deploy DNS, NTP, & Syslog
      Inventory Common Nodes
      Project Comprehensive Review
      Playbook deploy.yml
      Credentials Managed Nodes
  7. Create a job template named Create Backups that uses the net_backup.yml playbook to generate new backup files.

    1. Navigate to ResourcesTemplates and then click AddAdd job template. Create the job template with the following settings and then click Save:

      FieldValue
      Name Create Backups
      Inventory Common Nodes
      Project Comprehensive Review
      Playbook net_backup.yml
      Credentials Managed Nodes
  8. Create a workflow template named Configure & Back up that belongs to the Default organization and uses the Common Nodes inventory.

    1. Navigate to ResourcesTemplates and then click AddAdd workflow template. Create the workflow template with the following settings and then click Save:

      FieldValue
      Name Configure & Back up
      Organization Default
      Inventory Common Nodes
  9. Add a Project Sync node named Project Sync to synchronize the Comprehensive Review project.

    1. In the visualizer, click Start.

    2. On the Add Node page, select Project Sync in the Node Type list.

    3. Select the Comprehensive Review project.

    4. Enter Project Sync in the Node Alias field and then click Save.

  10. Add an Inventory Source Sync node named Inventory Sync that synchronizes the Project Inventory source if the Project Sync node succeeds.

    1. In the visualizer, hover over the Project Sync node and click the + icon to add a new node.

      Note

      You might need to increase the display resolution on the workstation machine, decrease the web browser zoom, or both, to see the entire visualizer display screen.

      If your mouse has a scroll wheel, then you can use the scroll wheel to zoom in and out of the visualizer.

    2. On the Run type page, select the On Success condition and then click Next.

    3. On the Node type page, select Inventory Source Sync in the Node Type list.

    4. Select the Project Inventory source.

    5. Enter Inventory Sync in the Node Alias field and then click Save.

  11. Add a Job Template node that launches the Configure Interfaces job template to configure interface descriptions if the Inventory Sync node succeeds.

    1. In the visualizer, hover over the Inventory Sync node and click the + icon to add a new node.

    2. On the Run type page, select the On Success condition and then click Next.

    3. On the Node type page, select the Configure Interfaces job template.

    4. Click Save.

  12. Add a Job Template node that launches the Deploy DNS, NTP, & Syslog job template to add DNS, NTP, and Syslog servers if the Inventory Sync node succeeds.

    1. In the visualizer, hover over the Inventory Sync node and then click the + icon to add a new node.

    2. On the Run type page, select the On Success condition and then click Next.

    3. On the Node type page, select the Deploy DNS, NTP, & Syslog job template.

    4. Click Save.

  13. Add a job template node that launches the Create Backups job template to generate new backup files if both the Configure Interfaces and Deploy DNS, NTP, & Syslog nodes succeed.

    1. In the visualizer, hover over the Configure Interaces node and then click the + icon to add a new node.

    2. On the Run type page, select the On Success condition and then click Next.

    3. On the Node type page, select the Create Backups job template.

    4. Select All from the Convergence menu and then click Save. This convergence setting indicates that all parent nodes that point to the Create Backups node must match their defined conditions.

      Notice that the icon for the Create Backups node contains the word ALL to indicate the convergence setting.

    5. Hover over the Deploy DNS, NTP, & Syslog node and then click the Link to an available node icon.

    6. Hover over the Create Backups node. The visualizer displays a dashed line with an arrow pointing to the node. Click the Create Backups node.

    7. Click Save to accept the default On Success condition.

    8. Click Save again in the upper-right corner to save this workflow template.

      After this step, the completed workflow template should appear as follows:

      Figure 8.2: Completed workflow template
  14. Add a survey to the Config & Back up workflow template, which prompts for a location to store the backup files.

    1. Navigate to ResourcesTemplates and click the Configure & Back up link.

    2. Click the Survey tab and then click Add to begin. Create the survey question with the following settings:

      FieldValue
      Question Enter an absolute path to the backup directory:
      Answer variable name backup_store
      Answer type Text
      Required (selected)
      Minimum length 2
      Maximum length 100
      Default Answer /backups

      Note

      The net_backup.yml playbook (used by the Create Backups node) includes the net_backup role. This role creates the directory defined by the value of the backup_store variable.

    3. Click Save.

    4. Enable the survey for the Config & Back up job template. Click Survey Disabled and verify that the label changes to Survey Enabled.

  15. Launch the Configure & Back up workflow template and observe the result.

    1. Navigate to ResourcesTemplates.

    2. Click the Launch Template icon for the Configure & Back up workflow template.

    3. Enter /compreview as the response to the survey question and then click Next.

    4. Click Launch to launch the workflow template with /compreview as the value for the backup_store variable.

    5. Monitor the workflow. All nodes in the workflow succeed.

  16. Verify that the /compreview directory exists on the workstation machine and that the directory contains a backup file for each managed node in the ios and junos inventory host groups.

    1. List the contents of the /compreview directory:

      [student@workstation ~]$ ls -1 /compreview
      iosxe1.lab.example.com.cfg
      iosxe2.lab.example.com.cfg
      junos1.lab.example.com.cfg
      junos2.lab.example.com.cfg
    2. (Optional) Inspect one or more of the backup files for changes made by the Configure Interfaces and the Deploy DNS, NTP, & Syslog job templates.

      The Configure Interfaces job template added the Managed by Ansible description to some interfaces on the managed nodes.

      The Deploy DNS, NTP, & Syslog job template added the following servers:

      Server typeAdded servers
      DNS 172.25.250.220 and 172.25.240.220
      NTP 172.25.23.240 and 172.25.23.230
      Syslog 192.168.10.10 and 192.168.11.10

Evaluation

As the student user on the workstation machine, use the lab command to grade your work. Correct any reported failures and rerun the command until successful.

[student@workstation ~]$ lab grade compreview-cr4

Finish

As the student user on the workstation machine, 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 compreview-cr4
Revision: do457-2.3-7cfa22a