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:
| Description | Value |
|---|---|
| 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.
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:
| Variable | Value for the eos inventory group |
|---|---|
ansible_connection
|
ansible.netcommon.network_cli
|
ansible_network_os
|
arista.eos.eos
|
ansible_become
|
true
|
ansible_become_method
|
enable
|
| Variable | Value for the ios inventory group |
|---|---|
ansible_connection
|
ansible.netcommon.network_cli
|
ansible_network_os
|
cisco.ios.ios
|
ansible_become
|
true
|
ansible_become_method
|
enable
|
| Variable | Value 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.
Install the ansible-navigator and podman RPM packages.
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!
Download the ee-supported-rhel8 automation execution environment from hub.lab.example.com, the lab environment's private automation hub.
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.comUsername:studentPassword:redhat123Login Succeeded!
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...Use the information in the following table to configure global Git settings for the student user.
| Description | Value |
|---|---|
| User's name |
Student User
|
| User's email |
student@lab.example.com
|
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
Verify the global configuration settings:
[student@workstation ~]$ git config --global -l
user.name=Student User
user.email=student@lab.example.comClone 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 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]$
Clone the git@git.lab.example.com:student/compreview repository:
[student@workstation git-repos]$git clone \git@git.lab.example.com:student/compreviewCloning into 'compreview'... ...output omitted...
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 cr1Switched to a new branch 'cr1'
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
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
If you attempt to redirect the output of the ansible-navigator command to a file named ansible-navigator.yml, then the command fails.
Rename the navigator-sample.yml file to ansible-navigator.yml.
[student@workstation compreview]$ mv navigator-sample.yml ansible-navigator.ymlOpen VS Code and click → . Navigate to → and click .
If prompted, select , and then click .
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: falsePerform 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.
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
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: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
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.
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_rsaansible_user: studentchildren: 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:
Delete the inventory-controller and inventory files:
[student@workstation compreview]$ rm inventory-controller inventoryCreate 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:
| Variable | Value for the eos inventory group |
|---|---|
ansible_connection
|
ansible.netcommon.network_cli
|
ansible_network_os
|
arista.eos.eos
|
ansible_become
|
true
|
ansible_become_method
|
enable
|
| Variable | Value for the ios inventory group |
|---|---|
ansible_connection
|
ansible.netcommon.network_cli
|
ansible_network_os
|
cisco.ios.ios
|
ansible_become
|
true
|
ansible_become_method
|
enable
|
| Variable | Value for the junos inventory group |
|---|---|
ansible_connection
|
ansible.netcommon.netconf
|
ansible_network_os
|
junipernetworks.junos.junos
|
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
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
Create the group_vars/junos/connection.yml file with the following content:
--- 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.
Create the host_vars directory and include a workstation.lab.example.com subdirectory:
[student@workstation compreview]$ mkdir -p host_vars/workstation.lab.example.comCreate the host_vars/workstation.lab.example.com/connection.yml file with the following content:
--- ansible_user: 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.
Use VS Code or the git add command to add the new and updated files and directories:
[student@workstation compreview]$ git add .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.yamlUse 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.yamlUse 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'.Close the /home/student/git-repos/compreview directory in VS Code.
Return to the /home/student directory in the GNOME terminal.
Click → in VS Code to close the /home/student/git-repos/compreview directory.
Run the cd command in the GNOME terminal to return to the student home directory:
[student@workstation compreview]$ cd