What Is Ansible?
Ansible is an open-source software provisioning, configuration management, and application-deployment tool enabling infrastructure as code. It runs on many Unix-like systems, and can configure both Unix-like systems as well as Microsoft Windows. It includes its own declarative language to describe system configuration. Ansible was written by Michael DeHaan and acquired by Red Hat in 2015. Ansible is agentless, temporarily connecting remotely via SSH or Windows Remote Management (allowing remote PowerShell execution) to do its tasks.
In other words you can run one command on multiple servers and win time.
How to install Ansible in Ubuntu server?
# Update server
sudo apt-get update
sudo apt-get upgrade -y
# Install dependences
sudo apt-get install python -y
# Install repository
sudo apt-add-repository ppa:ansible/ansible
# Install ansible
sudo apt install ansible
Code language: Bash (bash)
How to add hosts to ansbile?
sudo nano /etc/ansible/hosts
/etc/ansible/hosts
[servers]
server1 ansible_host=10.20.0.2
server2 ansible_host=10.20.0.3
server3 ansible_host=10.20.0.4
[all:vars]
ansible_python_interpreter=/usr/bin/python3
Code language: JavaScript (javascript)
How to check added servers?
sudo ansible-inventory --list -y
Code language: PHP (php)
output
all:
children:
servers:
hosts:
server1:
ansible_host: 10.20.0.2
ansible_python_interpreter: /usr/bin/python3
server2:
ansible_host: 10.20.0.3
ansible_python_interpreter: /usr/bin/python3
server3:
ansible_host: 10.20.0.4
ansible_python_interpreter: /usr/bin/python3
ungrouped: {}
Code language: JavaScript (javascript)
How to test connection to the Ansible servers?
sudo ansible all -m ping -u root
output
server1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
server2 | SUCCESS => {
"changed": false,
"ping": "pong"
}
server3 | SUCCESS => {
"changed": false,
"ping": "pong"
}
Code language: JavaScript (javascript)
How to run a command to all servers?
sudo ansible all -a "df -h" -u root
Code language: JavaScript (javascript)
Conclusion
in conclusion we can say that ansible is a wonderful software for managing multiple Linux servers worldwide, extremely easy and accessible to work