Bookmark this page

Guided Exercise: Running Playbooks in Automation Controller

  • Navigate through the automation controller web UI and launch a job.

Outcomes

  • Create source control and machine credentials.

  • Create a project.

  • Create an inventory that uses an inventory file from the project.

  • Create a new job template.

  • Launch a job template and review the output generated by the job.

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

This command creates the Git repository used by this exercise.

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

Procedure 3.1. Instructions

This exercise provides you with an Ansible project in a Git repository that contains a working playbook to deploy a simple web server.

  1. Automation controller must have a source control credential to access content from a Git repository. From the automation controller web UI, create a source control credential named Git Project Credential. Configure this 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. Create the credential with the following settings and then click Save.

      FieldValue
      Name Git Project Credential
      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.

  2. To run the playbook against each managed host, automation controller must have a machine credential that contains authentication information. Create a machine credential named Devops Machine Credential that contains authentication information for the managed hosts in the classroom environment.

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

      FieldValue
      Name Devops Machine Credential
      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

      Note

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

  3. Create a project named Controller Playbooks Project. This project points to a Git repository that contains a playbook and an inventory file. Configure the project to specify a default automation execution environment.

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

      FieldValue
      Name Controller Playbooks Project
      Organization Default
      Execution Environment Automation Hub Default execution environment
      Source Control Type Git
      Source Control URL git@git.lab.example.com:student/controller-playbooks.git
      Source Control Credential Git Project Credential
      Options Allow Branch Override

      After you click Save, automation controller immediately attempts to synchronize the project. The project synchronization should succeed.

      Important

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

  4. Create an inventory for this exercise named Controller Playbooks Inventory (Dev) using the inventory file in the project repository.

    Managing your inventory file in a Git repository enables you to benefit from storing your changes in a version control system. You can also update it by editing the file rather than manually updating inventory information in the automation controller web UI.

    1. Navigate to ResourcesInventories and then click AddAdd inventory.

    2. Create a new inventory with the following settings and then click Save.

      FieldValue
      Name Controller Playbooks Inventory (Dev)
      Organization Default
    3. From the Sources tab, click Add. Create a new inventory source with the following settings and then click Save.

      Note

      After selecting the project, you might see the following error message: That value was not found. Please enter or select a valid value. The error message disappears when you select the inventory file.

      FieldValue
      Name Controller Playbooks Source (Dev)
      Source Sourced from a Project
      Project Controller Playbooks Project
      Inventory file inventory
      Options Update on project update
    4. Click Sources in the breadcrumb navigator and then click the Start sync process icon for the Controller Playbooks Source (Dev) source. The status updates to indicate that the synchronization succeeded.

    5. Click the Hosts tab. The inventory source imported the serverf.lab.example.com host.

    6. Click the Groups tab. The inventory source imported the web group.

    7. Click web and then click the Hosts tab. The web group contains the serverf.lab.example.com host.

  5. Create a job template named Basic Web. Configure the job template to run the basic-web-fqcn.yml playbook using the default automation execution environment for the project. The playbook ensures that a web server and its content are deployed on hosts in the web inventory host group.

    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 Basic Web
      Inventory Controller Playbooks Inventory (Dev)
      Project Controller Playbooks Project
      Playbook basic-web-fqcn.yml
      Credentials Devops Machine Credential
    2. Click Launch to run the job template. The resulting job successfully runs the playbook.

    3. Navigate to ViewsJobs and look for a numbered job with Basic Web in the name. By default, automation controller lists the most recent jobs at the top. The Basic Web job displays a status of Successful.

    4. (Optional) Click the name of the Basic Web job to review the job output. This is the same output that you initially saw when you launched the job.

    5. Verify that the job successfully deployed a web server on serverf.lab.example.com. From a terminal window, run the curl command to access web content at http://serverf.lab.example.com.

      [student@workstation ~]$ curl http://serverf.lab.example.com
      Hello world from serverf.lab.example.com.

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-playbooks

This concludes the section.

Revision: do374-2.2-82dc0d7