About this Project
This Ansible Real-Time Project is specifically designed to bridge the gap between theoretical learning and practical DevOps application. By following this guide, you will gain hands-on experience in automating server configurations, a core requirement for any modern infrastructure role. Whether you are building your portfolio or preparing for a job interview, completing this Ansible Real-Time Project will give you the confidence to manage complex automation tasks in a professional environment.
Table of Contents
Prerequisites For Ansible Real-Time Project:
Install 3 Linux machine:
Ansible Control node: vm1.example.com
Host node: vm2.example.com
vm3.example.com
Setup Ansible Host machines:
Login both Remote hosts one by one and create user devops on both machine and add user in sudorus file.
adduser usermod -aG sudo devops
visudo
# Add following line in visudo file to Configure Passwordless Sudo For A Specific User in Linux
devops ALL=(ALL) NOPASSWD:ALL
Setup Ansible Controller machine:
-> Login to the Control node vm1.example.com and Check Ansible version by command ansible –version .
-> Now generate ssh key and copy ssh pub key on both remote hosts with following commands.
ssh-keygen
ssh-copy-id devops@192.168.56.12
ssh-copy-id devops@192.168.56.13
-> Now create a directory name ansible_lab and move to this directory.
mkdir ansible_lab
cd ansible_lab
-> Now create ansible.cfg configuration file and add all necessary entry under defaults and privilege_escalation
[defaults]
inventory = inventory
remote_user = devops
ask_pass = false
[privilege_escalation]
become = yes
become_method = sudo
become_user = root
become_ask_pass = false
Making connection between Controller and Hosts:
As already i have copied ssh pub key so now control node can connect to Remote hosts as password less authentication.
Adding host in Inventory and playbook file on Controller:
vagrant@vm1:~/ansible/inventory$ cat inventory
[webserver]
vm2.example.com
vm3.example.comPlaybook:
—
– name: Enable internet services
hosts: vm2.example.com
become: yes
tasks:
– name: installs the latest versions of firewalld, apach2, mariadb-server, php, and php-mysqlnd packages
apt:
name:
– firewalld
– apach2
– mariadb-server
– php
– php-mysqlnd
state: latest
– name: firewalld service is enabled and running
service:
name: firewalld
enabled: true
state: started
– name: Allow port 80
firewalld:
service: http
permanent: true
state: enabled
immediate: yes
– name: apach2 and mariadb services are enabled and running
service:
name:
– apache2
– mariadb
enabled: true
state: started
– name: Use the copy module to copy index.php file to /var/www/html/ on the managed host
copy:
src: index.php
dest: /var/www/html/index.php
– name: Remove html.index file from Control node to Remote host
file:
paht: /var/www/html/index.html
state: absent
– name: Test internet web server
hosts: vm3.example.com
become: yes
tasks:
– name: connect to internet web server from vm3.example.com
uri:
url: http://192.168.56.12
status_code: 200
Architecture of Ansible Project:

Install Apach2, php , mariadb on vm2 node to run apache web service:
- Create a new playbook, /home/vagrant/
ansible_lab/internet.yml, and add the necessary entries to start a first play named Enable internet services and specify its intended managed host, vm2.example.com. Add an entry to enable privilege escalation, and one to start a task list.
Add the required entries to the /home/vagrant/ansible_lab/internet.yml file to define a task that installs the latest versions of firewalld, apach2, mariadb-server, php, and php-mysqlnd packages.
Add the necessary entries to the /home/vagrant/ansible-lab/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 apach2 service.
Add the necessary tasks to ensure the apach2 and mariadb services are enabled and running.
Add the necessary entries to define the final task for generating web content for testing. Use the copy module to copy index.php file to /var/www/html/ on the managed host.
- Add the necessary entries to define a task to remove default index.html file from Managed host.
In /home/vagrant/ansible_lab/internet.yml, define another play for the task to be performed on the vm3.example.com. This play will test access to the web server that should be running on the vm3.example.com managed host using the uri module. Check for a return status code of 200.
Verify the syntax of the internet.yml playbook.
Use the ansible-playbook command to run the playbook. Read through the output generated to ensure that all tasks completed successfully.
Conclusion:
Completing this Ansible Real-Time Project is a major milestone in your journey to becoming a DevOps professional. By moving from manual tasks to automated playbooks, you have learned how to maintain consistency, reduce human error, and scale infrastructure efficiently.
Remember, the key to mastering any Ansible Real-Time Project is consistent practice. I encourage you to take the code from this tutorial and modify it—add more servers, try different modules, or integrate it with a CI/CD pipeline.
You can also visit Ansible official website https://docs.ansible.com/ to work on some advanced level real time project.
You can also visit my Ansible blog https://linuxgktech.com/ansible/ to know more about ansible.
