Bookmark this page

Lab: Installation and Configuration

Prepare for playbook development by installing required software, and then creating configuration files, inventory files, and variable files.

Outcomes

  • Install software that you use throughout the comprehensive review.

  • Use Git to clone a repository, create a branch, commit, and push changes to a branch.

  • Generate an automation content navigator configuration file.

  • Convert the provided Ansible inventory files to YAML format.

  • Create Ansible group variables.

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

[student@workstation ~]$ lab start compreview-cr1

Specifications

This exercise prepares the workstation machine to run playbooks by using an automation execution environment with automation content navigator.

  • Install the ansible-navigator and podman RPM packages.

  • Download the hub.lab.example.com/ee-supported-rhel8 automation execution environment from the lab environment's private automation hub. You can log in to the hub.lab.example.com container registry by using student as the username and redhat123 as the password.

  • Use the information in the following table to configure global Git settings for the student user:

    DescriptionValue
    User's name Student User
    User's email student@lab.example.com
  • Clone the git@git.lab.example.com:student/compreview repository into the /home/student/git-repos directory and then create a branch named cr1 for this exercise.

  • Create an automation content navigator configuration file that meets the following list of settings:

    • Uses the hub.lab.example.com/ee-supported-rhel8 automation execution environment image

    • Specifies missing as the image pull policy

    • Defines the inventory.yaml file as an Ansible inventory entry

    • Disables the creation of playbook artifacts

  • Perform the following actions on the provided inventory-controller and inventory files:

    • Convert the files from INI format to YAML format. Use inventory-controller.yaml and inventory.yaml as the respective file names.

    • Delete any variable information from the inventory-controller.yaml file.

    • Delete any variable information other than the ansible_ssh_private_key_file and ansible_user variables from the inventory.yml file, and then move those definitions to the all group of managed nodes.

    • Delete the inventory-controller and inventory files.

    Note

    The reason for having two inventories is that you can develop and test playbooks on the workstation machine using the inventory.yaml file, and then you can import the inventory-controller.yaml file into automation controller to run the playbooks from that environment.

    By defining the ansible_ssh_private_key_file variable in the inventory.yaml file, rather than in a file in the group_vars/all directory, your local playbooks can use the private SSH key without causing problems with automation controller, where you create the credential resources you need.

  • Your project already has a subdirectory structure for each inventory group of managed nodes under the group_vars directory. Create a file named connection.yml for the eos, ios, and junos inventory groups. Populate each connection.yml file with the appropriate variables and values from the following tables:

    VariableValue for the eos inventory group
    ansible_connection ansible.netcommon.network_cli
    ansible_network_os arista.eos.eos
    ansible_become true
    ansible_become_method enable
    VariableValue for the ios inventory group
    ansible_connection ansible.netcommon.network_cli
    ansible_network_os cisco.ios.ios
    ansible_become true
    ansible_become_method enable
    VariableValue for the junos inventory group
    ansible_connection ansible.netcommon.netconf
    ansible_network_os junipernetworks.junos.junos
  • Create the host_vars/workstation.lab.example.com directory and then create a file named connection.yml in that directory. Set the ansible_user variable to devops.

  • Commit and push all the changes that you made in the /home/student/git-repos/compreview directory to the remote Git repository. Use Prepare for development as the commit message.

  1. Install the ansible-navigator and podman RPM packages.

    1. Use the dnf command to install the ansible-navigator and podman packages:

      [student@workstation ~]$ sudo dnf install ansible-navigator podman
      [sudo] password for student: student
      ...output omitted...
      Is this ok [y/N]: y
      ...output omitted...
      Complete!
  2. Download the ee-supported-rhel8 automation execution environment from hub.lab.example.com, the lab environment's private automation hub.

    1. Use the podman login command to log in to the classroom private automation hub at hub.lab.example.com. Use student as the username and redhat123 as the password:

      [student@workstation ~]$ podman login hub.lab.example.com
      Username: student
      Password: redhat123
      Login Succeeded!
    2. Use the podman pull command to download the automation execution environment:

      [student@workstation ~]$ podman pull hub.lab.example.com/ee-supported-rhel8
      Trying to pull hub.lab.example.com/ee-supported-rhel8:latest...
      Getting image source signatures
      Copying blob 9b6252cdda58 done
      ...output omitted...
  3. Use the information in the following table to configure global Git settings for the student user.

    DescriptionValue
    User's name Student User
    User's email student@lab.example.com
    1. Use the git command with the config option to customize Git globally:

      [student@workstation ~]$ git config --global user.name 'Student User'
      [student@workstation ~]$ git config --global user.email student@lab.example.com
    2. Verify the global configuration settings:

      [student@workstation ~]$ git config --global -l
      user.name=Student User
      user.email=student@lab.example.com
  4. Clone the git@git.lab.example.com:student/compreview repository into the /home/student/git-repos directory and then create a branch named cr1 for this exercise.

    1. Create the /home/student/git-repos directory and then change to this directory:

      [student@workstation ~]$ mkdir -p ~/git-repos
      [student@workstation ~]$ cd ~/git-repos
      [student@workstation git-repos]$
    2. Clone the git@git.lab.example.com:student/compreview repository:

      [student@workstation git-repos]$ git clone \
      git@git.lab.example.com:student/compreview
      Cloning into 'compreview'...
      ...output omitted...
    3. Change to the repository directory. Create a branch named cr1 and check it out:

      [student@workstation git-repos]$ cd compreview
      [student@workstation compreview]$ git checkout -b cr1
      Switched to a new branch 'cr1'
  5. Create an automation content navigator configuration file that meets the following criteria:

    • Uses the hub.lab.example.com/ee-supported-rhel8 automation execution environment image

    • Specifies missing as the image pull policy

    • Defines the inventory.yaml file as an Ansible inventory entry

    • Disables the creation of playbook artifacts

    1. Use the ansible-navigator command with the settings subcommand and the --effective option to display the effective settings. Add the --eei and --pp options to specify the automation execution environment image and the pull policy. Redirect the command output into a file named navigator-sample.yml.

      [student@workstation compreview]$ ansible-navigator settings \
      --effective --eei hub.lab.example.com/ee-supported-rhel8 \
      --pp missing > navigator-sample.yml

      Important

      If you attempt to redirect the output of the ansible-navigator command to a file named ansible-navigator.yml, then the command fails.

    2. Rename the navigator-sample.yml file to ansible-navigator.yml.

      [student@workstation compreview]$ mv navigator-sample.yml ansible-navigator.yml
    3. Open VS Code and click FileOpen Folder. Navigate to git-reposcompreview and click Open.

      Note

      If prompted, select Trust the authors of all files in the parent folder 'student', and then click Yes, I trust the authors.

    4. Select the ansible-navigator.yml file. Add an entry for the inventory.yaml Ansible inventory and disable the creation of playbook artifacts. Optionally, remove any lines not related to what was requested. When finished, save the file.

      The final ansible-navigator.yml file must consist of at least the following content:

      ---
      ansible-navigator:
        ansible:
          inventory:
            entries:
              - ./inventory.yaml
        execution-environment:
          image: hub.lab.example.com/ee-supported-rhel8:latest
          pull:
            policy: missing
        mode: stdout
        playbook-artifact:
          enable: false
  6. Perform the following actions on the provided inventory-controller and inventory files:

    • Convert the inventory files to YAML format. Use inventory-controller.yaml and inventory.yaml as the respective file names.

    • Delete any variable information from the inventory-controller.yaml file.

    • Delete any variable information other than the ansible_user and ansible_ssh_private_key_file variables from the inventory.yaml file.

    • Delete the provided inventory-controller and inventory files to prevent any confusion.

    1. Use the ansible-navigator command with the inventory subcommand and the --list and --yaml options to display the YAML version of the inventory-controller file. Redirect the output of the command to create the inventory-controller.yaml file:

      [student@workstation compreview]$ ansible-navigator inventory \
      -i inventory-controller --list --yaml > inventory-controller.yaml
    2. Select the inventory-controller.yaml file in VS Code. Delete any information related to variables. When finished, save the file.

      After editing the inventory-controller.yaml file, it contains the following content:

      all:
        children:
          eos:
            hosts:
              arista1.lab.example.com:
              arista2.lab.example.com:
          ios:
            hosts:
              iosxe1.lab.example.com:
              iosxe2.lab.example.com:
          junos:
            hosts:
              junos1.lab.example.com:
              junos2.lab.example.com:
          ungrouped:
            hosts:
              workstation.lab.example.com:
    3. Use the ansible-navigator command with the inventory subcommand and the --list and --yaml options to display the YAML version of the inventory file. Redirect the output of the command to create the inventory.yaml file:

      [student@workstation compreview]$ ansible-navigator inventory \
      -i inventory --list --yaml > inventory.yaml
    4. Select the inventory.yaml file in VS Code. Delete any variable information other than the ansible_user and ansible_ssh_private_key_file variables from the inventory.yml file.

    5. Move the definitions of the ansible_ssh_private_key_file and ansible_user variables to the all group of managed nodes so that you do not have to define those variables in each group of managed nodes. When finished, save the file.

      After editing the inventory.yaml file, it contains the following content:

      all:
        vars:
          ansible_ssh_private_key_file: ~/.ssh/lab_rsa
          ansible_user: student
        children:
          eos:
            hosts:
              arista1.lab.example.com:
              arista2.lab.example.com:
          ios:
            hosts:
              iosxe1.lab.example.com:
              iosxe2.lab.example.com:
          junos:
            hosts:
              junos1.lab.example.com:
              junos2.lab.example.com:
          ungrouped:
            hosts:
              workstation.lab.example.com:
    6. Delete the inventory-controller and inventory files:

      [student@workstation compreview]$ rm inventory-controller inventory
  7. Create a file named connection.yml under each of the eos, ios, and junos subdirectories of the group_vars directory. Populate the connection.yml files with the variables and values from the following tables:

    VariableValue for the eos inventory group
    ansible_connection ansible.netcommon.network_cli
    ansible_network_os arista.eos.eos
    ansible_become true
    ansible_become_method enable
    VariableValue for the ios inventory group
    ansible_connection ansible.netcommon.network_cli
    ansible_network_os cisco.ios.ios
    ansible_become true
    ansible_become_method enable
    VariableValue for the junos inventory group
    ansible_connection ansible.netcommon.netconf
    ansible_network_os junipernetworks.junos.junos
    1. Create the group_vars/eos/connection.yml file with the following content:

      ---
      ansible_connection: ansible.netcommon.network_cli
      ansible_network_os: arista.eos.eos
      ansible_become: true
      ansible_become_method: enable
    2. Create the group_vars/ios/connection.yml file with the following content:

      ---
      ansible_connection: ansible.netcommon.network_cli
      ansible_network_os: cisco.ios.ios
      ansible_become: true
      ansible_become_method: enable
    3. Create the group_vars/junos/connection.yml file with the following content:

      ---
      ansible_connection: ansible.netcommon.netconf
      ansible_network_os: junipernetworks.junos.junos
  8. Create the host_vars/workstation.lab.example.com directory and then create a file named connection.yml in that directory. Set the ansible_user variable to devops.

    1. Create the host_vars directory and include a workstation.lab.example.com subdirectory:

      [student@workstation compreview]$ mkdir -p host_vars/workstation.lab.example.com
    2. Create the host_vars/workstation.lab.example.com/connection.yml file with the following content:

      ---
      ansible_user: devops
  9. Commit and push all the changes that you made in the /home/student/git-repos/compreview directory to the remote Git repository. Use Prepare for development as the commit message.

    1. Use VS Code or the git add command to add the new and updated files and directories:

      [student@workstation compreview]$ git add .
    2. Use VS Code or the git status command to display the list of files that you staged for the next commit:

      [student@workstation compreview]$ git status
      On branch cr1
      Changes to be committed:
        (use "git restore --staged <file>..." to unstage)
      	       new file:   ansible-navigator.yml
      	       new file:   group_vars/eos/connection.yml
      	       new file:   group_vars/ios/connection.yml
      	       new file:   group_vars/junos/connection.yml
      	       new file:   host_vars/workstation.lab.example.com/connection.yml
      	       deleted:    inventory
      	       deleted:    inventory-controller
      	       new file:   inventory-controller.yaml
      	       new file:   inventory.yaml
    3. Use VS Code or the git commit command to commit the files. Use Prepare for development as the commit message:

      [student@workstation compreview]$ git commit -m "Prepare for development"
      [cr1 3e21bbd] Prepare for development
       9 files changed, 66 insertions(+), 30 deletions(-)
       create mode 100644 ansible-navigator.yml
       create mode 100644 group_vars/eos/connection.yml
       create mode 100644 group_vars/ios/connection.yml
       create mode 100644 group_vars/junos/connection.yml
       create mode 100644 host_vars/workstation.lab.example.com/connection.yml
       delete mode 100644 inventory
       delete mode 100644 inventory-controller
       create mode 100644 inventory-controller.yaml
       create mode 100644 inventory.yaml
    4. Use VS Code or the git push command to update the remote Git repository:

      [student@workstation compreview]$ git push -u origin cr1
      Enumerating objects: 20, done.
      Counting objects: 100% (19/19), done.
      Delta compression using up to 6 threads
      Compressing objects: 100% (13/13), done.
      Writing objects: 100% (15/15), 1.50 KiB | 1.50 MiB/s, done.
      Total 15 (delta 2), reused 0 (delta 0), pack-reused 0
      remote:
      remote: To create a merge request for cr1, visit:
      remote:   https://git.lab.example.com/student/compreview/-/merge_requests/new?merge_request%5Bsource_branch%5D=cr1
      remote:
      To git.lab.example.com:student/compreview.git
       * [new branch]      cr1 -> cr1
      Branch 'cr1' set up to track remote branch 'cr1' from 'origin'.
  10. Close the /home/student/git-repos/compreview directory in VS Code. Return to the /home/student directory in the GNOME terminal.

    1. Click FileClose Folder in VS Code to close the /home/student/git-repos/compreview directory.

    2. Run the cd command in the GNOME terminal to return to the student home directory:

      [student@workstation compreview]$ cd

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 compreview-cr1

Finish

As the student user on the workstation machine, 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 compreview-cr1

Revision: do457-2.3-7cfa22a