Day 55: Understanding Configuration Management with Ansible

Day 55: Understanding Configuration Management with Ansible

What's this Ansible?

Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning.

Task-01

Installation of Ansible on AWS EC2 (Master Node)

sudo apt-add-repository ppa:ansible/ansible

sudo apt update

sudo apt install ansible

Create an EC2 instance.

Connect to your EC2 instance using SSH.

Add the Ansible PPA repository using the following command:

sudo apt-add-repository ppa:ansible/ansible

Update the package using the following commands

Install Ansible using the following command:

sudo apt install ansible

Once the installation is complete, you can check the version of Ansible using the following command:

ansible --version

Task-02

Read more about Hosts file sudo nano /etc/ansible/hosts and ansible-inventory --list -y

The Ansible hosts file is a configuration file that contains a list of hosts or servers that Ansible can manage. The hosts file is located at /etc/ansible/hosts on the Ansible control node, and it is used to define the inventory of hosts that Ansible can manage.

To edit the hosts file, you can use any text editor of your choice.

sudo nano /etc/ansible/hosts

Once the file is open, you can add the IP addresses or hostnames of the servers you want to manage. The format for adding hosts is as follows:

[group_name] 
host1 
host2 
host3

In this example, group_name is a user-defined name for the group of hosts, and host1, host2, and host3 are the IP addresses or hostnames of the servers. You can define multiple groups of hosts in the hosts file, each with its own list of hosts.

After you have added the hosts to the file, you can verify the inventory of hosts that Ansible can manage using the ansible-inventory command with the --list and -y options:

ansible-inventory --list -y

This command will display a YAML-formatted list of hosts and their attributes, including the hostnames, IP addresses, and any other defined variables or group memberships.

Task-03

Setup 2 more EC2 instances with same Private keys as the previous instance (Node)

Launch 2 new EC2 instances with same private keys as ansible-demo-master instance.

Copy the private key to master server where Ansible is setup.

Copy private key from your local.

In master server where ansible is setup, create a new file at location /home/ubuntu/.ssh and paste private key to that file.

Give permissions to the key file using chmod command.

Create an inventory file for Ansible that lists the IP addresses of the two new EC2 instances, and specifies the private key file to use for authentication.

Create inventory file at location /etc/ansible/hosts which is by default location of file. Ansible hosts file is a configuration file that contains a list of hosts or servers.

Once the file is open, you can add the IP addresses of the servers also add private key file location to use for authentication.

After you have added the hosts to the file, you can verify the inventory of hosts that Ansible can manage using the ansible-inventory command.

ansible-inventory --list -y

Try a ping command using ansible to the Nodes.

To test that Ansible is able to connect to your nodes, you can use the following command:

ansible all -m ping

The ping module will test if you have valid credentials for connecting to the nodes defined in your inventory file. A pong reply back means Ansible is ready to run commands on that node.

You can also use servers instead of all which is a group name.

Thank you for reading!! I hope you find this article helpful!!

Happy Learning!!

Sayali✨

Did you find this article valuable?

Support Sayali Jadhav by becoming a sponsor. Any amount is appreciated!