Manage group and inventory variables, configure automation content navigator settings, and push your changes to a new branch using Git.
Outcomes
Use Git to clone a repository, create a branch, ignore files, and push changes to a branch.
Configure basic automation content navigator settings.
Create Ansible group variables.
Create Ansible inventory variables in the YAML format.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command initializes the remote Git repository that you need for this lab.
When you are ready to push your changes to the remote repository, use Student@123 as the Git password.
[student@workstation ~]$ lab start review-cr1
All the computer systems have a student user account with student as the password.
The password for the root user account is redhat.
Specifications
Change an existing project that is stored in a Git repository:
The repository is stored at https://git.lab.example.com/student/review-cr1.git.
The repository must be cloned into the /home/student/git-repos/review-cr1 directory.
All your work must take place within the student/inventory-edits branch.
Git must be configured to not track or commit files with the .log file extension, or files in the project's .ssh/ and collections/ansible_collections/ directories.
Obtain a token from https://hub.lab.example.com, logging in as the student user with the password redhat123.
Set the token in ansible.cfg configuration file provided.
Configure Ansible and automation content navigator as follows:
Ansible must be configured to use the inventory/ directory by default.
Automation content navigator must use the ee-supported-rhel8:latest image as the default automation execution environment and must not generate any playbook artifact files.
Configure group variables:
The /home/student/git-repos/review-cr1/haproxy.yml playbook contains the lb_service and firewall_services defined variables.
To make this playbook more flexible, move these variables out of the playbook, and into the group_vars directory in the review-cr1 directory.
Configure inventory variables:
The /home/student/git-repos/review-cr1/webapp.yml playbook requires that the web_service and firewall_services variables be defined.
Create a group_vars/web/vars.yml file to define these variables for the web group with the following values:
| Variable | Value |
|---|---|
web_service
|
httpd
|
firewall_services
|
http and https
|
The /home/student/git-repos/review-cr1/db.yml playbook runs plays against the db group.
Add the db group to the existing inventory with the single host serverd.lab.example.com as a member.
This playbook requires that the db_service and db_port variables be defined.
Create a group_vars/db/vars.yml file to define these variables for the db group with the following values:
| Variable | Value |
|---|---|
db_service
|
mariadb
|
db_port
|
3306/tcp
|
After all the variables are defined, use automation content navigator to run the following playbooks:
/home/student/git-repos/review-cr1/haproxy.yml
/home/student/git-repos/review-cr1/webapp.yml
/home/student/git-repos/review-cr1/db.yml
Navigate to http://servera.lab.example.com to test the web application.
The web application displays This is the server server[bc] and the database is up.
After you confirm that the web application is running, commit and push your changes to the student/inventory-edits remote branch.
On the workstation machine, clone the https://git.lab.example.com/student/review-cr1.git repository into the /home/student/git-repos/review-cr1/ directory, and create a branch named student/inventory-edits.
Clone the repository to the /home/student/git-repos/review-cr1/ directory:
[student@workstation ~]$mkdir -p git-repos/review-cr1[student@workstation ~]$git clone \>https://git.lab.example.com/student/review-cr1.git \>/home/student/git-repos/review-cr1/
Change to the /home/student/git-repos/review-cr1/ directory.
Create a branch named student/inventory-edits and switch to it:
[student@workstation ~]$cd /home/student/git-repos/review-cr1/[student@workstation review-cr1]$git checkout -b student/inventory-edits[student@workstation review-cr1]$git statusOn branch student/inventory-edits nothing to commit, working tree clean
Configure Git to ignore any files with the .log file extension, and the .ssh/ and collections/ansible_collections/ directories.
Git should not track or commit these files or directories.
Create a /home/student/git-repos/review-cr1/.gitignore file with the following content:
*.log .ssh/ collections/ansible_collections
Retrieve a token from https://hub.lab.example.com, logging in as the student user with the password redhat123, and then use it to update the token option in the ansible.cfg file.
Use the ansible-galaxy command to install the collections.
The collections must be available to the execution environment, so they must be installed in the /home/student/git-repos/review-cr1/collections/ directory.
Log in to the private automation hub at https://hub.lab.example.com as the student user and using redhat123 as the password.
Navigate to → and then click . Copy the API token.
Using the copied token, update the token line in the ansible.cfg file.
Your token is probably different from the one that is displayed in this example.
...output omitted...
[galaxy_server.community_repo]
url=https://hub.lab.example.com/api/galaxy/content/community/
token=f41f07130d6eb6ef2ded63a574c161b509c647ddUse the ansible-galaxy command to install the community.mysql content collection into the collections/ directory.
[student@workstation review-cr1]$ansible-galaxy collection install \>-r collections/requirements.ymlStarting galaxy collection install process ...output omitted... Installing 'community.mysql:3.5.1' to '/home/student/git-repos/review-cr1/collections/ansible_collections/community/mysql' community.mysql:3.5.1 was installed successfully
Automation content navigator should use the ee-supported-rhel8:latest image as the default automation execution environment and should not generate playbook artifacts.
Create the /home/student/git-repos/review-cr1/ansible-navigator.yml file with the following content:
---
ansible-navigator:
execution-environment:
image: ee-supported-rhel8:latest
playbook-artifact:
enable: falseRemove the variables from the /home/student/git-repos/review-cr1/haproxy.yml playbook to make it more flexible.
Edit the /home/student/git-repos/review-cr1/haproxy.yml playbook and remove the vars: section.
The completed playbook should contain the following content:
---
- name: Deploy haproxy
hosts: haproxy
become: true
tasks:
...output omitted...Create the /home/student/git-repos/review-cr1/group_vars/{haproxy,web,db} directories:
[student@workstation review-cr1]$mkdir -p \>/home/student/git-repos/review-cr1/group_vars/{haproxy,web,db}
Create the /home/student/git-repos/review-cr1/group_vars/haproxy/vars.yml file and add the lb_service and firewall_services variables into it:
--- lb_service: haproxy firewall_services: - http - https
Create the /home/student/git-repos/review-cr1/group_vars/web/vars.yml file and add the web_service and firewall_services variables to it:
--- web_service: httpd firewall_services: - http - https
Create the /home/student/git-repos/review-cr1/group_vars/db/vars.yml file and add the db_service and db_port variables to it:
--- db_service: mariadb db_port: 3306/tcp
Add the db group to the /home/student/git-repos/review-cr1/inventory/inventory-static.yml inventory file with the single host serverd.lab.example.com:
web:
hosts:
serverb.lab.example.com:
serverc.lab.example.com:
db:
hosts:
serverd.lab.example.com:Use automation content navigator to run the playbooks.
Verify that automation content navigator is installed, and if not, install it.
[student@workstation review-cr1]$rpm -q ansible-navigatoransible-navigator-2.1.0-1.el8ap.noarch
You might need to install automation content navigator:
[student@workstation review-cr1]$sudo yum install ansible-navigator[sudo] password for student:student...output omitted...
The /home/student/git-repos/review-cr1/haproxy.yml playbook runs against the haproxy group that is defined in the /home/student/git-repos/review-cr1/inventory/inventory-dynamic.py dynamic inventory file.
This inventory file must have execute permissions before it can be used:
[student@workstation review-cr1]$ chmod 755 inventory/inventory-dynamic.pyUse the podman login command to log in to the private automation hub at hub.lab.example.com.
[student@workstation review-cr1]$podman login hub.lab.example.comUsername:studentPassword:redhat123Login Succeeded!
Run the /home/student/git-repos/review-cr1/haproxy.yml playbook:
[student@workstation review-cr1]$ ansible-navigator run -m stdout haproxy.yml
...output omitted...Run the /home/student/git-repos/review-cr1/webapp.yml playbook:
[student@workstation review-cr1]$ ansible-navigator run -m stdout webapp.yml
...output omitted...Run the /home/student/git-repos/review-cr1/db.yml playbooks:
[student@workstation review-cr1]$ ansible-navigator run -m stdout db.yml
...output omitted...Verify that the web application is up:
[student@workstation review-cr1]$curl http://servera.lab.example.comThis is the server serverc and the database is up [student@workstation review-cr1]$curl http://servera.lab.example.comThis is the server serverb and the database is up
Push your changes to the student/inventory-edits branch.
List all modified and untracked files:
[student@workstation review-cr1]$ git status
On branch student/inventory-edits
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: ansible.cfg
modified: haproxy.yml
modified: inventory/inventory-dynamic.py
modified: inventory/inventory-static.yml
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
ansible-navigator.yml
group_vars/
no changes added to commit (use "git add" and/or "git commit -a")Add the files you created and edited to the staging area:
[student@workstation review-cr1]$ git add --allCommit the staged files to the local repository:
[student@workstation review-cr1]$ git commit -m 'updating inventory'
...output omitted...Push the changes from the local repository to the student/inventory-edits branch on the remote repository.
If prompted, use Student@123 as the Git password.
[student@workstation review-cr1]$git push -u origin student/inventory-editsPassword for 'https://student@git.lab.example.com':Student@123...output omitted...
Verify that your changes were pushed to the student/inventory-edits branch:
[student@workstation review-cr1]$ git status
On branch student/inventory-edits
Your branch is up to date with 'origin/student/inventory-edits'.
nothing to commit, working tree clean