What's this Ansible?
Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intra-service 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.
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 host's 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 host file, you can use any text editor of your choice.
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 the same Private keys as the previous instance (Node)
Launch 2 new EC2 instances with the same private keys as ansible-server instance.
Copy the private key to the master server where Ansible is set up.
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 the 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 and also add a 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 means Ansible is ready to run commands on that node.
You can also use servers instead of all which is a group name.
I hope you find this article helpful!
Happy Learning!