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
Launch an EC2 Instance
Connect to Your EC2 Instance: Use an SSH client like ssh
to connect to your AWS EC2 instance
ssh -i your-key.pem ubuntu@your-instance-ip
Add the Ansible PPA (Personal Package Archive) to your instance
sudo apt-add-repository ppa:ansible/ansible
Update System Packages:
Install Ansible:
Verify Ansible Installation:
Task-02
- read more about Hosts file
sudo nano /etc/ansible/hosts ansible-inventory --list -y
Ansible Inventory File (/etc/ansible/hosts
):
The Ansible hosts file is a critical component that defines the hosts (machines or servers) that Ansible will manage. This file is used to specify inventory details, such as hostnames, IP addresses, connection details, and groups of hosts. The default location for the hosts file is usually /etc/ansible/hosts
, but you can use other files and directories as well.
The hosts file uses an INI-style format. Each host or group of hosts is specified under a section header, and the properties for each host are listed below the header.
Example:
[web_servers]
web1 ansible_host=192.168.1.101 ansible_user=ubuntu
web2 ansible_host=192.168.1.102 ansible_user=ubuntu
[db_servers]
db1 ansible_host=192.168.1.201 ansible_user=ubuntu
db2 ansible_host=192.168.1.202 ansible_user=ubuntu
In this example:
web_servers
anddb_servers
are group names.ansible_host
specifies the IP address of the host.ansible_user
specifies the SSH username used to connect to the host.
To List Inventory:
ansible-inventory --list -y
This command displays the entire inventory in YAML format. It can be useful to check if your inventory file is correctly configured and if Ansible is able to recognize the hosts.
Task-03
- Setup 2 more EC2 instances with same Private keys as the previous instance (Node)
- Copy the private key to master server where Ansible is setup
Then use then chmod
command to grant the crucial file permission
Use sudo vim /etc/ansible/hosts
to add the IP addresses of the servers and the location of the private key file to be used for authentication.
Use ansible-inventory --list -y
to check the list of hosts
- Try a ping command using ansible to the Nodes.