Bookmark this page

Lab: Running Playbooks with Automation Controller

  • Launch a job with automation controller that runs a playbook using a specific execution environment, and then review the job results.

Outcomes

  • Create automation controller resources, such as credentials, projects, and inventories.

  • Create a new job template and then launch a job from the job template.

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

This command creates the /home/student/controller-review directory, prepares automation controller and private automation hub for the exercise, and creates a Git repository that includes a playbook to test your work.

[student@workstation ~]$ lab start controller-review

Procedure 3.2. Instructions

This lab provides you with a Git repository that contains a working playbook to deploy a simple web server. Create all resources from the automation controller web UI located at https://controller.lab.example.com. Log in as the admin user with redhat as the password.

  1. Create a source control credential named reviewgitcred. The credential must belong to the Default organization. The GitLab user for the credential is student. Use the private key stored in the /home/student/.ssh/gitlab_rsa file on the workstation machine as the SCM private key.

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

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

      FieldValue
      Name reviewgitcred
      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 area and select Show Hidden Files. Viewing hidden files lets you see the .ssh directory in the /home/student directory.

  2. Create a machine credential named reviewmachinecred. The credential must belong to the Default organization. Configure this credential for the devops user. Use the SSH private key stored in the /home/student/.ssh/lab_rsa file. Use sudo as the privilege escalation method and root as the privilege escalation username.

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

      FieldValue
      Name reviewmachinecred
      Organization Default
      Credential Type Machine
      Username devops
      SSH Private Key Content of the /home/student/.ssh/lab_rsa file.
      Privilege Escalation Method sudo
      Privilege Escalation Username root
  3. Create an inventory named reviewinventory. The inventory must belong to the Default organization. Add the servera.lab.example.com host to this inventory.

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

      FieldValue
      Name reviewinventory
      Organization Default
    2. Click the Hosts tab and then click Add. Add the servera.lab.example.com host, and then click Save.

  4. Create a project named reviewproject. The project must belong to the Default organization. This project must use the git@git.lab.example.com:student/controller-review.git Git repository and use the reviewgitcred source control credential to authenticate to the repository.

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

      FieldValue
      Name reviewproject
      Organization Default
      Source Control Type Git
      Source Control URL git@git.lab.example.com:student/controller-review.git
      Source Control Credential reviewgitcred

      After clicking Save, automation controller immediately attempts to synchronize the project. The project synchronization succeeds.

      Important

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

  5. Create a job template named reviewtemplate. Configure the job template to use the reviewinventory inventory, the reviewproject project, the webserver.yml playbook, and the reviewmachinecred machine credential. Configure the job template to use the Automation Hub Default execution environment execution environment.

    Launch a job that uses the reviewtemplate job template. If you completed the exercise correctly, then navigating to http://servera.lab.example.com displays the following message:

    Successful playbook run from automation controller.
    1. Navigate to ResourcesTemplates and then click AddAdd job template. Create the new job template with the following settings and then click Save.

      FieldValue
      Name reviewtemplate
      Inventory reviewinventory
      Project reviewproject
      Execution Environment Automation Hub Default execution environment
      Playbook webserver.yml
      Credentials reviewmachinecred
    2. Click Launch to create a job from the job template. The resulting job runs the playbook.

      Important

      If the job fails, then ensure that the job template specifies the correct inventory and machine credential. Ensure that the machine credential uses the correct values and then launch a new job from the job template.

    3. Click the Details tab. Notice that the job displays Successful as its status.

    4. Verify the web content updated by the job. Either use a web browser to navigate to http://servera.lab.example.com or run the following curl command:.

      [student@workstation ~]$ curl http://servera.lab.example.com
      Successful playbook run from automation controller.

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

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

This concludes the section.

Revision: do374-2.2-82dc0d7