Ansible :

Ansible is a configuration tool or automation tool.

Ansible is a push mechanism

docs.ansible.com


Terraform is used to build instances in azure/aws

Instead of manually creating a machine, we can use terraform to build the machine by entering the codes.

Terraform can be used only in cloud deployments.

Terraform is like a civil engineer who build the servers.

Ansible is like a interior designer who make the installation on servers on both onpremise/cloud.

Ansible can make changes to the server configuration as well.

Ansible/puppet/chef/salt all are same configuration tool only.

For an example if you want to deploy java on multiple servers, you can use master slave concept and deploy them.

You need to install the ansible on the master server.


Example to use ansible, it is same like how we use for dockers, git.


Git <commands>

docker <commands>

Ansible <commands>

Ansible -> you can use linux command cli

Chef/puppet -> you need to know some scripts like ruby/groovy.

Avoid using name master/slave

Instead use control node / Managed nodes


Prerequisites to install ansible, you need to have python installed on the machine

On top of it, you need to install the ansible, because ansible is written in python language.

Windows is not supported for the control node.

Only linux machine can be used as control node.

Managed machines can be Windows or linux, but also as the prerequisites you need to have python in all managed nodes.

If you want to change port on all machine, you can do it from control node

if you want to run top command in all machine, you can do it from control node and get the results.


How ssh work and based on which algorithm


SSH works with public and private key pairs

SSH works behind RSA encryption algorithm

If one machine wants to send file to another machine, the destination machine will create two key pairs - public and private.

Then the public key is distributed to the source machine, the source machine will add the files to send and attach with public key.

Then the data is transferred with public key and it is decrypted using the private key on the destination server.

Similarly, it is same with EC2, the machine will create the key pairs and send the private key to the user.

Then only the user can open the machine, the pem is converted to ppk and given in the putty under auth connection.

To connect linux machine

Linux 1 = > ssh -i privatekey2 username2@ip2

Linux 2 = > ssh -i privatekey1 username1@ip1


To install python on all machines


#!/bin/bash

yum install python-pip -y

To check installed or not, type python --version

So now we can install ansible on the master server

we can perform the install through pip, but if you install through pip, the below two files will not be added

/etc/ansible/hosts = > invertory file (worker IP's ) slave IP's

/etc/ansible/ansible.cfg = > configuration file

But if you install through yum and apt install the file applicable by default.

so if do through pip, then you have to add the file manually


To install ansible


# pip install ansible

To create a host file > vi slave.txt

To create a ansible config file > go to website > ansible config file > get from github

select stable version based on your ansible version

select raw > wget website

once you download the config file, use vi editor and change the host keys =false

Then run a command 

#ansible all -i slave.txt -m ping

all means all the files in the slave.txt file.

-i means inventory file that is slave.txt

-m means module

here the module is ping

you can get several modules in online for ansible.

pagent only accepts ppk file


putty + pagent

pip install ansible

slave.txt  ansible.cfg

ansible all -i slaves.txt -m ping