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
Update the package using the following commands
Install Ansible using the following command:
Once the installation is complete, you can check the version of Ansible
Launch 2 new EC2 instances with same private key as ansible-master EC2 instance.
Copy the private key to master server where Ansible is setup.
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 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
Create an inventory file for Ansible that lists the IP addresses of the two new EC2 instances.
Create a new folder named ansible, inside folder create hosts file which is 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 a ping command using ansible to the Nodes.
This error message indicates that Ansible was unable to connect to the remote host using SSH, because the authentication method specified (likely public key authentication) failed. also Check the permissions on the remote host's private key file
Give permissions to the key file using chmod command.
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.
Thank you for reading!!I hope you find this article useful!
Happy Learning!!
Sayali✨