Ansible
Ansible is an open source automation engine that automates software provisioning, configuration management, and application deployment.
DEPLOY APPS. MANAGE SYSTEMS. CRUSH COMPLEXITY.
Ansible delivers simple IT automation that ends repetitive tasks and frees up DevOps teams for more strategic work.
ANSIBLE OPEN SOURCE
SIMPLE. POWERFUL. AGENTLESS.
App deployment, configuration management and orchestration - all from one system. Ansible is powerful automation that you can learn quickly.
As with most configuration management software, Ansible has two types of servers: controlling machines and nodes. First, there is a single controlling machine which is where orchestration begins. Nodes are managed by a controlling machine over SSH. The controlling machine describes the location of nodes through its inventory.
To orchestrate nodes, Ansible deploys modules to nodes over SSH. Modules are temporarily stored in the nodes and communicate with the controlling machine through a JSON protocol over the standard output. When Ansible is not managing nodes, it does not consume resources because no daemons or programs are executing for Ansible in the background.
Note : You can install Ansible upon any linux flavour but here i am using REDhat 7.1
1) Installing Ansible
i) Method first :- Using RPM package or with YUM command
ii) Method Second :- Using python based PIP installer
Step 1: First install Pip installer you don't have in your redhat 6.4/7.1
[root@desktop83 ~]# yum install python-pip
then Install ansible :
[root@desktop83 ~]# pip install ansible
After Installation process this operation you can check there will be /etc/ansible directory
OR :
You can use Yum installer if you have repopath setup already.
For Redhat 6.4 and later
==================
[root@desktop57 ~]# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@desktop57 ~]# yum install ansible
For Redhat 7.1 and Later
[root@desktop57 ~]# rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
[root@desktop57 ~]# cd /etc/yum.repos.d
[root@desktop57 yum.repos.d]# cat live.repo
[aa]
baseurl=http://mirror.centos.org/centos-7/7.2.1511/os/x86_64/
gpgcheck=0
[bb]
baseurl=http://mirror.centos.org/centos-7/7.2.1511/extras/x86_64/
gpgcheck=0
[root@desktop57 ~]# yum install ansible
root@shalinux:/etc/ansible# cd /etc/ansible/
root@shalinux:/etc/ansible# ls
hosts
Step 2: Managing Servers
Ansible was designed to managed multiple servers from a single system by using SSH
Important :
Here We have three machine one is Ansible installed and other two are the targets where we want to perform operation
Ansible Installed machine is : 192.168.100.104
Target1 -- 192.168.100.9
target2 -- 192.168.100.10
Note: Setup and and share ssh-keys from Ansible machine to target
i) Generating ssh-keys
[root@hmaster ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
fe:4c:85:36:03:b8:3a:35:35:ec:70:f0:28:bb:ee:a1 root@hmaster.example.com
The key's randomart image is:
+--[ RSA 2048]----+
| . |
| * |
| . + B |
| o * o . |
| . + S = . |
| + o . + |
| = . . |
| o o + |
| E.o o |
+-----------------+
ii) share keys to both the targets machine
[root@hmaster ~]# ssh-copy-id 192.168.100.9
[root@hmaster ~]# ssh-copy-id 192.168.100.10
iii) make a backup of host file
root@shalinux:~# cp /etc/ansible/hosts /etc/ansible/hosts.backup
iv) Now edit this file and specify the targets IPS
Important: File /etc/ansible/hosts also known as inventory file
root@shalinux:~# vim /etc/ansible/hosts
This will look like this
root@shalinux:~# cat /etc/ansible/hosts
[testing]
192.168.100.9
192.168.100.10
v) Running Some basic commands
sending icmp packets
a) Sending Icmp echo-request
root@shalinux:~# ansible testing -m ping
192.168.100.9 | success >> {
"changed": false,
"ping": "pong"
}
192.168.100.10 | success >> {
"changed": false,
"ping": "pong"
}
Here:
ansible :- is the command
testing :- name defined in inventory file for calling all the list server
-m :- use for specify the module name
ping : This is the name of module which simply send icmp packets to all the define servers
b) In case you have many entries in inventory file then want to send icmp packets
root@shalinux:~# vim /etc/ansible/hosts
root@shalinux:~# cat /etc/ansible/hosts
[testing]
192.168.100.9
192.168.100.10
[apache]
192.168.100.11
root@shalinux:~# ansible all -m ping
192.168.100.10 | success >> {
"changed": false,
"ping": "pong"
}
192.168.100.9 | success >> {
"changed": false,
"ping": "pong"
}
192.168.100.11 | success >> {
"changed": false,
"ping": "pong"
}
Note:
all : for all inventory file entries
##########
Modules:
Modules are predefined functions in ansible which are used to perform some specific task :
I am listing some names with examples of modules.
Module LIst:
a) ping
b) shell
c) command
=========
example: testing date command
root@shalinux:~# ansible testing -m shell -a date
192.168.100.109 | success | rc=0 >>
Thu Feb 18 06:54:36 EST 2016
-------------------------------------------------------
root@shalinux:~# ansible all -m shell -a date
192.168.100.109 | success | rc=0 >>
Thu Feb 18 06:54:45 EST 2016
192.168.100.108 | success | rc=0 >>
Thu Feb 18 06:54:53 EST 2016
----------------------------------------
Service Restart for apache web services
root@shalinux:~# ansible all -m shell -a "service httpd restart"
192.168.100.109 | success | rc=0 >>
192.168.100.108 | success | rc=0 >>
Using command modules:
root@shalinux:/etc/ansible# ansible all -m command -a "date"
192.168.100.109 | success | rc=0 >>
Fri Feb 19 01:06:51 EST 2016
192.168.100.108 | success | rc=0 >>
Fri Feb 19 01:07:04 EST 2016
Note: with shell module you need to pass -a option for passing arguments
1) Installing Ansible
i) Method first :- Using RPM package or with YUM command
ii) Method Second :- Using python based PIP installer
Step 1: First install Pip installer you don't have in your redhat 6.4/7.1
[root@desktop83 ~]# yum install python-pip
then Install ansible :
[root@desktop83 ~]# pip install ansible
After Installation process this operation you can check there will be /etc/ansible directory
OR :
You can use Yum installer if you have repopath setup already.
For Redhat 6.4 and later
==================
[root@desktop57 ~]# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@desktop57 ~]# yum install ansible
For Redhat 7.1 and Later
[root@desktop57 ~]# rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
[root@desktop57 ~]# cd /etc/yum.repos.d
[root@desktop57 yum.repos.d]# cat live.repo
[aa]
baseurl=http://mirror.centos.org/centos-7/7.2.1511/os/x86_64/
gpgcheck=0
[bb]
baseurl=http://mirror.centos.org/centos-7/7.2.1511/extras/x86_64/
gpgcheck=0
[root@desktop57 ~]# yum install ansible
root@shalinux:/etc/ansible# cd /etc/ansible/
root@shalinux:/etc/ansible# ls
hosts
Step 2: Managing Servers
Ansible was designed to managed multiple servers from a single system by using SSH
Important :
Here We have three machine one is Ansible installed and other two are the targets where we want to perform operation
Ansible Installed machine is : 192.168.100.104
Target1 -- 192.168.100.9
target2 -- 192.168.100.10
Note: Setup and and share ssh-keys from Ansible machine to target
i) Generating ssh-keys
[root@hmaster ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
fe:4c:85:36:03:b8:3a:35:35:ec:70:f0:28:bb:ee:a1 root@hmaster.example.com
The key's randomart image is:
+--[ RSA 2048]----+
| . |
| * |
| . + B |
| o * o . |
| . + S = . |
| + o . + |
| = . . |
| o o + |
| E.o o |
+-----------------+
ii) share keys to both the targets machine
[root@hmaster ~]# ssh-copy-id 192.168.100.9
[root@hmaster ~]# ssh-copy-id 192.168.100.10
Configure Inventory
Ansible works against multiple systems in your infrastructure at the same time. It does this by selecting portions of systems listed in Ansible’s inventory, which defaults to being saved in the location
/etc/ansible/hosts
. You can specify a different inventory file using the -i <path>
option on the command line.
The inventory file can be in one of many formats, depending on the inventory plugins you have. For this example, the format for
/etc/ansible/hosts
is an INI-like (one of Ansible’s defaults) and looks like this:
The headings in brackets are group names, which are used in classifying systems and deciding what systems you are controlling at what times and for what purpose.
Now go to Ansible machine and configure the hosts fileiii) make a backup of host file
root@shalinux:~# cp /etc/ansible/hosts /etc/ansible/hosts.backup
iv) Now edit this file and specify the targets IPS
Important: File /etc/ansible/hosts also known as inventory file
root@shalinux:~# vim /etc/ansible/hosts
This will look like this
root@shalinux:~# cat /etc/ansible/hosts
[testing]
192.168.100.9
192.168.100.10
v) Running Some basic commands
sending icmp packets
a) Sending Icmp echo-request
root@shalinux:~# ansible testing -m ping
192.168.100.9 | success >> {
"changed": false,
"ping": "pong"
}
192.168.100.10 | success >> {
"changed": false,
"ping": "pong"
}
Here:
ansible :- is the command
testing :- name defined in inventory file for calling all the list server
-m :- use for specify the module name
ping : This is the name of module which simply send icmp packets to all the define servers
b) In case you have many entries in inventory file then want to send icmp packets
root@shalinux:~# vim /etc/ansible/hosts
root@shalinux:~# cat /etc/ansible/hosts
[testing]
192.168.100.9
192.168.100.10
[apache]
192.168.100.11
root@shalinux:~# ansible all -m ping
192.168.100.10 | success >> {
"changed": false,
"ping": "pong"
}
192.168.100.9 | success >> {
"changed": false,
"ping": "pong"
}
192.168.100.11 | success >> {
"changed": false,
"ping": "pong"
}
Note:
all : for all inventory file entries
##########
Modules:
Modules are predefined functions in ansible which are used to perform some specific task :
I am listing some names with examples of modules.
Module LIst:
a) ping
b) shell
c) command
=========
example: testing date command
root@shalinux:~# ansible testing -m shell -a date
192.168.100.109 | success | rc=0 >>
Thu Feb 18 06:54:36 EST 2016
-------------------------------------------------------
root@shalinux:~# ansible all -m shell -a date
192.168.100.109 | success | rc=0 >>
Thu Feb 18 06:54:45 EST 2016
192.168.100.108 | success | rc=0 >>
Thu Feb 18 06:54:53 EST 2016
----------------------------------------
Service Restart for apache web services
root@shalinux:~# ansible all -m shell -a "service httpd restart"
192.168.100.109 | success | rc=0 >>
192.168.100.108 | success | rc=0 >>
Using command modules:
root@shalinux:/etc/ansible# ansible all -m command -a "date"
192.168.100.109 | success | rc=0 >>
Fri Feb 19 01:06:51 EST 2016
192.168.100.108 | success | rc=0 >>
Fri Feb 19 01:07:04 EST 2016
Note: with shell module you need to pass -a option for passing arguments
yurtdışı kargo
ReplyDeleteresimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
F6PA
Hollanda yurtdışı kargo
ReplyDeleteİrlanda yurtdışı kargo
İspanya yurtdışı kargo
İtalya yurtdışı kargo
Letonya yurtdışı kargo
PW8FDE
Angila yurtdışı kargo
ReplyDeleteAndora yurtdışı kargo
Arnavutluk yurtdışı kargo
Arjantin yurtdışı kargo
Antigua ve Barbuda yurtdışı kargo
İBWD
Azerbaycan yurtdışı kargo
ReplyDeleteAruba yurtdışı kargo
Avustralya yurtdışı kargo
Azor Adaları yurtdışı kargo
Bahamalar yurtdışı kargo
UHMN2