Day 57: Ansible Hands-on with video


Task-01
Write a Blog explanation for the ansible video
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
Use the commands below to update the package.
sudo apt update
Install Ansible using the following command:
sudo apt install ansible
The following command can be used to determine the Ansible version after installation is complete:
ansible --version
Setup 2 more EC2 instances with the same Private keys as the previous instance (Node)
Using the same private keys as the ansible-demo-master instance, launch 2 new EC2 instances.
To install Ansible, copy the private key to the master server.
Copy the 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.
You can SSH into two new server instances from the master instance by using your private key.
- SSH into an ansible-server1 instance
sudo ssh -i /key-path ubuntu@public-ip-address
2. SSH into an ansible-server2 instance
Create an inventory file for Ansible that lists the IP addresses of the two new EC2 instances.
Create a new folder named Ansible. Inside the folder, create a host file, which is an inventory file for Ansible. add the IP addresses of the servers inside hosts file.
You can verify the inventory of hosts using the ansible-inventory command.
ansible-inventory --list -y -i <inventory-file-path>
Try sending a ping command using Ansible to the nodes.
The failure of the given authentication mechanism, most likely public key authentication, prevents Ansible from establishing an SSH connection to the remote host. also, Verify the remote host's private key file's permissions. Use the chmod command to grant the crucial file permissions.
Specify the private key file to use for authentication using the --private-key option when running the Ansible command.
ansible -i <inventory_file> all -m ping --private-key=<path_to_private_key>
<inventory_file> is the path to the inventory file.
<hosts> is the name or pattern of the host(s) that you want to ping.
<path_to_private_key> is the path to the private key file to use for authentication.
ansible command to check the free memory or memory usage of hosts:
-a "free -m": the -a option specifies the arguments to pass to the command to be executed on the remote hosts. In this case, the free -m command is executed to show the memory usage on each host.
ansible ad hoc command to check uptime
-a uptime: specifies the arguments to pass to the command module, which in this case is simply the uptime command.
I sincerely appreciate your patience as I begin to publish my first articles on the hashnode. Please contact me if you have any questions.
Subscribe to my newsletter
Read articles from Vinay Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
