Day 57 of #90DaysOfDevOps
Task: Write a Blog explanation for this ansible video
Questionaries:
What is Ansible?
Ansible is a configuration management tool.
For example, install Ansible on a server and provide IP addresses, local Python installation directory, and SSH key of those IP addresses and it can do everything on those servers by using the Ansible installed server like installing any tool (docker, nginx etc.), checking uptime of the servers etc.
In short, one master server can control the configurations of many servers.
The scripts in Ansible are called playbooks.
What are the benefits of Anisble?
One master server can control the configurations of many servers.
Ansible is agentless and it communicates through SSH.
Ansible is lightweight.
Ansible is automation-friendly.
Which scripting language does Ansible use?
- Ansible uses YAML for scripting.
Which management technique does Ansible work on?
- Ansible works on the PUSH management technique.
Explain important terms of Ansible.
Ansible Server - The machine where Ansible is installed. Playbooks can be run here.
Module - Command or set of commands to be executed client side.
Inventory - It is a file containing data about client servers.
Play - Execution of a playbook.
Ad Hoc commands - Can be performed individually to perform a quick function.
Default inventory file location - /etc/ansible/hosts
How to install Ansible on an AWS instance?
Launch an instance with any Linux OS. I am using the Ubuntu Server and free tier configuration.
-
Create a new key pair and security group (with access to http, https, ssh), and click on Launch.
-
Connect to the instance.
-
After connecting, run
sudo apt-add-repository ppa:ansible/ansible
-
Then update the system and install Ansible with the command:
sudo apt update && sudo apt install ansible -y
-
Verify installation with
ansible --version
-
Ansible has been installed on the instance successfully.
How to connect and ping Ansible with other servers?
Create 3 more servers with the same configuration as the master just like above.
-
Copy the key pair file data and paste it on the master server at path /home/ubuntu/.ssh with the file extension .pem
-
Change the access of the file to 600 by entering the command:
sudo chmod 600 ansible-master.pem
. It will be open to use by Ansible. Go back to the home directory.
On the master server, create an inventory file and enter the IP of the other servers, providing a local Python directory.
You can refer to this link to create inventory.
-
Verify by writing the command:
ansible-inventory --list -i /home/ubuntu/ --yaml
Configuration is completed, now you can ping the servers group with ad hoc command.
ansible servers -m ping -i servers_list.yaml --private-key /home/ubuntu/.ssh/ansible-master.pem
-
To get to know more about the ad hoc commands refer to these links:
Ping has been successfully done!
How to check the memory (RAM) usage of the other servers?
Enter
ansible -a "free -h" servers -i servers_list.yaml --private-key /home/ubuntu/.ssh/ansible-master.pem
How to check other servers' uptime?
Enter the command:
ansible -a "uptime" servers -i servers_list.yaml --private-key /home/ubuntu/.ssh/ansible-master.pem
Thank you for reading!