Configuration Management using Ansible! 🤖🔗📚

Configuration Management using Ansible! 🤖🔗📚

·

5 min read

🌟 What is Ansible?

  • Ansible is a software tool that provides simple but powerful automation for cross-platform computer support. It is primarily intended for IT professionals, who use it for application deployment, updates on workstations and servers, cloud provisioning, configuration management, intra-service orchestration, and nearly anything a systems administrator does on a weekly or daily basis.

  • Ansible doesn't depend on agent software and has no additional security infrastructure, so it's easy to deploy.

🌟 How Ansible Works?

  • Ansible works by connecting to nodes (clients, servers, or whatever you're configuring) on a network, and then sending a small program called an Ansible module to that node. Ansible executes these modules over SSH and removes them when finished.

  • SSH keys are the most common way to provide access, but other forms of authentication are also supported.

🔱 Ansible Architecture: Nodes and Modules

  • Ansible's Architecture is based on the concept of a control node and a managed node. The platform is executed from the control node where a user runs the ansible-playbook command. There must be at least one control node; a backup control node can also exist. The devices being automated and managed by the control node are known as managed nodes.

  • Ansible automates Linux and Windows by connecting to managed nodes and pushing out small programs called Ansible modules. Ansible executes these modules, which are the resource models of the desired system state, over Secure Socket Shell (SSH) by default and removes them when finished.

  • Ansible modules are written in Python and can be written in any language. Ansible modules are reusable, standalone scripts that can be used by the Ansible API, Ansible Playbooks, or Ansible Galaxy.

🔱 Create 4 Instances on AWS EC2 with the following names:

  • Ansible_Master

  • Server_1

  • Server_2

  • Server_3


🌟Follow these steps to perform this project

🔱TASK 1: Create Ansible Master Server

✔Step 1: Go to AWS Console and search EC2

✔Step 2: Select your OS image and Instance Type

You just have to mention what is the name of your server (Ansible_Master), after that select the type of OS image and number of instances.

✔Step 3: Select your Instance type and Create a new Key-pair

Then go to the instance type and select t2.micro free tier eligible. After that select the key pair (login) or you can create a new pair.

✔Step 4: Configure your Network settings and Storage

The next step is the networking setting there is a firewall (security group), select create a security group provide the name of the security group and give a description. Configure the ebs volume storage.

🔱TASK 2: Create Ansible Node Servers

✔Step 1: Go to AWS Console and search EC2

✔Step 2: Select your OS image and Instance Type

You just have to mention what is the name of your server (Ansible_Master), and after that select the type of OS image and number of instances.

✔Step 3: Select your Instance type and Create a new Key-pair

Then go to the instance type and select t2.micro free tier eligible. After that select the key pair (login) or you can create a new pair.

✔Step 4: Configure your Network settings and Storage

The next step is the networking setting there is a firewall (security group), select create a security group and provide the name of the security group and give a description. Configure the ebs volume storage.

🔱TASK 3: Installing Ansible in Ansible Master Server

✔Step 1: SSH your Ansible Master EC2 Instance

✔Step 2: Install Ansible in the Master Server and Check the Version

  • Open Ansible_Master_Server and run the following commands or create a script for it:
#!/bin/bash
sudo apt-add-repository ppa:ansible/ansible
sudo apt update
sudo apt install ansible
  • Attach permissions to the script and run it:
sudo chmod 700 install.sh
sudo ./ansible_install.sh
  • Check the Ansible version

🔱TASK 4: SCP Private Key file for Node Servers

✔Step1: SCP Private Key file of Node Server to Ansible Master Server

I am using ansible-key.pem file for an ansible master server and node servers.

🔱TASK 5: Ansible Host files

✔ What is a Host file?

  • In the context of Ansible, a host file (also known as an inventory file) is a configuration file used to define and organize the list of target hosts that Ansible should manage.

✔ Where is the Host file located?

  • Ansible uses this file to map target hosts to managed nodes. The host's file is usually located in /etc/ansible/hosts.

  • So, open the host's file and add the IP addresses of the Nodes:

sudo vim /etc/ansible/hosts

✔Step1: Add Node Server IP Addresses

Let's add the Node IP addresses in the host's file:

[servers]
Server_1 ansible_host= <Public IP-Adddress of Node-1>
Server_2 ansible_host= <Public IP-Adddress of Node-2>

[servers:vars]
ansible_python_interpreter=/usr/bin/python3
ansible_ssh_private_key_file=/home/ubuntu/.ssh/id_rsa

✔Step2: Try a ping command using Ansible to the Nodes

We use the following commands to check connectivity between the master server and node servers.

ansible servers -m ping
# ansible is the command line utility used to interact with remote servers
# servers is a group name we created for node servers, shown above
# -m is the module
# ping is the name of module

✔Step3: Testing Linux commands (ad hoc commands)

We use the following commands to check the memory and disk space of remote servers.

ansible servers -a "free -h"

ansible servers -a "df -h"

We have Pinged Server_1, Server_2 and Server_3 from Ansible_Master.

\...................................................................................................................................................

The above information is up to my understanding. Suggestions are always welcome. Thanks for reading this article.😊

#aws #cloudcomputing #ansible #configurationmanagement #Devops #TrainWithShubham #90daysofdevops #happylearning

Follow for many such contents:

LinkedIn: linkedin.com/in/dushyant-kumar-dk

Blog: dushyantkumark.hashnode.dev

Â