You are on page 1of 8

P.

Savitha
DevOps 5l3321LO;o 39

Configwalion Managernert Osig


Ansible

Assigonent - 2

Anstble Moduuler
Ansible modles ae used to pefom VaDçous tusts
7enOte hots. thee basicay nall, s tasalone,
Soits thO t cnsible wse tt com uniate woith the
1emote hasts in orde to exeite Specfic actiors.
the moles Can be e e cubed from the
(ine o an be ontten in the plauybooks
Synta fo Loitirg the modile on (ommand line
wbile
wstg the moule wAe tbe option
Such as - m and -CL. the -n SfoT mdte and a s for
aument,ftei he -a oFtio we Spectty he exectuable
Command in doule quDtes.

Cornmeony wed nocdiles


1. Comand- FoloUoiNg s a modle tbat
executes a coroman oO nemote hosts

$ ansble al Comand aecho Helo bosts"


modle is wed to Geate, modify
2. Osey - The WoeI
de lete wes

$ anc+ble dev Lser -a 'name-new ube state


esernt"
3. Pio - The pirg Modle Ubed to
Connec tivity
to Aemote basts
$ ansi ble al | - m ping
4. Copy - The opy module s Lsed to copY iles
control machine to nernote bosts
from

5. packae- The packoge modle s ed to înctall,


AeMOVe or upgrade the packoe
6. Shell -The Shetl modute wbed to s shetl conmard
uwitmoe teibility on nemote hosti.
1.
levice - The Sevice module wsed to <tt,stpP OY
Ye stCOt
a specific sevice on emote horts.
Aote hat 4he Stoted for staoring he
State Cah

evi ce. stopped fo stopDg the Sevlce.


Stotted lstoppet aDe derpotent actions ttat c l Dot
comnards unless necossay.
Aestrtel oill alays bounce the sevlce
MeOaded oilla y s retoad.
Anssbe (nven tory les
" the înventoy fle also called s bost le.

" t a text Ale ttat costainsthe ist cÙ

maraged nodes. these nodes can be oaNged i


diefexent hast groups. ha can be usefy for orgarizi
you hests and for unn+g tasEs on specifie goups
O& hasts.
Can eate a goup called websewe tat

affects the wes Senves by taoigeting


Playbook t a t ony
the "websenven Jroup
3
The inventony ile as ecsent al coeponent oB
ansible aochi tectuoe.

" b the iventony le s a easerstla eory the


addecs c eac node s speciied.
For eample -
[usebseven]
(92.(b8|.23

useb hort I
Cdevj

|92.(681.01
|92.1b&|.O2

(92. lb&.1. |
192. lb8IR

The inven tery files o wsed by ans+ble to

detemine obich bosts to r s


taskS

When ansi ble runs a ploybooklt uoili i s t

for tbe Toventory Hle CLNent coorg


investory fie fouansible uo0
dinec toy. If the
the defauIt oc ation obich b lete (ansible/
look for i
to neet
hasts. e caO modity this file
Ansible playbooEs
ctrictions thet
An nsible playbooky b a set ot
ansible ube to awtoate tss O5 efote hots playbeoy
hiran- eadable forrat.
aSe ¡Htes in vÀMLa
The laybooks ae s i i l a to as rsible t -d ist
tbat has a lst o tosLo.
the extensiN to the plouyboo le
The styucte o playbook b a shouon beLoor

Comnent line

Name d playbook

Host group Aome

Sudo pri vileges


Play

Tasrs
|mecules)

Each playboOk on tas fobiDg inportant elennents


Hosts: In a play we cas Specity tte taget hosts or
9Ops Cb hasts ohene you ant to appy the tasks.

Play: ployboos ae Lollections oß One or


more plays
that Coe perforned In a certain order. A plauy is ao

Ordeed ceuence ct tasbs Petorrned aganist hosts from


the înventory ile uhich we define
5
aNe the indivicul usits Cf uork Lotbin
|a play. Each tsk epreets on action tobe tcikor os he
toiqet hostS.Tac can incude ansTsle modules, uohich e

Pedefinet soiets to perfor vaious acti cs on 2emote


hosts, such as instaling packaqesy tanogig sevices, coPirg
files and ONe
Modles Ansble provides a wide Aae t rocles for
aHeent ppoces. MOdules oe wed is tasks t perforr
Specific actios. Examples indude +he yu modu le for
Pactage manaqerent.the sevice moule for managing
Sevices, the coPy module for copying les and many more.
Alorg he abore basic elemers define
vaiables, handleu and roles in the play boo k.

Impo tant cote thatibden tatiOs mst be sthctt

follouoed wbile c o g tte playboOks Hles

plouyboots Good Practce is to give


stats wit wbi te <Spce a f t e tf

thae e dases

-t# Thi is my first plouybook osch simy


gatteLs the feects
basts : dey
After colon thee
Wseyans ble
mwst be single
ConDecthon :sb Lsbite spac
becone yes
gather- acts !yes
Ths should be
irden ted o
Same couh
Ansible Res
" In
anci ble aes there s a Specific directry stutu
and the tauskh Con be sepcootecd o t Ih the appropiacte
Rles aCLorchg to hey funcioalities These les
can be
Called as p euisemets,
Abcble Aoles help Structuoe and
noilarrze ouI
ansible ects.
.Usig ansble ole e Cas mate the ceve Cof
tasks more maintaibate, neuLsable and
easier toundostu
Benefts o Ansi ble roles
. Reua bility-Roles can be neuse in
tisle playbcoEs
hicS Saves o tme ond effort
2. Modulai ty- Roles help t teep ansible playbeoks
and modla. oranized
B. Shoneabliy- Roles can be easiy Shaoe uoth
othe
ansible wseLs.
4. Consus teny- Roles
help to enssethat asible tsks ame
pafoed Consisteny acOSs diefeent
ploybooks
Typicc) sbrc tube t ansible role.
Lmyusebdefaults
+les
Loin.yrm l
ha
meto

Lroai. yn)
+Readme md
4ta
’templates ymain.ym)
4(nventomy
yteSt testyol
VOrs
de foults - It Stores 4he defoult vaojable for the role
files - This folde cOntains the les eaiyed to trarsfer
deploy to the taiget
machines
Lsed by
" bandles - t cootuins bandles, wbich may be
SONe Aole.
data or informatien about tho ola
metta - t deAne .come
t toss to be ezeutet
" tas ks -(t ontains he main list
defioed in sepaNate Gtes
by the ole. these tasts nlght be
functionalities
cs per the
the templates wshich ca be
" templates - It cotains
deployed via a role.
ansible
Adhoc comtandc in
ae cL CcomDand Line
+ The ansible adhoc ommasds
s
Commands sed for siPle and one irne such
In tece)
hosts at a time or transfeig some
Shutting dous all he
nodes.
ile to all the
eas but they
The adhoc coMMads a e qick and
e Dot eUsable.
ae Lsed n ansIble to pef
Te adboc Comands
Immediate banie
or openrtion that a e neecded o
toxh
equisements.
as pe the

coands
Syntaz for adhoe
Ne 2hosts 7[-m Lmocule_name ]-a L"a1guments">

-u LLsenname -- beormeT
. To test the nec tion betoeen Corrto|Node and all the
mabaged nodes
$ ansible dev -m ping
2. TO check the list G a) 4he hosts

3. To check tthe uptìme


uptime
$ ansible dev -m shell -a up time
$ Cunsible dev -a uptime

u. To check the free memory or memoy es age c& hasts


$ ans+ble dev -a 'free - m"

basts
S. TO get the physical memory allocated to the
$ ansTble dev -m shell -a cat lpYDC lead -2"

6. TO tranfer a 9le to all the hocts c& a roup


4ansible dev - copy -a'src =| test-file te xt destntest tile.tx"
1. TO ate a nes irec tory on all tthe host ofa group

8. TO manage a Package on all the hos ts


9. TO ather the facts
ansible dev - setup

t0. To Aebot the all e seves

& ansible dev -a (sbin reboo t"

You might also like