Bookmark this page

Lab: Operating Automation Controller using the API

  • Use the automation controller API to identify and modify your automation controller settings.

Outcomes

  • Browse the automation controller API to identify variable names.

  • Prepare for changes by modifying a Git repository file used by an existing project.

  • Verify that running an existing job template updates your automation controller settings.

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

Specifications

In this activity, you manage the settings on your automation controller by using a "configuration as code" approach. You can log in to your automation controller at https://controller.lab.example.com as the admin user with redhat as the password.

  • At https://controller.lab.example.com/api/v2/settings/all/, browse the API settings for your automation controller to identify variable names and their values.

    • Identify the variable name used to set the maximum number of forks per job. This setting has a default value of 200 forks.

    • Identify the variable name used to set the maximum number of seconds of inactivity before a user needs to log in again. Automation controller tracks this with a cookie, and the setting has a default value of 1800 seconds.

    • Identify the variable name used to set the maximum number of logged in sessions that a user is allowed to have. This setting uses a default value of -1, which sets no maximum limit.

  • Clone the https://git.lab.example.com/git/comp_api.git repository to the /home/student/git-repos directory. This repository contains one playbook and two variable files. The modify_settings.yml playbook updates settings using a list of key-value pairs defined by the controller_settings variable in the vars/settings.yml variable file. (The playbook uses the ansible.controller.settings module to communicate with the automation controller API.) The vars/auth.yml variable file contains connection and authentication information for automation controller and is protected using redhat123 as the Ansible Vault password.

  • Modify the /home/student/git-repos/comp_api/vars/settings.yml file with new settings. Update the existing key-value pair in the file and add three new key-value pairs. The keys for these key-value pairs must match the name of the relevant variable that you identified from the automation controller API for that setting.

    • Update the existing ANSIBLE_FACT_CACHE_TIMEOUT key to use 7200 as the value.

    • Add a new key-value pair to set the maximum number of forks per job to 100 forks.

    • Add a new key-value pair to set the maximum number of seconds of inactivity (before a user needs to log in again) to 3600 seconds.

    • Add a new key-value pair to set the maximum number of logged in sessions that a user is allowed to have to 2 sessions.

    • Add, commit, and push your changes to the remote Git repository. Use the Git commit message: Changes to controller settings

  • From the automation controller web UI, synchronize the Controller Settings Comp-API project and then launch the Compreview_API job template. After the job completes, browse the automation controller API to verify that your automation controller uses the updated settings.

  1. Use the automation controller web UI to identify the variable names for the settings that you intend to modify.

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

    2. Navigate to https://controller.lab.example.com/api/v2/settings/all/ and search for forks. Automation controller uses the MAX_FORKS variable to set the maximum number of forks per job.

    3. Navigate to https://controller.lab.example.com/api/v2/settings/all/ and search for either cookie or 1800. Automation controller uses the SESSION_COOKIE_AGE variable to set the maximum number of seconds of inactivity before a user needs to log in again.

      Note

      Identifying the name of this variable can be difficult because possible keywords in the description of the variable do not appear in the variable name. One approach to identifying the name of a variable like the SESSION_COOKIE_AGE variable is to manually set the variable with a unique value using the web UI. You can then search the https://controller.lab.example.com/api/v2/settings/all/ page for the value that you used and identify the variable that has that value.

      You can manually change the SESSION_COOKIE_AGE variable by navigating to Settings and clicking the Miscellaneous Authentication settings link. Click Edit, enter a unique value in the Idle Time Force Log Out field, and then click Save.

    4. Navigate to https://controller.lab.example.com/api/v2/settings/all/ and search for sessions. Automation controller uses the SESSIONS_PER_USER variable to set the maximum number of logged in sessions that a user is allowed.

  2. Clone the https://git.lab.example.com/git/comp_api.git repository to the /home/student/git-repos directory.

    1. From a terminal, create the /home/student/git-repos directory if it does not 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/comp_api.git repository and then change into the cloned repository.

      [student@workstation git-repos]$ git clone \
      > https://git.lab.example.com/git/comp_api.git
      Cloning into 'comp_api'...
      ...output omitted...
      [student@workstation git-repos]$ cd comp_api
    3. Use the tree command to display the files in the repository.

      [student@workstation comp_api]$ tree
      .
      ├── modify_settings.yml
      └── vars
          ├── auth.yml
          └── settings.yml
      
      1 directory, 3 files
  3. Configure the local repository with new settings for your automation controller. When finished, push the changes to the remote Git repository.

    1. Modify the /home/student/git-repos/comp_api/vars/settings.yml file using the keys and values in the following table.

      KeyValue
      ANSIBLE_FACT_CACHE_TIMEOUT 7200
      MAX_FORKS 100
      SESSION_COOKIE_AGE 3600
      SESSIONS_PER_USER 2

      After you edit the /home/student/git-repos/comp_api/vars/settings.yml file, the file should have the following content:

      ---
      controller_settings:
        - key: ANSIBLE_FACT_CACHE_TIMEOUT
          value: 7200
        - key: MAX_FORKS
          value: 100
        - key: SESSION_COOKIE_AGE
          value: 3600
        - key: SESSIONS_PER_USER
          value: 2
    2. Add, commit, and push your changes to the remote repository. Use the commit message: Changes to controller settings

      [student@workstation comp_api]$ git add vars/settings.yml
      [student@workstation comp_api]$ git commit -m "Changes to controller settings"
      ...output omitted...
      [student@workstation comp_api]$ git push
      ...output omitted...
  4. Apply the changes made to the Git repository using the automation controller web UI.

    1. Navigate to ResourcesProjects. For the Controller Settings Comp-API project, click the Sync Project icon. Wait until the project displays the Successful status.

    2. Navigate to ResourcesTemplates. For the Compreview_API job template, click the Launch Template icon. The job succeeds and output from the job indicates changes for each key defined in the settings.yml file.

      Figure 12.19: Compreview_API job output
    3. From the https://controller.lab.example.com/api/v2/settings/all/ page, search for each key in the following table and verify that it has the expected value.

      KeyValue
      ANSIBLE_FACT_CACHE_TIMEOUT 7200
      MAX_FORKS 100
      SESSION_COOKIE_AGE 3600
      SESSIONS_PER_USER 2

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 earlier exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish compreview-api

This concludes the section.

Revision: do467-2.2-08877c1