Ansible Tool
Ansible Tool
Automation Tool-Redhat-ANSIBLE
============================================================
Task-->
-->Task is a section tha contains procedure to be completed
---->A task can have multiple MODULES
*ANSIBLE tool is very easy to configure and use in the production env
--------------------------------
Examples for TASKS:
------------------------------
*Stop,start services
*User,group perm
*Application Deployment
*Backup
*Package installations,upgrading,remove
-------------------------------------------------------
History ANSIBLE
--------------------------------------------------------
---------------------------------------------------------------
Advantages of ANSIBLE
-------------------------------------------------------------
*Opensource
*Increase productivity
*Easy to use
*Secure(Over SSH)
*Human errors
-----------------------------------------------------------------------------------
------------------------------------------
NOTE:1 ANSIBLE SERVER/CONTROL NODE MUST BE LINUX(REDHAT)
NOTE:3 But you can push a task to multiple cross platform OS's from the CONTROL
NODE
-----------------------------------------------------------------------------------
---------------------------------------------
=================================================
INVENTORY FILE/ANSIBLE CONFIG FILE
==================================================
*This file has info about the Remote servers/target servers(IP DETAILS) where the
tasks are executed
#cat -n /etc/ansible/hosts
=====================================================
Configure ANSIBLE/CONTROL NODE SERVER-REDHAT
=====================================================
Procedure:
(ANSIBLE)SERVER-1 192.168.0.109(Chennai)
SERVER-2 192.168.0.181(Bangalore)
SERVER-3 192.168.0.197(Kerla)
=================
ON SERVER-1
==================
#vi /etc/ansible/hosts
# Ex 1: Ungrouped hosts, specify before any group headers.
## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10
192.168.0.181
192.168.0.197
:wq!
==============================
To List the Inventory details?
==============================
#ansible-inventory --list
{
"_meta": {
"hostvars": {
"192.168.0.181": {},
"192.168.0.197": {}
}
},
"all": {
"children": [
"ungrouped"
]
},
"ungrouped": {
"hosts": [
"192.168.0.181",
"192.168.0.197"
=====================================================
Establashing Connection to remote server using SSH
======================================================
*Copy the keys and sent it to the remote servers for PASSWORD LESS SSH CONNECTIONS
ON ANSIBLE SERVER-1
---------------------------
Create SSH KEYS:
--------------------------
#ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:7erN4yOS6aHZxg3O6bnTHLMQ7xlkqJlP4eH56KYJcxw root@icicibankserver
The key's randomart image is:
+---[RSA 2048]----+
| |
| |
| . |
| = o. |
| E* OS . |
| .+.B =. |
| o o*.& *. |
| + =#oX+o |
| =BB=oo+o |
+----[SHA256]-----+
--------------------------------------------------
Copy the keys to the remote servers
----------------------------------------------------
Syntax: #ssh-copy-id <Remote server IP>
# ssh-copy-id 192.168.0.181
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed:
"/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out
any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted
now it is to install the new keys
[email protected]'s password:
# ssh-copy-id 192.168.0.197
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed:
"/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.0.197 (192.168.0.197)' can't be established.
ECDSA key fingerprint is SHA256:BW6Mv7zraUNfMSa9QSOtS9Foa820NqAYuipXl6aW3ao.
ECDSA key fingerprint is MD5:7f:c8:5a:e1:67:1c:7c:9f:35:46:42:d7:0a:62:64:a4.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out
any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted
now it is to install the new keys
[email protected]'s password:
-----------------------------------------------------------------------------------
-------------
TO VERIFY PASSWRODLESS LOGIN TO THE REMOTE SERVERS
-----------------------------------------------------------------------------------
-------------
FROM SERVER-1
# ssh 192.168.0.181
[root@AWSSERVER ~]# ifconfig enp0s3
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.181 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 2406:7400:c2:c161:9179:2281:ff97:3657 prefixlen 64 scopeid
0x0<global>
inet6 fe80::a9a5:910d:fec1:b66e prefixlen 64 scopeid 0x20<link>
ether 08:00:27:e8:0e:de txqueuelen 1000 (Ethernet)
RX packets 83192 bytes 12108746 (11.5 MiB)
RX errors 0 dropped 31 overruns 0 frame 0
TX packets 6884 bytes 823227 (803.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
================================================
Push tasks to Multiple servers using ANSIBLE
================================================
SERVER-2 192.168.0.181(Bangalore)
SERVER-3 192.168.0.197(Kerla)
Ansible--->YAML SCRIPTING
--->ANSIBLE COMMANDS AND MODULES
Task: Check the currently mounted partition info on all remote servers
Ex:3 How to check the status of "nfs" service on all remote servers?