Ansible is configuration management and provisioning tool, quite similar to puppet or chef. It is a simple IT automation system that handles configuration-management, application deployment, cloud provisioning, multiple task execution and multi-node orchestration, including trivializing things like zero downtime rolling updates with load balancers.
These configuration management systems are used to act as a servers for administration and operation that allow you to control many different systems in an automated way from one central location. Thus, we can have a centralized server to control and configure all the client machines.
For IT personnels, tasks can be repetitive and exploiting same amount of resources over similar tasks is not a good way to go. With this automation tool, IT admins can automate their tasks and speedup their efforts. It uses simple, less complex way to begin with it. It uses SSH connection from server side to client side and no configuration is required to be done on the clients side. Automation and configuration management makes a lot of sense when it cuts down setup time and efforts.
Ansible Installation
Update your server and install software-properties-common package to work with PPA,
1 2 3 4 |
sudo su apt-get update apt-get install software-properties-common |
Add PPA repository,
1 |
apt-add-repository ppa:ansible/ansible |
Now, update the repository and install the package,
1 2 3 |
apt-get update apt-get install ansible |
Create SSH key pairs to let host communicates with clients using SSH connections,
1 |
ssh-keygen |
This will create RSA key pairs.
Now configure the hosts you want to control by ansible,
1 |
nano /etc/ansible/hosts |
1 2 3 4 5 6 |
# If you have multiple hosts following a pattern you can specify # them like this: [TESTING] host1 ansible_ssh_host=192.168.1.64 host2 ansible_ssh_host=192.168.1.10 |
You can allot group name to client’s IP addresses. Like’ TESTING’ is a group assigned to the above mentioned clients.
Close the hosts file.
Now mention the SSH user present on the client that you are accessing via SSH connection,
1 2 |
mkdir /etc/ansible/group_vars nano /etc/ansible/group_vars/TESTING |
Files should be in YAML format so it must begin with “—” ,
1 2 3 4 |
--- ansible_ssh_user: test |
Close the file.
Now the copy the ssh-key to the clients as,
1 2 3 |
ssh-copy-id test@192.168.1.64 ssh-copy-id test@192.168.1.10 |
Now check the connectivity with clients as,
1 |
ansible -m ping all |
If you get,
1 2 3 4 5 6 7 8 9 |
host1 | SUCCESS => { "changed": false, "ping": "pong" } host2 | SUCCESS => { "changed": false, "ping": "pong" } |
It also uses ad-hoc commands and playbooks (written in YAML format) for automation and provisioning. In our next blog, we will begin with writing playbooks and execution of ad-hoc commands.