We already have an inventory file under /home/thor/ansible directory on jump host.
Write a playbook playbook.yml under /home/thor/ansible directory on jump host itself.
Using the playbook perform below given tasks:
Install httpd web server on all app servers, and make sure its service is up and running.
Create a file /var/www/html/index.html with content:
This is a Nautilus sample file, created using Ansible!
Using lineinfile Ansible module add some more content in /var/www/html/index.html file.
Below is the content:
Welcome to xFusionCorp Industries!
Also make sure this new line is added at the top of the file.
The /var/www/html/index.html fileâs user and group owner should be apache on all app servers.
The /var/www/html/index.html fileâs permissions should be 0755 on all app servers.
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.
[email protected]_host ~/ansible$ vim playbook.yml
-
name: install and start httpd on all app servers
hosts: all
remote_user: root
become: truetasks:
-
name: Install the latest version of Apache
ansible.builtin.package:
name:
- httpd
state: latest -
name: Start service httpd, if not started
ansible.builtin.service:
name: httpd
state: started -
name: Create index.html file and add line to file
ansible.builtin.lineinfile:
path: /var/www/html/index.html
line: âThis is a Nautilus sample file, created using Ansible!â
create: yes -
name: Update permissions of index.html
ansible.builtin.file:
path: /var/www/html/index.html
owner: apache
group: apache
mode: 0755 -
name: Append line of text to index.html and add new line before beginning of file
ansible.builtin.lineinfile:
path: /var/www/html/index.html
insertbefore: BOF
line: âWelcome to xFusionCorp Industries!â
-
[email protected]_host ~/ansible$
Below is the index.html content found on the target servers after running the playbook:
[[email protected] ~]# cat /var/www/html/index.html
Welcome to xFusionCorp Industries!
This is KodeKloud Ansible Lab !
This is a Nautilus sample file, created using Ansible!
[[email protected] ~]#
The problem:
Iâm not sure how the second line âThis is KodeKloud Ansible Lab !â is getting inserted into the index.html file based on the above playbook.