Installation on Linux(ubuntu):
Mainly, there are two types of machines for deployment in ansible’s case
- Master machine − Machine from where we can manage other machine
- Remote machines − Machines which are handled/controlled by control machines.
Master Machine Requirements
Ansible:Python 2 (versions 2.6 or 2.7) or Python 3 (versions 3.5 and higher) are used to run Ansible programs.
Note − Windows does not support master machines.
By default, Ansible uses ssh to manage remote machines.
Ansible does not add any database. There are no daemons thread required to start and keep it running. whereas managing remote machines, Ansible doesn’t leave any software package put in or running on them. So, this makes ansible to upgrade easily.
Installation through Apt on Ubuntu Machine
sudo apt-get update -y && sudo apt-get install ansible -y
After running the above line of code, you are ready to manage remote machines/servers through Ansible. Just run Ansible –version to check the installed version of ansible as well as just to check whether Ansible was installed properly or not.
Configuring master and remote machine in Ansible
For configuring your master and remote machine follow the steps mentioned below:-
1) ssh to your master machine and go to your .ssh directory
Here look for the public key i.e. id_rsa.pub, if it is not there then create a new public key using
Once you execute the above command press enter, it will create a public key with name id_rsa.pub
2) Now copy the content of your id_rsa.pub key of your master server
3) Now ssh into your remote server and move to .ssh directory of your remote server
4) Here you will find a file with name authorized_keys
5) Open this file and paste the content of your master public key that you have copied in step 2
6) Save the changes
7) Now go to your master server and edit the host file mentioned in /etc/ansible directory
sudo nano /etc/ansible/hosts
Uncomment the web server part and enter the ip of your remote server
NOTE:- IF you want then you can create another group like web servers as it is created, we will be installing apache2 in this demo so i have uncommented web server group and entered my remote server ip
Save your configuration and to exit from nano press CTRL+X and Y and press enter
8) Now execute
ansible all -m ping
The above command is used to check connectivity, after executing it you should receive a ping-pong response, if prompts for adding hosts type YES and hit enter
9) Now execute the below ad hoc command to install apache2,
ansible all -m apt -a "name=apache2 state=latest" -b
As you can see it has started the installation process, once it is done just copy the ip of your remote server and paste it in browser, you should see apache2 page