Ensure that your workstation is prepared to use Ansible and is configured with an appropriate configuration file and inventory, and use a provided playbook to ensure that several servers are in the correct configuration.
Outcomes
Install the ansible-navigator package.
Configure and use Ansible inventories and ansible.cfg files.
Confirm that Ansible is working correctly and can connect to managed hosts.
Run Ansible Playbooks to configure managed hosts.
As the student user on the workstation machine, use the lab command to prepare your environment for this exercise, and to ensure that all required resources are available.
[student@workstation ~]$ lab start ansible-review
Instructions
On the workstation machine, install the ansible-navigator package that provides automation content navigator, to use that machine as your control node.
Ensure that the execution environment container image is downloaded for the ansible-navigator tool.
You do not need to download the ee-supported-rhel9 execution environment, because it is preloaded in your classroom.
Use the ansible-navigator tool to list the container images.
[student@workstation ~]$ ansible-navigator imagesPress Esc to exit the image list.
Image Tag Execution environment Created Size 0│ee-supported-rhel9 latest True 4 months ago 1.63 GB ^b/PgUp page up ^f/PgDn page down ↑↓ scroll esc back [0-9] goto :help help
Create the /home/student/ansible-review directory.
Navigate to the /home/student/ansible-review directory.
In the /home/student/ansible-review directory, create an Ansible configuration file named ansible.cfg.
Use the following values.
| Section | Directive | Value |
|---|---|---|
| defaults | inventory | ./inventory |
| remote_user | ansible-labuser | |
| privilege_escalation | become | true |
| become_method | sudo | |
| become_user | root | |
| become_ask_pass | false |
In the /home/student/ansible-review directory, create the inventory file.
Use the following values.
| Group | Host |
|---|---|
| prod | servera |
| serverb | |
| test | workstation |
| webserver:children | prod |
| test |
List all the managed hosts that are present in the inventory.
In the /home/student/ansible-review directory, create an Ansible Playbook file named webserver.yml.
The playbook acts on all hosts in the prod host group.
Create the following tasks:
Install the httpd package.
Start the firewalld service.
Create the index.html file with some content.
Use the firewalld Ansible module to enable the http service.
Start the httpd service.
[student@workstation ansible-review]$ cat webserver.yml
---
- name: Start a webserver
hosts: prod
tasks:
- name: Install httpd package
yum:
name: httpd
state: present
- name: Start firewalld service
service:
name: firewalld
state: started
enabled: true
- name: Copy content
copy:
content: "Welcome to RH415 webserver\n"
dest: /var/www/html/index.html
- name: Add http service to firewalld
firewalld:
service: http
state: enabled
immediate: true
permanent: true
- name: Start httpd service
service:
name: httpd
state: started
enabled: true
...Before running your playbook, validate the webserver.yml playbook syntax.
Correct any reported errors before continuing.
Run the webserver.yml playbook.
Read through the generated output to ensure that all tasks completed successfully.
[student@workstation ansible-review]$ansible-navigator run -m stdout \ webserver.ymlPLAY [Start a webserver] ******************************************************* TASK [Gathering Facts] ********************************************************* ok: [serverb] ok: [servera] TASK [Install httpd package] *************************************************** changed: [serverb] changed: [servera] TASK [Start firewalld service] ************************************************* ok: [serverb] ok: [servera] TASK [Copy content] ************************************************************ changed: [serverb] changed: [servera] TASK [Add http service to firewalld] ******************************************* changed: [serverb] changed: [servera] TASK [Start httpd service] ***************************************************** changed: [serverb] changed: [servera] PLAY RECAP ********************************************************************* servera : ok=6changed=4unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 serverb : ok=6changed=4unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Use the curl command to verify that both servera.lab.example.com and serverb.lab.example.com are configured as HTTPD servers.