Understanding Configuration Management with Ansible

This is Day 55 of #90daysofdevops challenge

ยท

3 min read

Understanding Configuration Management with Ansible

What is 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)

  • First, create an EC2 instance and name it Master. This server is used as Ansible master server.

  • Now, login to the server and run this command sudo apt-add-repository ppa:ansible/ansible

  • Now install Ansible using the commands given below:
sudo apt update 
sudo apt install ansible

  • You can verify the installation by checking the Ansible version:
ansible --version

Task-02: Read more about the Hosts file

The Ansible hosts file, typically located at /etc/ansible/hosts, is a configuration file that defines the hosts or target machines where Ansible should execute tasks or playbooks. It specifies the IP addresses or hostnames of the remote machines and groups them logically so that you can manage them collectively.

  1. sudo nano /etc/ansible/hosts: This command opens the Ansible hosts file using the nano text editor with superuser privileges (sudo). You are editing the Ansible hosts file to define the inventory of target machines Ansible will work with.

  2. ansible-inventory --list -y: The ansible-inventory --list -y command displays all hosts and groups in your Ansible inventory in YAML format.

    This command is useful to:

    • Verify the structure of your inventory

    • Debug inventory issues

    • Share your inventory configuration with others

The --list option tells ansible-inventory to output all hosts info, just like an inventory script.

The -y option specifies that you want YAML output instead of the default JSON format.

Task-03: Multi-Node EC2 Instance Setup and Ansible Ping Test in a Distributed System Configuration

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

  • Let's create 2 more EC2 instances and name it Node-1 and Node-2

-> Copy the private key to master server where Ansible is setup

  • Simply use ssh-keygen in the Master as well as the Node server and copy the Master server id_rsa.pub which is a public key and paste it on authorized_keys in both the Node-1 and Node-2 servers.

  • Use vim authorized_keys to edit the file and paste the Master id_rsa.pub in it. Do it in both the Nodes.

  • After this check whether you can access Node-1 or Node-2 from the Master node. Simply use ssh (Node Private Ip address)

  • Now make an inventory file in the Master server and add the Private Ip address of both Node-1 and Node-2.

-> Try a ping command using ansible to the Nodes.

  • Now use the command given below to ping the nodes:
ansible -i inventory all -m ping

We can see both pings are successful which indicates servers are in active states.

"Thank you for enjoying my DevOps blog! Your positive response fuels my passion to dive deeper into technology and innovation.

Stay tuned for more captivating DevOps articles, where we'll explore this dynamic field together. Follow me on Hashnode and connect on LinkedIn (https://www.linkedin.com/in/som-shanker-pandey/) for the latest updates and discussions.

Did you find this article valuable?

Support Som Pandey's blog by becoming a sponsor. Any amount is appreciated!

ย