Installation of ansible and How to write playbook.

Installation of ansible and How to write playbook.

·

3 min read

In this article, we have configured Ansible on the system step by step.

Ansible is an open-source automation tool and it is also used for creating infrastructure or configuration management.

Step -1 First, you have to create a server on your system using a virtual machine or you can use Amazon web services I am using AWS for this.

You have to create a server to install ansibe master. I have used the Ubuntu server to install ansible master.

This is my ansible master in aws.

In this, I have downloaded a private key and using this private key I have ssh this server and after that, you have to first configure ansible master to connect the worker node.

Step-2

Connect your system to the AWS server using SSH for the installation of Ansible on the master node. you can also connect to the server using a web browser in AWS by using AWS instance connect.

Connect to the server open the terminal and run this command on your terminal.

sudo apt-add-repository ppa:ansible/ansible

This command collects all required files that are required to install Ansible.

sudo apt update

Update the system and install all required files for Ansible.

sudo apt install ansible

This command is installable in the system.

To check Ansible is installed in your system you have to check this path.

cat /etc/ansible/hosts

if this command is run then you have successfully installed ansible master and know you have to connect your worker node with the master node

Step -3

create your worker node on AWS using GUI. After creating the worker node you have to mention your worker IP address in the ansible matser host file.

In host file we can create a group of server use square bracket to denote them and inside this mention the name of group in this example I have servers. server{1..3} is server name and ansible_host is variable name.

Check connectivity between master node to worker node is connected we can use ping command and if connection is successful then output is look like this.

ansible servers -m ping.

Now we use add hock command and add hock command great for task s you repeat rarely.

ansible servers -a "free -h"

Some more example of add hock command.

ansible servers -a "df -h"

ansible servers -a "last"

ansible servers -a "top -h"

Now we move to playbook in ansible.

We can write first playbook

this playbook is show the date of each server here is the yaml file for date playbook script. the out of this play is look like this.

Write second playbook for update each server.

Output of above playbook is below.

Now we can deploy a static website sing ansible. first write playbook for this deploy satatic webpage.

In this we create three different server 1) test server 2) dev sever 3) prod server

In this we deploy static website on development server(dev).

Now nginx is run development server and we are reddy to deploy web page using nginx server

Now we have deploy static web page on nginx server.

On next blog I will explain how to configure nginx and deploy website which is running on docker container and also use route for webste.

if you like this blog pleases like this and share it.