Bookmark this page

Lab: Configuring Job Templates

  • Configure several job templates, as well as a supporting project and source control credentials.

Outcomes

  • Create a machine credential and a source control credential.

  • Create a project.

  • Create an inventory and use a static inventory file stored in a Git repository as its source.

  • Create some job templates.

  • Launch the job templates 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 prepares your environment and ensures that all required resources are available.

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

Specifications

In this lab, you create a job template for a log server configuration and a job template for the configuration of the clients. You also create the necessary credentials and use an existing inventory stored in a Git repository as an inventory source.

Your automation controller is at https://controller.lab.example.com. You can log in to it using admin as the user and redhat as the password.

  • Create a machine credential in your automation controller using the information in the following table.

    FieldValue
    Name Virtual Machines
    Description Credential for managing virtual machines
    Organization Default
    Credential Type Machine
    Username devops
    Password redhat
    Privilege Escalation Method sudo
    Privilege Escalation Username root

    Note

    Because the devops user does not need to enter a password to run sudo commands, you do not need to enter a password in the Privilege Escalation Password field.

  • Create a source control credential in your automation controller using the information in the following table.

    FieldValue
    Name Git Credential
    Organization Default
    Credential Type Source Control
    Username git
    SCM Private Key Contents of the /home/student/.ssh/gitlab_rsa file

    Note

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

  • Create a new project in your automation controller using the information in the following table. Notice that you use the source control credential previously created. After you save the project, verify that automation controller reports the success of the project synchronization.

    FieldValue
    Name Log Centralization
    Description Log Centralization Project
    Organization Default
    Source Control Type Git
    Source Control URL git@git.lab.example.com:git/compreview-templates.git
    Source Control Credential Git Credential

    Important

    If the project synchronization fails, then ensure that the project specifies the correct source control URL and the correct source control credential. Ensure that the source control credential uses the correct values and then attempt the project synchronization again.

  • Create an inventory in your automation controller called Lab Git Sourced in the Default organization.

    FieldValue
    Name Lab Git Sourced
    Organization Default

    Then, add a source for this inventory using the information in the following table. After you save the Git Inventory Lab source, start the synchronization process. Verify that the synchronization process succeeds.

    FieldValue
    Name Git Inventory Lab
    Source Sourced from a Project
    Project Log Centralization
    Inventory file inventory
    Update options Update on launch (selected)

    Important

    You might see the following message below the Project field, even if you selected the project name from the list of projects.

    That value was not found. Please enter or select a valid value.

    The message disappears as soon as you select a different field.

  • Review the Groups tab and the Hosts tab for the Lab Git Sourced inventory. The hosts are grouped as shown in the following table. Notice that the variables for the dev_clients and prod_clients groups are also imported.

    Parent groupChildren groupHost
    log_servers dev_servers servera.lab.example.com
    prod_servers serverd.lab.example.com
    log_clients dev_clients serverb.lab.example.com
    serverc.lab.example.com
    prod_clients servere.lab.example.com
    serverf.lab.example.com
  • Create a job template in your automation controller using the information in the following table. This job template configures a centralized log server on each of the hosts in the log_servers group for the Lab Git Sourced inventory.

    FieldValue
    Name Log Servers Deploy
    Job Type Run
    Inventory Lab Git Sourced
    Project Log Centralization
    Playbook rsyslog_server_deploy.yml
    Credentials Virtual Machines
  • Create a job template in your automation controller using the information in the following table. This job template configures each of the hosts in the log_clients group for the Lab Git Sourced inventory as a client for its respective log server.

    FieldValue
    Name Log Clients Deploy
    Job Type Run
    Inventory Lab Git Sourced
    Project Log Centralization
    Playbook rsyslog_client_deploy.yml
    Credentials Virtual Machines
  • Launch the Log Servers Deploy job template. Observe the live output of the running job. Verify that the job succeeds.

  • Launch the Log Clients Deploy job template. Observe the live output of the running job. Verify that the job succeeds.

  • Verify that the hosts from the dev_clients group in the Lab Git Sourced inventory send logs to servera.lab.example.com. Use the logger "This is a test" command to create a log entry in the dev_clients hosts.

  • Verify that the hosts from the prod_clients group in the Lab Git Sourced inventory send logs to serverd.lab.example.com. Use the logger "This is a test" command to create a log entry in the prod_clients hosts.

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

  2. Create a machine credential using the information in the following table.

    FieldValue
    Name Virtual Machines
    Description Credential for managing virtual machines
    Organization Default
    Credential Type Machine
    Username devops
    Password redhat
    Privilege Escalation Method sudo
    Privilege Escalation Username root
    1. Navigate to ResourcesCredentials and click Add to add a new credential.

    2. Enter Virtual Machines in the Name field and Credential for managing virtual machines in the Description field.

    3. Select the Default organization.

    4. In the Credential Type list, choose Machine.

    5. Enter devops in the Username field and redhat in the Password field.

    6. In the Privilege Escalation Method list, choose sudo.

    7. Enter root in the Privilege Escalation Username field.

    8. Click Save to save the machine credential.

  3. Create a source control credential using the information in the following table.

    FieldValue
    Name Git Credential
    Organization Default
    Credential Type Source Control
    Username git
    SCM Private Key Content of the /home/student/.ssh/gitlab_rsa file.
    1. Navigate to ResourcesCredentials and click Add to add a new credential.

    2. Enter Git Credential in the Name field.

    3. Select the Default organization.

    4. In the Credential Type list, choose Source Control.

    5. Enter git in the Username field and click Browse in the SCM Private Key field.

    6. By default, the File Upload directory navigation window opens in the Desktop directory. Click student to move to the home directory for the student user.

      Figure 12.10: Browsing for the SCM Private Key
    7. Right-click anywhere in the directory navigation window and select Show Hidden Files.

    8. Change to the .ssh hidden directory, then select the gitlab_rsa file, and click Open.

    9. Click Save to save the source control credential.

  4. Create a new project using the information in the following table. After you save the project, verify that automation controller reports the success of the project synchronization.

    FieldValue
    Name Log Centralization
    Description Log Centralization Project
    Organization Default
    Source Control Type Git
    Source Control URL git@git.lab.example.com:git/compreview-templates.git
    Source Control Credential Git Credential
    1. Navigate to ResourcesProjects and then click Add to create a new project.

    2. Enter Log Centralization in the Name field and Log Centralization Project in the Description field.

    3. Select the Default organization if it is not selected by default.

    4. In the Source Control Type list, choose Git.

    5. Enter git@git.lab.example.com:git/compreview-templates.git in the Source Control URL field.

    6. Select the Git Credential source control credential.

    7. Click Save to save the project.

    8. Automation controller automatically attempts to synchronize the new project. On the Details page for the Log Centralization project, verify that the Last Job Status field displays the Successful message.

      Important

      If the project synchronization fails, then ensure that the project specifies the correct source control URL and the correct source control credential.

  5. Create an inventory called Lab Git Sourced in the Default organization.

    FieldValue
    Name Lab Git Sourced
    Organization Default

    Then, add a source for this inventory using the information in the following table. After you save the Git Inventory Lab source, start the synchronization process. Verify that the synchronization process succeeds.

    FieldValue
    Name Git Inventory Lab
    Source Sourced from a Project
    Project Log Centralization
    Inventory file inventory
    Update options Update on launch (selected)
    1. Navigate to ResourcesInventories.

    2. Click AddAdd inventory.

    3. Enter Lab Git Sourced in the Name field and select the Default organization. When done, click Save.

    4. Click in the Sources tab, and then click Add to add a source for the inventory.

    5. Enter Git Inventory Lab in the Name field.

    6. In the Source list, choose Sourced from a Project.

    7. Select the Log Centralization project. You might see the following message below the Project field:

      That value was not found. Please enter or select a valid value.

      The message disappears as soon as you select a different field.

    8. Select inventory as the Inventory file.

    9. Select the Update on launch option and click Save when done.

    10. Click Sync and wait until the value of the Last Job Status field displays the Successful message.

  6. Review the Groups tab and the Hosts tab for each group in the Lab Git Sourced inventory. The hosts are grouped as shown in the following table. Notice that the variables for the hosts in the log_clients group are also imported.

    Parent groupChild groupHost
    log_servers dev_servers servera.lab.example.com
    prod_servers serverd.lab.example.com
    log_clients dev_clients serverb.lab.example.com
    serverc.lab.example.com
    prod_clients servere.lab.example.com
    serverf.lab.example.com
    1. Navigate to ResourcesInventories.

    2. Click the Lab Git Sourced link.

    3. Review the Groups tab and the Hosts tab and notice the groups and hosts that were added to the inventory. You can use the preceding table for reference.

    4. Click the Details tab for the dev_clients group and notice the variables are also imported.

      Figure 12.11: Imported variables for the hosts in the dev_clients group
    5. Click the Details tab for the prod_clients group and notice the variables are also imported.

      Figure 12.12: Imported variables for the hosts in the prod_clients group
  7. Create a job template using the information in the following table. This job template configures a centralized log server on each of the hosts in the log_servers group for the Lab Git Sourced inventory.

    FieldValue
    Name Log Servers Deploy
    Job Type Run
    Inventory Lab Git Sourced
    Project Log Centralization
    Playbook rsyslog_server_deploy.yml
    Credentials Virtual Machines
    1. Navigate to ResourcesTemplates.

    2. Click AddAdd job template.

    3. Enter Log Servers Deploy in the Name field.

    4. Select Run as the Job Type if it is not selected by default.

    5. Select the Lab Git Sourced inventory and the Log Centralization project.

    6. In the Playbook list, choose rsyslog_server_deploy.yml.

    7. Select the Virtual Machines credential.

    8. Click Save to save the job template.

  8. Create a job template using the information in the following table. This job template configures each of the hosts in the log_clients group for the Lab Git Sourced inventory as a client for its respective log server.

    FieldValue
    Name Log Clients Deploy
    Job Type Run
    Inventory Lab Git Sourced
    Project Log Centralization
    Playbook rsyslog_client_deploy.yml
    Credentials Virtual Machines
    1. Navigate to ResourcesTemplates.

    2. Click AddAdd job template.

    3. Enter Log Clients Deploy in the Name field.

    4. Select Run as the Job Type if it is not selected by default.

    5. Select the Lab Git Sourced inventory and the Log Centralization project.

    6. In the Playbook list, choose rsyslog_client_deploy.yml.

    7. Select the Virtual Machines credential.

    8. Click Save to save the job template.

  9. Launch the Log Servers Deploy job template. Observe the live output of the running job. Verify that the job succeeds.

    1. Navigate to ResourcesTemplates.

    2. Click the Launch Template icon for the Log Servers Deploy job template.

    3. Observe the live output of the running job.

      Figure 12.13: Successful output for the "Log Servers Deploy" job
    4. Click the Details tab and verify that the Status field displays the Successful message.

  10. Launch the Log Clients Deploy job template. Observe the live output of the running job. Verify that the job succeeds.

    1. Navigate to ResourcesTemplates.

    2. Click the Launch Template icon for the Log Clients Deploy job template.

    3. Observe the live output of the running job.

      Figure 12.14: Successful output for the "Log Clients Deploy" job template related job
    4. Click the Details tab and verify that the Status field displays the Successful message.

  11. Use the logger "This is a test" command to create a log entry in each of the dev_clients hosts. Verify that servera.lab.example.com, which is the only host in the dev_servers group, receives the log entries.

    1. Open a terminal on the workstation machine and use the logger command to create a log entry in the serverb.lab.example.com and serverc.lab.example.com hosts.

      [student@workstation ~]$ ssh serverb.lab.example.com "logger 'This is a test'"
      [student@workstation ~]$ ssh serverc.lab.example.com "logger 'This is a test'"
      [student@workstation ~]$
    2. Verify that the logging server receives the messages. Use the devops user in the servera.lab.example.com host for consulting the message in the /var/log/messages file. This user can run sudo commands without entering a password.

      [student@workstation ~]$ ssh devops@servera.lab.example.com \
      > "sudo grep 'This is a test' /var/log/messages"
      Aug 10 13:06:01 serverb student[1266]: This is a test
      Aug 10 13:06:07 serverc student[1263]: This is a test
      [student@workstation ~]$
  12. Use the logger "This is a test" command to create a log entry in the prod_clients hosts. Verify that serverd.lab.example.com, which is the only host in the prod_servers group, receive the log entry.

    1. Open a terminal on workstation and use the logger command to create a log entry in the servere.lab.example.com and serverf.lab.example.com hosts.

      [student@workstation ~]$ ssh servere.lab.example.com "logger 'This is a test'"
      [student@workstation ~]$ ssh serverf.lab.example.com "logger 'This is a test'"
      [student@workstation ~]$
    2. Verify that the logging server receives the messages. Use the devops user in the serverd.lab.example.com host for consulting the message in the /var/log/messages file. This user can run sudo commands without entering a password.

      [student@workstation ~]$ ssh devops@serverd.lab.example.com \
      > "sudo grep 'This is a test' /var/log/messages"
      Aug 10 13:07:37 servere student[1310]: This is a test
      Aug 10 13:07:41 serverf student[1308]: This is a test
      [student@workstation ~]$

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 compreview-templates

This concludes the section.

Revision: do467-2.2-08877c1