Table of contents
Hello everyone Welcome to the new blog. This blog is a written explanation for the below video. Although we have already done some of the tasks in our earlier challenge but for the sake of completion we will do those tasks again.
Task-01
Write an explanation for this Ansible video
Create an EC2 instance and SSH into its terminal.
Install Ansible on it using the following commands:
sudo apt-add-repository ppa:ansible/ansible
sudo apt update
sudo apt install ansible
#check the version using
ansible --version
Launch 2 new EC2 instances using the same key that we used earlier.
Now in the server where we had installed Ansible, let's copy the key file inside the /.ssh folder so that we can ssh into our other servers right from our master server.
Let's check if it has been copied
You can SSH into 2 new server instances from master instance by using private key.
- SSH into ansible-server1 instance
sudo ssh -i /key-path ubuntu@public-ip-address
2. SSH into ansible-server2 instance
Generate an inventory file tailored for Ansible, outlining the IP addresses of the two fresh EC2 instances.
Inside a newly crafted "ansible" folder, fashion a file named "hosts" that functions as Ansible's inventory file. Populate this file with the IP addresses of the servers.
To validate the host inventory, employ the "ansible-inventory" command. Execute the following:
ansible-inventory --list -y -i <inventory-file-path>
Experiment with an Ansible ping command directed at the nodes.
If confronted with an error message, it implies that Ansible encountered an issue connecting to the remote host through SSH, likely due to authentication failure, such as public key authentication. Scrutinize the permissions on the remote host's private key file and rectify them using the "chmod" command.
Specify the private key file for authentication using the "--private-key" option when executing the Ansible command. Utilize the following template:
ansible -i <inventory_file> all -m ping --private-key=<path_to_private_key>
Here:
<inventory_file>
corresponds to the path of the inventory file.<hosts>
denotes the name or pattern of the host(s) designated for pinging.<path_to_private_key>
designates the path to the private key file for authentication.
For an Ansible command unveiling the free memory or memory usage of hosts, use the following structure:
ansible -i <inventory_file> all -a "free -m"
In this command:
- The
-a
option defines the arguments for the command executed on the remote hosts, in this case, the "free -m" command showcasing memory usage.
For a swift ad hoc check of uptime, use the following Ansible command:
ansible -i <inventory_file> all -a uptime
Here, the -a
option specifies the arguments for the command module, with "uptime" being the chosen command for execution.
Thankyou for reading until here. Hope you have found it worthwhile.