Bookmark this page

Lab: Managing Projects and Launching Ansible Jobs

  • Create a new project and job template, and assign an appropriate role for a team to be able to launch a job.

Outcomes

  • Create a project.

  • Create a job template.

  • Allow a team to launch a job using a job template.

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

Procedure 4.3. Instructions

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

  2. Create a new project called My Webservers with the following information:

    Table 4.1. New Project Details

    FieldValue
    Name My Webservers
    Description Webservers Project
    Organization Default
    Source Control Credential Type Git
    Source Control URL git@git.lab.example.com:git/my_webservers.git
    Source Control Credential Student Git Credential

    1. Navigate to ResourcesProjects and then click Add.

    2. Create the new project using the information in the New Project Details table. When finished, click Save.

    3. Automation controller automatically attempts to synchronize the new project. On the Details page for the My Webservers 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.

  3. Give the Developers team both the Use and the Update roles on the My Webservers project.

    1. Navigate to ResourcesProjects and click the My Webservers link.

    2. Click the Access tab and then click Add.

    3. Select Teams and then click Next.

    4. Select Developers and then click Next.

    5. Select both Use and Update and then click Save to assign the roles. This redirects you to the list of permissions for the My Webservers project. The daniel and david users have the Use and Update roles because they belong to the Developers team.

  4. Create a new job template called TEST webservers setup with the following information:

    Table 4.2. New Job Template Details

    FieldValue
    Name TEST webservers setup
    Description Setup apache on TEST webservers
    Job Type Run
    Inventory Test
    Project My Webservers
    Playbook apache-setup.yml
    Credentials Operations

    1. Navigate to ResourcesTemplates and click AddAdd job template.

    2. Create the new job template using the information in the New Job Template Details table. When finished, click Save.

  5. Give the Developers team the Execute role on the TEST webservers setup job template.

    1. Navigate to ResourcesTemplates and click the TEST webservers setup link.

    2. Click the Access tab and then click Add.

    3. Select Teams and then click Next.

    4. Select Developers and then click Next.

    5. Select Execute and then click Save to assign the role. This redirects you to the list of permissions for the TEST webservers setup job template. The daniel and david users have the Execute role because they belong to the Developers team.

  6. Clone the https://git.lab.example.com/git/my_webservers.git Git repository into the /home/student/git-repos directory.

    1. From a terminal, create the /home/student/git-repos directory if it does not already exist, and then change into it.

      [student@workstation ~]$ mkdir -p ~/git-repos/
      [student@workstation ~]$ cd ~/git-repos/
    2. Clone the https://git.lab.example.com/git/my_webservers.git repository and then change into the cloned repository:

      [student@workstation git-repos]$ git clone \
      > https://git.lab.example.com/git/my_webservers.git
      Cloning into 'my_webservers'...
      ...output omitted...
      [student@workstation git-repos]$ cd my_webservers
  7. Edit the ~/git-repos/my_webservers/templates/index.html.j2 Jinja2 template file. Add the highlighted Host IP Address line so that the file has the following content. Add and commit your changes to your Git repository, and then push your changes to the remote repository.

    Current Host: {{ ansible_facts['fqdn'] }} <br>
    Host IP Address: {{ ansible_facts['default_ipv4']['address'] }} <br>
    Server list: <br>
    {% for host in groups['all'] %}
    {{ host }} <br>
    {% endfor %}
    1. Edit the ~/git-repos/my_webservers/templates/index.html.j2 file so that it contains the previously displayed Host IP Address line.

    2. Use the git add command to add the modified file to the next Git commit.

      [student@workstation my_webservers]$ git add templates/index.html.j2
    3. Commit your changes to your local Git repository.

      [student@workstation my_webservers]$ git commit -m "Added Host IP Address"
      [main 373e307] Added Host IP Address
       1 file changed, 1 insertion(+)
    4. Use the git push command to push the changes to the remote Git repository.

      [student@workstation my_webservers]$ git push
      Enumerating objects: 7, done.
      Counting objects: 100% (7/7), done.
      Delta compression using up to 4 threads
      Compressing objects: 100% (4/4), done.
      Writing objects: 100% (4/4), 524 bytes | 524.00 KiB/s, done.
      Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
      To https://git.lab.example.com/git/my_webservers.git
         abd5989..373e307  main -> main
  8. Test the project and job template permissions that you previously assigned to the Developers team. Log in as david using redhat123 as the password, update the My Webservers project, and then launch a job using the TEST webservers setup job template. When finished, log out of the automation controller web UI.

    1. From the automation controller web UI, click adminLogout and then log in as david using redhat123 as the password.

    2. Navigate to ResourcesProjects and then click the Sync Project icon for the My Webservers project.

    3. Navigate to ResourcesTemplates and then click the Launch Template icon for the TEST webservers setup job template.

    4. Observe the live output of the running job.

    5. Click the Details tab and verify that the Status field displays the Successful message. This step could take several seconds or minutes to complete depending of the size of the Git repository,

    6. From the automation controller web UI, click davidLogout.

  9. Verify the web content displayed on http://serverc.lab.example.com and http://serverd.lab.example.com. The web pages should display the fully qualified domain name and IP address of the current host.

    1. From a terminal window, use the curl command to review the web content on http://serverc.lab.example.com and http://serverd.lab.example.com.

      [student@workstation my_webservers]$ for X in server{c,d}.lab.example.com
      > do curl http://${X}
      > echo
      > done
      Current Host: serverc.lab.example.com <br>
      Host IP Address: 172.25.250.12 <br>
      Server list: <br>
      serverc.lab.example.com <br>
      serverd.lab.example.com <br>
      
      Current Host: serverd.lab.example.com <br>
      Host IP Address: 172.25.250.13 <br>
      Server list: <br>
      serverc.lab.example.com <br>
      serverd.lab.example.com <br>

      Note

      Alternatively, review the content of both http://serverc.lab.example.com and http://serverd.lab.example.com in a graphical web browser such as Firefox.

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

This concludes the section.

Revision: do467-2.2-08877c1