Day 59: Ansible Project🛠🚀
✨✨Welcome back to build a Ansible project using Ansible Playbooks. In this blog , we will delve into Ansible how to efficiently structure and organize automation workflows using Ansible Projects.
Ansible playbooks are amazing, as you learned yesterday. What if you deploy a simple web app using Ansible? Sounds like a good project, right?
Task 1
create 3 EC2 instances . make sure all three are created with same key pair
- To create 3 EC2 instances, navigate to the EC2 service and launch them.
After you have created the 3 EC2 instances, designate one as the Ansible control node (ansible_master) and the other two as managed nodes (ansible_server).
Install Ansible only on Master node using following commands.
# Add ansible repository to your instance sudo apt-add-repository ppa:ansible/ansible # Update the package sudo apt update # Install the Ansible sudo apt install ansible
Once the installation is complete, check the version of Ansible using the following command:
Ansible --version
Access into .ssh directory ,there open private key (id_rsa)
Copy the Private Key and next, upload it from your local machine to the host server . Paste the private key into the host server's (.ssh directory), which is normally located at /home/ubuntu/.ssh.
Access Inventory file using
/etc/ansible/hosts.
Modify the inventory file to include the IP addresses of the servers, a list of hosts or servers, and the location of the private key file to be used for authentication.
[servers] host_1 ansible_host=52.39.126.158 host_2 ansible_host=35.89.144.134 [all:vars] ansible_python_interpreter=/usr/bin/python3 ansible_user=ubuntu ansible_ssh_private_key_file=/home/ubuntu/.ssh/ansible_key
-
Create a Playbook to install Nginx .
sudo vim install_nginx.yml
---
- name: Install and Start Nginx
hosts: servers
become: yes
tasks:
- name: Update apt
apt:
update_cache: yes
- name: Install Nginx
apt:
name: nginx
state: latest
- name: Start Nginx
service:
name: nginx
state: started
enabled: yes
Run the playbook using the following command
ansible-playbook install_nginx.yml
Check the status of Nginx on all the servers.
For deploying a static website, Create a new file index.html and add the file path in the playbook directory, and add some sample content in the index file.
Create sample webpage index.html on masternode.
<!DOCTYPE html> <html> <head> <title> chandana- DevOps Engineer</title> <style> body { font-family: Arial, sans-serif; background-color: yellow; color: #333; text-align: center; margin: 0; padding: 0; } h1 { color: #007BFF; } p { margin: 20px; } a { color: #007BFF; text-decoration: none; } a:hover { text-decoration: underline; } </style> </head> <body> <h1>Chandana - DevOps Engineer</h1> <p> I am highly skilled DevOps Engineer with over 3 years of experience in the field. With a strong background in supporting, automating, and optimizing deployments on AWS, I have successfully streamlined software development and delivery processes for various organizations. </p> <p> My expertise lies in leveraging configuration management tools, implementing CI/CD pipelines, and following DevOps best practices to ensure efficient and reliable software releases. I am well-versed in technologies such as Jenkins, Git, Linux, Ansible, and various AWS services, allowing me to design and implement robust DevOps solutions. </p> <p> If you are looking for a DevOps Engineer who can drive process optimization, enhance system scalability, and ensure seamless software delivery, please feel free to reach out. I am always eager to contribute my skills and expertise to help organizations achieve their goals. </p> <p> Let's connect and explore how we can work together to create efficient and robust DevOps solutions! </p> <p> LinkedIn: <a href="https://www.linkedin.com/in/chandana yantrapalli-54948a270/">linkedin.com/in/chandana yantrapalli-54948a270</a> </p> </body> </html>
Update the Ansible Playbook file , by adding index.html file path.
Once the playbook finishes executing, open a web browser and enter the public IP address of one of the running server.
Conclusion:
🔹In conclusion, the Ansible project is a versatile automation tool that has revolutionized the way infrastructure and application deployments are managed. Throughout the project, we have explored 🔎✨ various aspects of Ansible and its capabilities, highlighting its numerous benefits and practical applications.
🔹Ansible's extensive 💡 module library is a major strength. It offers a wide range of modules that can interact with various systems and services, from managing servers and networks to configuring databases and ☁☁cloud resources.
🔹Additionally, Ansible's support for orchestration and configuration management greatly simplifies scaling and managing large infrastructures. It enables the management of multiple servers or 🛠clusters in a coordinated and synchronized manner, reducing ⌛ manual effort and minimizing errors.
🔹Throughout this project🚀, we've learned valuable lessons about Ansible best practices, 📖playbook optimization, and integration with existing systems.
🔹Looking ahead, there are several areas we plan to explore🔎🔎 further. This includes expanding Ansible's role in managing additional infrastructure components, implementing more advanced 🛠automation workflows.
Thank you for 📖reading my blog, 👍Like it and share it 🔄 with your friends.
Happy learning😊😊
Subscribe to my newsletter
Read articles from Siri Chandana directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by