rmll2013 introduction to ansible

25
Introduction to Ansible Toshaan Bharvani - VanTosh bvba What is Ansible? Modus operandi Getting started Conclusion The End Introduction to Ansible System Orchestration Tool Toshaan Bharvani - VanTosh bvba <[email protected]> RMLL/LSM 2013 11 July 2013 Introduction to Ansible Toshaan Bharvani - VanTosh bvba 1 / 25

Upload: mirfak

Post on 28-Apr-2017

236 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Introduction to AnsibleSystem Orchestration Tool

Toshaan Bharvani - VanTosh bvba

<[email protected]>

RMLL/LSM 2013

11 July 2013

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 1 / 25

Page 2: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

$ whoami

Toshaan Bharvani

From Antwerp, Belgium

Currently self-employed : VanToshhttp://www.vantosh.com

Involved with Enterprise Linux : RHEL, CentOS, SLES, . . .

Likes to keep everything secure : SELinux, Web, . . .

Lives in a virtual world : KVM, Xen, LXC, . . .

Likes automation : Ansible

Works on both hardware and software side

Wants to take over the world

Twitter : @toshywoshy

Blog : http://www.toshaan.com

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 2 / 25

Page 3: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Table of contents

1 What is Ansible?

2 Modus operandi

3 Getting started

4 Conclusion

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 3 / 25

Page 4: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

1

What is Ansible?

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 4 / 25

Page 5: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End Configuration Management Tool

System Orchestration Tool

Remote Execution/Deployment Tool

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 5 / 25

Page 6: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

An overview

Python based

Server based, agentless1

uses SSH (can use ZeroMQ aka fireball)

host information in flat files, CMDB, scripts, . . .

executes a task on the host side

Playbook : combination of tasks with meta information

YAMLJSON

Templates : Jinja2

works where Python works2

1However in certain setup an agent might be required, but by default it is not necessary

2Ansible can actually run without Python on the remote host, however it is not fully supported

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 6 / 25

Page 7: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Internal Design

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 7 / 25

Page 8: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

2

Modus operandi

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 8 / 25

Page 9: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Adhoc Mode

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 9 / 25

Page 10: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Delegation Mode

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 10 / 25

Page 11: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Fireball Mode

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 11 / 25

Page 12: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Pull Mode

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 12 / 25

Page 13: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

3

Getting started

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 13 / 25

Page 14: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Inventory - Files

hosts file is by default in ini format� �1 [ v a n t o s h ]2 main a n s i b l e s s h h o s t=main . v a n t o s h . com a n s i b l e s s h p o r t

=22222 a n s i b l e s s h u s e r=a n s i b l ea n s i b l e s s h p r i v a t e k e y f i l e =/path / to /my/ p r i v a t e / key

34 [ be l g iu m ]5 b i e r . b e l g iu m . i n t6 c h o c o l a t e s . be lg i um . be7 diamonds . antwerp . com89 [ b e e r ]

10 b i e r . b e l g iu m . i n t11 p i v o . r u s s i a . i n t12 b e e r . uk . co . i n t� �

hosts vars and group vars folder and files

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 14 / 25

Page 15: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Inventory - Script

can be an executable script that outputs json� �1 #! / u s r / b i n / env python23 import s q l i t e 34 import s y s5 import j s o n67 dbname = ’ h o s t s . db3 ’89 v a r s = {}

1011 con = s q l i t e 3 . c o n n e c t ( dbname )12 con . r o w f a c t o r y=s q l i t e 3 . Row13 c u r = conn . c u r s o r ( )1415 c u r . e x e c u t e ( ”SELECT COUNT(∗) FROM h o s t s WHERE name=?” , ( name

, ) )16 row = c u r . f e t c h o n e ( )17 p r i n t j s o n . dumps ( row , i n d e n t =4)1819 con . c l o s e ( )� �

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 15 / 25

Page 16: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Facts� �1 {2 ” a n s i b l e f a c t s ” : {3 ” a n s i b l e a r c h i t e c t u r e ” : ” x86 64 ” ,4 ” a n s i b l e d i s t r i b u t i o n ” : ”CentOS” ,5 ” a n s i b l e d i s t r i b u t i o n r e l e a s e ” : ” F i n a l ” ,6 ” a n s i b l e d i s t r i b u t i o n v e r s i o n ” : ” 6 . 4 ” ,7 ” a n s i b l e f o r m f a c t o r ” : ” Mini Tower” ,8 ” a n s i b l e f q d n ” : ”d54C610ED . a c c e s s . t e l e n e t . be ” ,9 ” a n s i b l e h o s t n a m e ” : ” s a n i ” ,

10 ” a n s i b l e k e r n e l ” : ” 2 . 6 . 3 2−3 5 8 . 6 . 1 . e l 6 . x86 64 ” ,11 ” a n s i b l e m a c h i n e ” : ” x86 64 ” ,12 ” a n s i b l e o s f a m i l y ” : ”RedHat” ,13 ” a n s i b l e p k g m g r ” : ”yum” ,14 ” a n s i b l e p r o c e s s o r ” : [15 ” I n t e l (R) Xeon (R) CPU E31220 @ 3 . 1 0 GHz”16 ] ,17 ” a n s i b l e p r o c e s s o r c o r e s ” : 4 ,18 ” a n s i b l e p r o c e s s o r c o u n t ” : 1 ,19 ” a n s i b l e p r o c e s s o r t h r e a d s p e r c o r e ” : 1 ,20 ” a n s i b l e p r o c e s s o r v c p u s ” : 4 ,21 ” a n s i b l e p y t h o n v e r s i o n ” : ” 2 . 6 . 6 ” ,22 ” a n s i b l e s e l i n u x ” : {23 ” c o n f i g m o d e ” : ” e n f o r c i n g ” ,24 ”mode” : ” e n f o r c i n g ” ,25 ” p o l i c y v e r s ” : 24 ,26 ” s t a t u s ” : ” e n a b l e d ” ,27 ” t y p e ” : ” t a r g e t e d ”28 } ,29 ” a n s i b l e v i r t u a l i z a t i o n r o l e ” : ” h o s t ” ,30 ” a n s i b l e v i r t u a l i z a t i o n t y p e ” : ”kvm” ,31 }� �

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 16 / 25

Page 17: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Modules

cloud : cloudformation, digital ocean, ec2, linode, rax, rds, s3, virt, openstack

commands : command, raw, script, shell

database : mongodb, mysql, postgresql, riak

files : assemble, copy, fetch, file, ini file, lineinfile, stat, template

inventory : add host, group by

messaging : rabbitmq

monitoring : airbrake deployment, datadog event, monit, nagios, newrelic deployment, pagerduty,pingdom

net infrastructure : arista, bigip pool, netscaler

network : get url, slurp, uri

notification : campfire, flowdock, hipchat, irc, jabber, mail, mqtt, osx say

packaging : apt, easy install, gem, homebrew, npm, openbsd pkg, opkg, pacman, pip, pkgin, pkgng,redhat, svr4pkg, yum, zypper

source control : bzr, git, hg, subversion

system : authorized key, cron, facter, filesystem, group, lvg, lvol, mount, ohai, ping, seboolean,selinux, service, setup, sysctl, user, zfs

utilities : debug, fail, fireball, pause, set fact, wait for

web infrastructure : django manage, htpasswd, supervisorctl

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 17 / 25

Page 18: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Single Tasks

� �12 # p i n g a l l h o s t s3 a n s i b l e a l l −m p i n g45 # run s e t u p / f a c t s module6 a n s i b l e a l l −m s e t u p78 # run t h e command dd9 a n s i b l e a l l −m command −a ’ dd i f =/dev / z e r o o f=/tmp/ d d f i l e bs =1024

count =1000 ’1011 # i n s t a l l l a t e s t tmux package12 a n s i b l e a l l −m yum −a name=tmux s t a t e=l a t e s t� �

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 18 / 25

Page 19: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Playbooks� �1 −−−2 − h o s t s : w e b s e r v e r s3 v a r s :4 h t t p p o r t : 805 m a x c l i e n t s : 2006 h t t p v i r t u a l h o s t : {{ v i r t u a l h o s t n a m e}7 u s e r : r o o t8 sudo : y e s9 s u d o u s e r : p o s t g r e s

10 s e r i a l : 511 t a s k s :12 − name : t a k e out o f l o a d b a l a n c e r p o o l13 a c t i o n : command / u s r / b i n / t a k e o u t o f p o o l {{

i n v e n t o r y h o s t n a m e }}14 d e l e g a t e t o : 1 2 7 . 0 . 0 . 115 − name : e n s u r e apache i s a t t h e l a t e s t v e r s i o n16 a c t i o n : yum pkg=h t t p d s t a t e=l a t e s t17 − name : w r i t e t h e apache c o n f i g f i l e18 a c t i o n : t e m p l a t e s r c =/ s r v / h t t p d . j 2 d e s t=/e t c / h t t p d . c o n f19 n o t i f y :20 − r e s t a r t apache21 − name : e n s u r e apache i s r u n n i n g22 a c t i o n : s e r v i c e name=h t t p d s t a t e=s t a r t e d23 − name : add back to l o a d b a l a n c e r p o o l24 a c t i o n : command / u s r / b i n / a d d b a c k t o p o o l {{

i n v e n t o r y h o s t n a m e }}25 d e l e g a t e t o : 1 2 7 . 0 . 0 . 126 h a n d l e r s :27 − name : r e s t a r t apache28 a c t i o n : s e r v i c e name=h t t p d s t a t e=r e s t a r t e d� �

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 19 / 25

Page 20: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Templates

� �1 # {{ a n s i b l e m a n a g e d }}23 {# editmode i s e i t h e r ” v i ” o r ” emacs ” #}45 s e t −g p r e f i x C−a6 s e t −g s t a t u s−u t f 8 on7 setw −g mode−k e y s {{ ed i tmode }}� �

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 20 / 25

Page 21: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Fireball

� �1 −−−2 # I n i t i a l i z e f i r e b a l l3 − h o s t s : 0mq4 g a t h e r f a c t s : no5 c o n n e c t i o n : s s h6 u s e r : f b7 sudo : y e s8 t a s k s :9 − a c t i o n : f i r e b a l l

1011 # f i r e b a l l now !12 − h o s t s : n a m e s e r v e r s13 c o n n e c t i o n : f i r e b a l l14 t a s k s :15 − a c t i o n : s h e l l echo ” H e l l o {{ i t em }}”16 w i t h i t e m s :17 − one18 − two� �

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 21 / 25

Page 22: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

API

� �1 #! / u s r / b i n / env python23 import a n s i b l e . r u n n e r4 import s y s56 r e s = a n s i b l e . r u n n e r . Runner (7 p a t t e r n= ’ a1∗ ’ ,8 module name= ’ command ’ ,9 m o d u l e a r g s= ’ / u s r / b i n /uname −a ’

10 ) . run ( )1112 p r i n t r e s� �

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 22 / 25

Page 23: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

4

Conclusion

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 23 / 25

Page 24: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

Conclusion

Automation MUST[RFC2119] be easy

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 24 / 25

Page 25: Rmll2013 Introduction to Ansible

Introductionto Ansible

ToshaanBharvani -VanTosh

bvba

What isAnsible?

Modusoperandi

Gettingstarted

Conclusion

The End

The End

Thank You

Toshaan Bharvani - VanTosh bvba <[email protected]>

http://www.vantosh.com/publications

Made with Beamer LATEXa TEXbased Presentation program

Introduction to Ansible Toshaan Bharvani - VanTosh bvba 25 / 25