Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ansible - Automazione e orchestrazione agile

Ansible - Automazione e orchestrazione agile

Introduzione ad Ansible (http://www.ansible.com), sistema di automazione e orchestrazione IT scritto in Python, libero (GNU GPL v3) e che si contraddistingue dai concorrenti per l'utilizzo di un' infrastruttura minimale e la sua semplicità.
PDF esportato dalla presentazione originale scritta per reveal.js (https://github.com/hakimel/reveal.js), sorgente della presentazione disponibile su github (https://github.com/lgaggini/ansible-reveal).

Lorenzo Gaggini

February 05, 2014
Tweet

Other Decks in Technology

Transcript

  1. CARATTERISTICHE 1 SOFTWARE LIBERO GNU General Public License V3 MULTIFUNZIONE

    orchestratore provisioning di configurazioni deploy di applicazioni API Python Web app Ansible AWX
  2. CARATTERISTICHE 2 INFRASTRUTTURA MINIMALE requisiti minimali: python e 4 package

    (paramiko PyYAML jinja2 httplib2) nessun agente transport ssh (gestione utenti, crittografia e firewall inclusi) supporto a sudo modello push multi-controller
  3. CARATTERISTICHE 3 AGILE sintassi pseudonaturale in formato yaml task ordinali

    ampia libreria di moduli idempotenti json output templating jinja 2
  4. INSTALLAZIONE REPOSITORY Rpm-based from EPEL: $ s u d o

    y u m i n s t a l l a n s i b l e Deb-based from custom PPA: $ s u d o a p t - g e t i n s t a l l a n s i b l e SORGENTI $ s u d o p i p i n s t a l l p a r a m i k o P y Y A M L j i n j a 2 h t t p l i b 2 $ g i t c l o n e g i t : / / g i t h u b . c o m / a n s i b l e / a n s i b l e . g i t $ c d . / a n s i b l e $ s o u r c e . / h a c k i n g / e n v - s e t u p
  5. MACCHINE: INVENTORY file ansible_hosts, inventory delle macchine, gruppi e impostazioni

    [ d a t a c e n t e r 1 - w e b s e r v e r s ] f o o . e x a m p l e . c o m a n s i b l e _ s s h _ p o r t = 2 2 2 2 a n s i b l e _ s s h _ u s e r = m a n a g e r w w w [ 0 1 : 5 0 ] . e x a m p l e . c o m [ d a t a c e n t e r 2 - w e b s e r v e r s ] w w w . e x a m p l e 2 . c o m [ d a t a - c e n t e r 1 : c h i l d r e n ] d a t a c e n t e r 1 - w e b s e r v e r s d a t a c e n t e r 1 - d b s e r v e r s [ w e b s e r v e r s : c h i l d r e n ] d a t a c e n t e r 1 - w e b s e r v e r s d a t a c e n t e r 2 - w e b s e r v e r s
  6. ORCHESTRAZIONE Trasferimento di file $ a n s i b

    l e w e b s e r v e r s - m c o p y - a " s r c = / e t c / h o s t s d e s t = / t m p / h o s t s " Package $ a n s i b l e w e b s e r v e r s - m y u m - a " n a m e = h t t p d s t a t e = l a t e s t " Deploy $ a n s i b l e w e b s e r v e r s - m g i t - a " r e p o = g i t : / / f o o . e x a m p l e . o r g / r e p o . g i t d e s t = / s r v / m y a p p v e r s i Servizi $ a n s i b l e w e b s e r v e r s - m s e r v i c e - a " n a m e = h t t p d s t a t e = r e s t a r t e d " -m Ampia disponibilità di moduli
  7. AUTOMAZIONE: PLAYBOOK 1 - h o s t s :

    w e b s e r v e r s v a r s : h t t p _ p o r t : 8 0 m a x _ c l i e n t s : 2 0 0 u s e r : a n s i b l e s u d o : t r u e t a s k s : - n a m e : e n s u r e a p a c h e i s a t t h e l a t e s t v e r s i o n y u m : p k g = h t t p d s t a t e = l a t e s t - n a m e : w r i t e t h e a p a c h e c o n f i g f i l e 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 f n o t i f y : - r e s t a r t a p a c h e - n a m e : e n s u r e a p a c h e i s r u n n i n g s e r v i c e : n a m e = h t t p d s t a t e = s t a r t e d h a n d l e r s : - n a m e : r e s t a r t a p a c h e s e r v i c e : n a m e = h t t p d s t a t e = r e s t a r t e d $ a n s i b l e - p l a y b o o k w e b s e r v e r s m y p l a y b o o k . y m l
  8. AUTOMAZIONE: PLAYBOOK 2 TEMPLATING playbook - v a r s

    : h t t p _ p o r t : 8 0 m a x _ c l i e n t s : 2 0 0 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 f httpd.j2 L i s t e n { { h t t p _ p o r t } } M a x C l i e n t s { { m a x _ c l i e n t s } }
  9. AUTOMAZIONE: PLAYBOOK 3 CONDIZIONI - n a m e :

    " s h u t d o w n D e b i a n f l a v o r e d s y s t e m s " c o m m a n d : / s b i n / s h u t d o w n - t n o w w h e n : a n s i b l e _ o s _ f a m i l y = = " D e b i a n " LOOP - n a m e : a d d s e v e r a l u s e r s u s e r : n a m e = { { i t e m . n a m e } } s t a t e = p r e s e n t g r o u p s = w h e e l w i t h _ i t e m s : - t e s t u s e r 1 - t e s t u s e r 2
  10. AUTOMAZIONE: PLAYBOOK 4 ERROR HANDLING Registrazione di esiti per controlli

    successivi: - n a m e : i f t h i s c o m m a n d f a i l r e g i s t e r t h e f a i l b u t i g n o r e t h e e r r o r c o m m a n d : / u s r / b i n / e x a m p l e - c o m m a n d - x - y - z r e g i s t e r : c o m m a n d _ r e s u l t i g n o r e _ e r r o r s : T r u e Condizioni di fallimento personalizzabili: - n a m e : t h i s c o m m a n d p r i n t s F A I L E D w h e n i t f a i l s c o m m a n d : / u s r / b i n / e x a m p l e - c o m m a n d - x - y - z r e g i s t e r : c o m m a n d _ r e s u l t f a i l e d _ w h e n : " ' F A I L E D ' i n c o m m a n d _ r e s u l t . s t d o u t "
  11. INTERFACCE 1 API Python # ! / u s r

    / b i n / p y t h o n i m p o r t a n s i b l e . r u n n e r i m p o r t s y s # c o n s t r u c t t h e a n s i b l e r u n n e r a n d e x e c u t e o n a l l h o s t s r e s u l t s = a n s i b l e . r u n n e r . R u n n e r ( p a t t e r n = ' * ' , f o r k s = 1 0 , m o d u l e _ n a m e = ' c o m m a n d ' , m o d u l e _ a r g s = ' / u s r / b i n / u p t i m e ' , ) . r u n ( ) i f r e s u l t s i s N o n e : p r i n t " N o h o s t s f o u n d " s y s . e x i t ( 1 ) p r i n t " U P * * * * * * * * * * * " f o r ( h o s t n a m e , r e s u l t ) i n r e s u l t s [ ' c o n t a c t e d ' ] . i t e m s ( ) : i f n o t ' f a i l e d ' i n r e s u l t : p r i n t " % s > > > % s " % ( h o s t n a m e , r e s u l t [ ' s t d o u t ' ] )
  12. CONCLUSIONI Una qualsiasi forma di automazione strutturata (Chef, Puppet, Ansible,

    Salt) è meglio di nessuna automazione. Ansible fa dei suoi punti di forza: semplicità infrastruttura minimale curva di apprendimento agevole multifunzionalità (orchestrazione e automazione)