Ansible is powerful automation and configuration management tool written in python. Ansible does by default communicate with machines over the SSH protocol, Ansible is agent free, does not require any additional agent/daemons to be installed on remote machines. You will have to setup playbook to execute multiple commands for a deployment/configuration written in YAML format.
Ansible upholds four months short release cycles to tackle all minor bugs. Major bugs will still have maintenance releases whenever needed.
Prerequisites : Ansible can be run from any machine with Python 2.6 or 2.7
Operating System: RHELx, CentOS, Fedora, Debian, Ubuntu and BSD.
Step #1: Add the EPEL Repository
Ansible is part of EPEL community repository for non-standard packages, we need to first setup the EPEL repository om CentOS7.
Once EPEL repo installation is completed, run makecache command to download all the metadata for the enabled yum repos.
Step #2: Update OS
Running yum update on all nodes to ensure all installed packages are up to date. While updating packages, yum will ensure that all dependencies are also installed.
- yum update -y
Step #3 : ssh key deployment across all hosts
Generate authentication keys for ssh using ssh-keygen. -t option reflects the type of key to be generated rsa/dsa/ecdsa.
ssh-copy-id command logs into the remote machine with password to enable key based authentication.
[root@ansible-master ~]# ssh-copy-id -i .ssh/id_dsa.pub ansible-master
Step #4 : Add all nodes into /etc/hosts
Edit the /etc/hosts file, This file is a simple text file containing IP addresses with hostnames, one line per IP address.
Step #5 : Installing Ansible
While making ansible installation with yum, it does resolve all dependencies of python
- [root@ansible-master ~]# yum install ansible -y
Step #6 : How to Check Ansible version
[root@ansible-master ~]# ansible –version
Step #7 : Add remote host in Ansible inventory (/etc/ansible/hosts) file.
Edit the /etc/ansible/hosts file to declare the nodes or servers inventory of Ansible.
The format for /etc/ansible/hosts file is an INI-like format. Object mentioned in brackets are group names, deciding what systems you are controlling for what objective.
it’s fine to define hosts in more than one group, for instance a server part of both a webservers and a dbservers
Step #8 : Run the commands from Ansible.
[root@ansible-master ~]# ansible all -a “/bin/echo hello”
[root@ansible-master ~]# ansible -m ping dbservers,application
[root@ansible-master ~]# ansible -m command -a ‘uptime’ dbservers,application
[root@ansible-master ~]# ansible -m command -a ‘cat /etc/redhat-release’ dbservers,application