Ansible Playbooks and Project.

ยท

3 min read

What is Ansible Playbooks?

An Ansible playbook orchestrates a series of tasks, roles, configurations, deployment steps, and variables. When dealing with multiple servers, playbooks streamline the process, orchestrating tasks across assembled machines, ensuring they operate as intended by users. Think of playbooks as comprehensive instruction manuals for orchestrating and managing server activities

Task-01

  • Write an ansible playbook to create a file on a different server.

Solution:

Step 1: Create an Ansible playbook to create a file on a different server

Step 2: Lets trigger playbook with below synatx.

ansible playbook <playbook .YML file name> -i <Hostfile path>

We can see with the help of playbook we are able to create file on 2 server with one command.

Step 3: verify the file existence with help below command

  • Write an ansible playbook to create a new user.

Solution:

Step 1: Create playbook .yml file for create new user task.

Step 2: trigger the playbook.

Step 3: We can verify user using /etc/group file

  • Write an ansible playbook to install java-17 on a group of servers

Solution

Step 1:Lets write an ansible playbook.yml file for the same

Step 2: trigger the playbook.

Step 3: verify installation using version command.

Ansible Project ๐Ÿ”ฅ

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-01

  • create 3 EC2 instances . make sure all three are created with same key pair

  • Install Ansible in host server

  • copy the private key from local to Host server (Ansible_host) at (/home/ubuntu/.ssh)

  • access the inventory file using sudo vim /etc/ansible/hosts

  • Create a playbook to install Nginx

  • deploy a sample webpage using the ansible playbook

Solution:

Step 1: Created 3 ec2 instance with same key pair for Ansible-master.

Step 2: install ansible on master node.

Step 3: verify installation.

step 4: copy private key from local to ansible master.

Created empty folder on ansible-master to to copy the private key.

Using SCP we copying the pem file from local to Ansible-master

Step 5: access the inventory file using sudo vim /etc/ansible/hosts and add entry to all hosts.

Listed all three server here with private key location.

Step 6: Create a playbook to install Nginx. and trigger the playbook.

Step 7: we can verify nginx install with 2 way.

Step 8 : Lets create custom index.html page and save it in playbook folder and integrate in playbook.yml file for deployoment.

Step 9: trigger the playbook and check custom webpage using public-ip:80 on web browser.

Lets verify the custom web page using public-ip instace:80

  1. Server1:

    Server2:

    Server3:

I hope this article will assist you in comprehending the process of crafting an Ansible playbook and successfully executing it.

Thanks for reading..!

Thanks,

Kishor Chavan

ย