Ansible is a Opensource, lightweight, powerful, and agentless solution for automation in IT infrastructure. Ansible assists you in automating and configuring your systems in order to save time and boost productivity.
Michael DeHaan, the founder of Cobbler and Func, initially developed Ansible in 2012.In 2015, RedHat, Inc. decided to buy the firm that sponsored Ansible. Because RedHat was acquired by IBM in 2019, Ansible is now part of the IBM family.
Ansible is a command-line tool that operates on Windows and Unix-like operating systems. Ansible is a agentless tool and it’s connect clients via SSH.
Lets Explore ansible functions.
Ansible’s typical use cases:
- System and network automation.
- Maintain virtual machines with the same configurations.
- For Ansible Graphic Interface use AWX (Free), Ansible tower.
- Useful for Application deployments.
Ansible Terms:
Ansible Server: The Ansible installed computer that executes all tasks and playbooks.
Host: Computers or virtual machines manage with ansible computer.
Play: Playbook execution.
Playbook: Automation task scripts written in YAML language.
Task: Command execution procedure.
Tag: Assign name to task.
Module: Clients side set off commands for execution.
Inventory: A file contains client-server data.
Fact: Gather operation information from client machine.
Installation Requirements:
Ansible server and Clients required Python Version 2.7 or 3.5 above.
For Windows Use WSL (Windows Subsystem for Linux) to use ansible as control node.
CentOS 7 : sudo yum -y install epel-repo
sudo yum -y update
sudo yum -y update
Ubuntu: sudo apt-add-repository ppa:ansible/ansible
sudo apt update
sudo apt install ansible
Setup Ansible Inventory file or Host(Client) configuration File:
Inventory File Location: /etc/ansible/hosts
The inventory file includes data about the hosts that Ansible will manage.
Sample File Screenshot:
We created dev and db groups with machine ip address. In Our case we use 2 client host machine.i.e.192.168.0.185 & 192.168.0.186 & User as root and password is root123.
IP ADDRESS > ansible_ssh_server=USER ansible_ssh_password=PASSWORD
Ansible server connect there clients/hosts through SSH protocol.
Lets try ansible command lines through terminal.
- Test Ansible Inventory/hosts with below command.
ansible-inventory –list -y
2. Test Inventory/Hosts connection using ansible ping module.Will use -u for user, without define -u in command will work same as below. Dont forget we already added user with password in inventory hosts file.
ansible all -m ping -u root
3. Lets Run Ad-Hoc commands to collect client machines status.
– Check 2 machines partition status with df -h command.
ansible all -a “df -h” -u root
4. Check system uptime with group name or by ip addresses.
We can Use single ip address or group name to get machine uptime status.
ansible 192.168.0.185 -a “uptime” -u root
OR
We can use group name or multiple ipaddress to check uptime, make sure machine ip address or group names separated by : (colon).
ansible 192.168.0.185:192.168.0.186 -a “uptime” -u root
OR
ansible 192.168.0.185:192.168.0.186 -a “uptime” -u root




