One of the Nautilus DevOps team members is working on to develop a role for httpd installation and configuration. Work is almost completed, however there is a requirement to add a jinja2 template for index.html file. Additionally, the relevant task needs to be added inside the role. The inventory file ~/ansible/inventory is already present on jump host that can be used. Complete the task as per details mentioned below:
Update ~/ansible/playbook.yml playbook to run the httpd role on App Server 2.
Create a jinja2 template index.html.j2 under /home/thor/ansible/role/httpd/templates/ directory and add a line This file was created using Ansible on <respective server> (for example This file was created using Ansible on stapp01 in case of App Server 1). Also please make sure not to hard code the server name inside the template. Instead, use inventory_hostname variable to fetch the correct value.
Add a task inside /home/thor/ansible/role/httpd/tasks/main.yml to copy this template on App Server 2 under /var/www/html/index.html. Also make sure that /var/www/html/index.html file’s permissions are 0777.
The user/group owner of /var/www/html/index.html file must be respective sudo user of the server (for example tony in case of stapp01).
Note: Validation will try to run the playbook using command ansible-playbook -i inventory playbook.yml so please make sure the playbook works this way without passing any extra arguments.
Move into ansible directory and check each files
cd ansible
ls
cat inventory
cat playbook.yml
ls role
Create index.html.j2 file
vi role/httpd/templates/index.html.j2
copy paste the following line:
<p> This file was created using Ansible on </p>
Update main.yml of httpd role
vi role/httpd/tasks/main.yml
add these lines at the below:
- name: Copy index.html template
ansible.builtin.template:
src: index.html.j2
dest: /var/www/html/index.html
mode: '0777'
owner: ""
group: ""
Or you can replace all contents with this YAML file
Add target hosts in playbook.yml
hosts: all
playbook.ymlfile should be look like this:
---
- hosts: all
become: yes
become_user: root
roles:
- role/httpd
Run the playbook command:
ansible-playbook -i inventory playbook.yml
verify with curl
curl http://stapp01
curl http://stapp02
curl http://stapp03

Further check?
login into each app server and run this command
ls -la /var/www/html
[tony@stapp01 ~]$ ls -la /var/www/html
total 12
drwxr-xr-x 2 root root 4096 Oct 25 02:47 .
drwxr-xr-x 4 root root 4096 Oct 25 02:46 ..
-rwxrwxrwx 1 tony tony 57 Oct 25 02:47 index.html
[tony@stapp01 ~]$