Bookmark this page

Guided Exercise: Using Custom Content Collections and Execution Environments in Automation Controller

  • Run a playbook in automation controller that retrieves an Ansible Content Collection by using a requirements file and that uses content in a custom Ansible Content Collection.

Outcomes

  • Run a playbook on automation controller that uses a customized collection stored on a private automation hub.

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/builder-use directory and configures automation controller with the following resources:

  • The Exercise Credential machine credential.

  • The Git Project Credential source control credential.

  • The Exercise Inventory resource.

The command also requests a new API token for the private automation hub admin user and updates the relevant automation controller credentials with the new token.

[student@workstation ~]$ lab start builder-use

Procedure 9.4. Instructions

  1. Publish the provided Ansible Content Collection on private automation hub.

    1. Navigate to https://hub.lab.example.com and log in as the student user with redhat123 as the password.

    2. From the private automation hub web UI, navigate to CollectionsNamespaces and then click Create.

    3. On the Create new namespace page, complete the details as follows and click Create to create the namespace.

      FieldValue
      Name exercise
      Namespace owners Content Developers

      Important

      The Content Developers group must be a namespace owner for group members, such as the student user, to upload to the namespace.

    4. Click Upload collection and then Select file.

    5. In the UI, browse to the /home/student/builder-use directory, select the exercise-motd-1.0.0.tar.gz file, and click Upload.

      The upload produces the following messages:

      Importing with galaxy-importer 0.4.4
      Getting doc strings via ansible-doc
      Finding content inside collection
      Loading role banner
      Linting role banner via ansible-lint...
      CHANGELOG.rst file not found at top level of collection.
      Collection loading complete
      
      Done

      Note

      A collection can include an optional CHANGELOG.rst file. It is safe to ignore the message about not being able to find the CHANGELOG.rst file.

    6. After the upload completes, navigate to CollectionsApproval and then click Approve.

  2. Create a project from the automation controller web UI.

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

    2. Navigate to ResourcesProjects and then click Add.

    3. Add a new project that installs the exercise.motd collection using a requirements file located in the project. Use the following information for the project and then click Save.

      FieldValue
      Name Install Collection
      Organization Default
      Source Control Type Git
      Source Control URL git@git.lab.example.com:student/use-collection.git
      Source Control Credential Git Project Credential
    4. Wait for the synchronization to complete.

      Note

      If the synchronization fails, then ensure that you entered the correct source control URL and that the uploaded motd collection has been approved from the private automation hub web UI. Attempt the project synchronization again.

    5. From the Details page, click Successful to display details about the project synchronization. Notice that the job installed collections found in the collections/requirements.yml file.

      ...output omitted...
      TASK [fetch galaxy collections from collections/requirements.(yml/yaml)] *******
      changed: [localhost] => (item=/var/lib/awx/projects/_8__install_collection/collections/requirements.yml)
      PLAY RECAP *********************************************************************
      localhost                  : ok=4    changed=2  ...  failed=0    skipped=2   ...
    6. (Optional) Locate the installed exercise.motd collection on the automation controller server. Open a terminal and use the ssh command to connect to the controller machine as the awx user. Display the contents of the /var/lib/awx/projects/.__awx_cache directory.

      [student@workstation ~]$ ssh awx@controller \
      > 'tree /var/lib/awx/projects/.__awx_cache'
      /var/lib/awx/projects/.__awx_cache
      └── _8__install_collection 1
          └── 3 2
              ├── requirements_collections
              │   └── ansible_collections 3
              │       ├── exercise 4
              │       │   └── motd 5
              │       │       ├── FILES.json
              │       │       ├── MANIFEST.json
      ...output omitted...

      1

      Each automation controller project has a unique identification number associated with it. In this example, the Install Collection project has project ID 8. Your project ID might be different.

      2

      This numbered directory represents the job ID of the automation controller job that performed the project synchronization. Your job ID might be different.

      3

      The ansible_collections directory contains any collections installed during the project synchronization.

      4

      The exercise director contains installed collections from the exercise namespace.

      5

      The motd directory contains files and directories from the exercise.motd collection.

      Note

      This step is for information purposes only. Most developers do not have access to view the /var/lib/awx/projects/.__awx_cache directory on the automation controller server.

  3. Display the existing messages of the day for the servera and serverb machines. The machines do not display custom messages of the day.

    1. Use the ssh command to connect to the servera machine as the student user.

      [student@workstation ~]$ ssh student@servera
      Activate the web console with: systemctl enable --now cockpit.socket
      
      This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
      To register this system, run: insights-client --register
    2. Use the logout command to return to the workstation machine.

      [student@servera ~]$ logout
      Connection to servera closed.
      [student@workstation ~]$
    3. Use the ssh command to connect to the serverb machine as the student user.

      [student@workstation ~]$ ssh student@serverb
      Activate the web console with: systemctl enable --now cockpit.socket
      
      This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
      To register this system, run: insights-client --register
    4. Use the logout command to return to the workstation machine.

      [student@serverb ~]$ logout
      Connection to serverb closed.
      [student@workstation ~]$
  4. Create a job template to run the motd-test.yml playbook from the Install Collection project.

    1. From the automation controller web UI, navigate to ResourcesTemplates.

    2. On the Templates page, click AddAdd job template. Create a job template using the following information and then click Save.

      FieldValue
      Name MOTD Test 1
      Description Test using installed collection
      Inventory Exercise Inventory
      Project Install Collection
      Execution Environment Automation Hub Minimal execution environment
      Playbook motd-test.yml
      Credentials Exercise Credential
      Limit servera.lab.example.com
    3. Click Launch to launch the MOTD Test 1 job template. The job succeeds and the output indicates that servera.lab.example.com was changed.

      ...output omitted...
      TASK [exercise.motd.banner : Create custom motd banner] ************************
      changed: [servera.lab.example.com]
      ...output omitted...
  5. Verify that the servera machine contains an additional message of the day.

    1. Use the ssh command to connect to the servera machine as the student user. The system displays a message indicating that it is managed by Ansible.

      [student@workstation ~]$ ssh student@servera
      ...output omitted...
      ================================================================================
      ================================================================================
      ==                                                                            ==
      ==                     This system is managed by Ansible.                     ==
      ==                                                                            ==
      ================================================================================
      ================================================================================
      ...output omitted...
    2. Use the logout command to return to the workstation machine.

      [student@servera ~]$ logout
      Connection to servera closed.
      [student@workstation ~]$
  6. Add a new execution environment resource using the automation controller web UI.

    1. Navigate to AdministrationExecution Environments and then click Add.

    2. Create an execution environment resource using the following information, and then click Save:

      FieldValue
      Name MOTD execution environment
      Image hub.lab.example.com/ee-motd-minimal
      Pull Only pull the image if not present before running.
      Organization Default
      Registry credential Automation Hub Container Registry
  7. Add a new automation controller project that uses the exercise.motd collection installed within a custom automation execution environment.

    1. Navigate to ResourcesProjects and then click Add. Create a project resource using the following information, and then click Save:

      FieldValue
      Name Use Custom EE
      Organization Default
      Source Control Type Git
      Source Control URL git@git.lab.example.com:student/use-ee.git
      Source Control Credential Git Project Credential
    2. Wait for the synchronization to complete.

      Note

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

  8. Create a job template to run the motd-test.yml playbook from the Use Custom EE project.

    1. Navigate to ResourcesTemplates and then click AddAdd job template. Create the job template using the following information:

      FieldValue
      Name MOTD Test 2
      Description Test using custom EE
      Inventory Exercise Inventory
      Project Use Custom EE
      Execution Environment MOTD execution environment
      Playbook motd-test.yml
      Credentials Exercise Credential
      Variables message: "My test message"
      Limit serverb.lab.example.com

      Note

      The job template selects a specific automation execution environment and only uses one host from the Exercise Inventory resource. The job template overrides the value of the message variable set in the exercise.motd.banner role.

    2. Click Save.

    3. Click Launch to launch the MOTD Test 2 job template. The job succeeds and the output indicates that serverb.lab.example.com was changed.

      ...output omitted...
      TASK [exercise.motd.banner : Create custom motd banner] ************************
      changed: [serverb.lab.example.com]
      ...output omitted...
  9. Verify that the serverb machine contains an additional message of the day.

    1. Use the ssh command to connect to the serverb machine as the student user. The system displays a message using the value of the message variable configured in the MOTD Test 2 job template.

      [student@workstation ~]$ ssh student@serverb
      ...output omitted...
      ================================================================================
      ================================================================================
      ==                                                                            ==
      ==                              My test message                               ==
      ==                                                                            ==
      ================================================================================
      ================================================================================
      ...output omitted...
    2. Use the logout command to return to the workstation machine.

      [student@serverb ~]$ logout
      Connection to serverb closed.
      [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 builder-use

This concludes the section.

Revision: do374-2.2-82dc0d7