In this lab, you configure and perform administrative tasks on managed hosts using a playbook.
Outcomes
You should be able to construct and run an Ansible Playbook to install, configure, and verify the status of web and database services on a managed host.
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-review
The /home/student/playbook-review working directory has been created on the workstation machine for the Ansible project.
The directory has already been populated with an ansible.cfg configuration file and an inventory file.
The managed host, serverb.lab.example.com, is already defined in this inventory file.
Procedure 2.5. Instructions
Change into the /home/student/playbook-review directory and create a new playbook called internet.yml.
Add the necessary entries to start a first play named Enable internet services and specify its intended managed host, serverb.lab.example.com.
Add the necessary entry to enable privilege escalation, and one to start a task list.
Add the following entry to the beginning of the /home/student/playbook-review/internet.yml file to begin the YAML format.
---
Add the following entry to denote the start of a play named Enable internet services.
- name: Enable internet services
Add the following entry to indicate that the play applies to the serverb.lab.example.com managed host.
Make sure that the beginning of the entry is indented two spaces.
hosts: serverb.lab.example.com
Add the following entry to enable privilege escalation. Indent the beginning of the entry two spaces.
become: true
Add the following entry to define the beginning of the tasks list.
Indent the beginning of the entry two spaces.
tasks:
Add the necessary entries to the /home/student/playbook-review/internet.yml file to define a task that installs the latest versions of the firewalld, httpd, mariadb-server, php, and php-mysqlnd packages.
Indent the beginning of the entry four spaces.
Add the necessary entries to the /home/student/playbook-review/internet.yml file to define the firewall configuration tasks.
They should ensure that the firewalld service is enabled and running, and that access is allowed to the http service.
Indent the beginning of these entries four spaces.
Add the necessary entries to ensure the httpd and mariadb services are enabled and running.
Indent the beginning of these entries four spaces.
Add the necessary entry that uses the ansible.builtin.copy module to copy the /home/student/playbook-review/index.php file to the /var/www/html/ directory on the managed host.
Ensure the file mode is set to 0644.
Indent the beginning of these entries four spaces.
Define another play in the /home/student/playbook-review/internet.yml file for a task to be performed on the control node.
This play tests access to the web server that should be running on the serverb.lab.example.com managed host.
This play does not require privilege escalation, and runs on the workstation.lab.example.com managed host.
Add the following entry to denote the start of a second play named Test internet web server.
- name: Test internet web server
Add the following entry to indicate that the play applies to the workstation managed host.
Indent the beginning of the entry two spaces.
hosts: workstation
Add the following entry after the hosts keyword to disable privilege escalation for the second play.
Indent the beginning of the entry two spaces.
become: false
Add the following entry to the /home/student/playbook-review/internet.yml file to define the beginning of the tasks list.
Indent the beginning of the entry two spaces.
tasks:
Add the necessary entry that tests the web service running on serverb from the control node using the ansible.builtin.uri module.
Look for a return status code of 200.
Indent the beginning of the entry four spaces.
Validate the syntax of the internet.yml playbook.
Use the ansible-navigator run command to run the playbook.
Read through the generated output to ensure that all tasks completed successfully.
[student@workstation playbook-review]$ansible-navigator run \>-m stdout internet.ymlPLAY [Enable internet services] ************************************************ TASK [Gathering Facts] ********************************************************* ok: [serverb.lab.example.com] TASK [Latest version of all required packages installed] *********************** changed: [serverb.lab.example.com] TASK [firewalld enabled and running] ******************************************* ok: [serverb.lab.example.com] TASK [firewalld permits http service] ****************************************** changed: [serverb.lab.example.com] TASK [httpd enabled and running] *********************************************** changed: [serverb.lab.example.com] TASK [mariadb enabled and running] ********************************************* changed: [serverb.lab.example.com] TASK [Test php page is installed] ************************************************* changed: [serverb.lab.example.com] PLAY [Test internet web server] ************************************************ TASK [Gathering Facts] ********************************************************* ok: [workstation] TASK [Connect to internet web server] ****************************************** ok: [workstation] PLAY RECAP ********************************************************************* serverb.lab.example.com : ok=7 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 workstation : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
This concludes the section.