In this exercise, you edit Ansible configuration files to customize your Ansible environment.
Outcomes
You should be able to create configuration files to configure your Ansible environment with persistent custom settings.
As the student user 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 playbook-manage
Procedure 2.2. Instructions
Change into the /home/student/playbook-manage directory.
[student@workstation ~]$ cd ~/playbook-manage
[student@workstation playbook-manage]$Configure automation content navigator.
Create the /home/student/playbook-manage/ansible-navigator.yml file.
Configure automation content navigator to use the execution environment image utility.lab.example.com/ee-supported-rhel8:latest and to only pull the image if it is missing.
Also configure automation content navigator to disable playbook artifacts.
The file should consist of the following content:
---
ansible-navigator:
execution-environment:
image: utility.lab.example.com/ee-supported-rhel8:latest
pull:
policy: missing
playbook-artifact:
enable: falseRun the ansible-navigator images command to list the available execution environment images.
[student@workstation playbook-manage]$ ansible-navigator images ---------------------------------------------------------------------------------- Execution environment image and pull policy overview ---------------------------------------------------------------------------------- Execution environment image name: utility.lab.example.com/ee-supported-rhel8:latest Execution environment image tag: latest Execution environment pull arguments: None Execution environment pull policy: missing Execution environment pull needed: True ---------------------------------------------------------------------------------- Updating the execution environment ...output omitted... Running the command: podman pull utility.lab.example.com/ee-supported-rhel8:latest Trying to pull utility.lab.example.com/ee-supported-rhel8:latest... ...output omitted...
After automation content navigator pulls the execution environment image you should see it in the list:
Image Tag Execution environment Created Size 0│ee-supported-rhel8 latest True 3 weeks ago 1.34 GB ^b/PgUp page up ^f/PgDn page down ↑↓ scroll esc back [0-9] goto :help help
Press Esc to exit the image list.
In your /home/student/playbook-manage directory, start editing a new file named ansible.cfg.
Create a [defaults] section in that file.
In that section, add a line that uses the inventory directive to specify the ./inventory file as the default inventory.
[defaults] inventory = ./inventory
Save your work and exit the text editor.
In the /home/student/playbook-manage directory, start editing the new static inventory file, inventory.
The static inventory should contain four host groups:
[myself] should contain the workstation host.
[intranetweb] should contain the servera.lab.example.com host.
[internetweb] should contain the serverb.lab.example.com host.
[web] must contain the intranetweb and internetweb host groups.
In /home/student/playbook-manage/inventory, create the myself host group by adding the following lines:
[myself] workstation
In /home/student/playbook-manage/inventory, create the intranetweb host group by adding the following lines:
[intranetweb] servera.lab.example.com
In /home/student/playbook-manage/inventory, create the internetweb host group by adding the following lines:
[internetweb] serverb.lab.example.com
In /home/student/playbook-manage/inventory, create the web host group by adding the following lines:
[web:children] intranetweb internetweb
The final inventory file should consist of the following content:
[myself] workstation [intranetweb] servera.lab.example.com [internetweb] serverb.lab.example.com [web:children] intranetweb internetweb
Save your work and exit the text editor.
Use the ansible-navigator command to run the provided playbooks and test the configuration of your inventory file's host groups.
The ansible-navigator run command runs an Ansible Playbook, formatted as a YAML file, that contains automation instructions to be run on managed hosts.
The following ansible-navigator commands use the configuration files that you edited in preceding steps.
Each of the following playbooks runs the ansible.builtin.ping module on a host or group of hosts to determine if they are ready to be used as managed hosts by Ansible.
These tests also validate whether your inventory file is correct.
Run the /home/student/playbook-manage/ping-myself.yml playbook to verify that the workstation machine is in the myself inventory group.
[student@workstation playbook-manage]$ansible-navigator run \>-m stdout ping-myself.ymlPLAY [Validate inventory hosts] ********************************************** TASK [Ping workstation] ****************************************************** ok: [workstation] PLAY RECAP *******************************************************************workstation: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Run the /home/student/playbook-manage/ping-intranetweb.yml playbook to verify that the servera.lab.example.com machine is in the intranetweb inventory group.
[student@workstation playbook-manage]$ansible-navigator run \>-m stdout ping-intranetweb.ymlPLAY [Validate inventory hosts] ********************************************** TASK [Ping intranetweb] ****************************************************** ok: [servera.lab.example.com] PLAY RECAP *******************************************************************servera.lab.example.com: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Run the /home/student/playbook-manage/ping-internetweb.yml playbook to verify that the serverb.lab.example.com machine is in the internetweb inventory group.
[student@workstation playbook-manage]$ansible-navigator run \>-m stdout ping-internetweb.ymlPLAY [Validate inventory hosts] ********************************************** TASK [Ping internetweb] ****************************************************** ok: [serverb.lab.example.com] PLAY RECAP *******************************************************************serverb.lab.example.com: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Run the /home/student/playbook-manage/ping-web.yml playbook to verify that the servera.lab.example.com and serverb.lab.example.com machines are in the web inventory group.
[student@workstation playbook-manage]$ansible-navigator run \>-m stdout ping-web.ymlPLAY [Validate inventory hosts] ********************************************** TASK [Ping web] ************************************************************** ok: [servera.lab.example.com] ok: [serverb.lab.example.com] PLAY RECAP *******************************************************************servera.lab.example.com: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0serverb.lab.example.com: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Run the /home/student/playbook-manage/ping-all.yml playbook to verify that the workstation, servera.lab.example.com, and serverb.lab.example.com machines are all in the inventory file.
[student@workstation playbook-manage]$ansible-navigator run \>-m stdout ping-all.ymlPLAY [Validate inventory hosts] ********************************************** TASK [Ping all] ************************************************************** ok: [serverb.lab.example.com] ok: [servera.lab.example.com] ok: [workstation] PLAY RECAP *******************************************************************servera.lab.example.com: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0serverb.lab.example.com: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0workstation: ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Open the /home/student/playbook-manage/ansible.cfg file in a text editor.
Add a [privilege_escalation] section to configure Ansible to automatically use the sudo command to switch from student to root when running tasks on the managed hosts.
Ansible should also be configured to prompt you for the password that student uses for the sudo command.
Create the [privilege_escalation] section in the /home/student/playbook-manage/ansible.cfg configuration file by adding the following entry:
[privilege_escalation]
Enable privilege escalation by setting the become directive to true.
become = true
Set the privilege escalation to use the sudo command by setting the become_method directive to sudo.
become_method = sudo
Set the privilege escalation user by setting the become_user directive to root.
become_user = root
Enable prompting for the privilege escalation password by setting the become_ask_pass directive to true.
become_ask_pass = true
The complete ansible.cfg file should consist of the following content:
[defaults] inventory = ./inventory [privilege_escalation] become = true become_method = sudo become_user = root become_ask_pass = true
Save your work and exit the text editor.
Use the ansible-navigator command to run the /home/student/playbook-manage/ping-intranetweb.yml playbook again to verify that you are now prompted for the sudo password.
When prompted for the sudo password, enter student.
[student@workstation playbook-manage]$ansible-navigator run \>-m stdout ping-intranetweb.ymlBECOME password:studentPLAY [Validate inventory hosts] ********************************************** TASK [Ping intranetweb] ****************************************************** ok: [servera.lab.example.com] PLAY RECAP ******************************************************************* servera.lab.example.com : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
This concludes the section.