system automation mit puppet und foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf ·...

35
System Automation mit Puppet und Foreman Toni Schmidbauer 9. Mai 2014

Upload: others

Post on 11-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

System Automation mit Puppet und Foreman

Toni Schmidbauer

9. Mai 2014

Page 2: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

whoami

I SysAdmin@s-itsolutions

I [email protected]

I http://stderr.at

I http://github.com/tosmi

I [email protected]

Page 3: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Agenda

I Kurze Umfrage

I Was ist Puppet?

I Was ist Foreman?

I Puppet@s-iTSolutions

I Was haben wir geplant?

Page 4: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Umfrage

Page 5: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Was ist Puppet?

I Declarative programming: telling the machine what you wouldlike to happen, and let the computer figure out how to do it.

I Imperative programming: telling the machine how to do something

1 c l a s s l i n u x w o c h e n 2 0 1 4 ($ e n s u r e = p r e s e n t

3 ) {u s e r { ’ t o n i ’ :

5 e n s u r e => $ensure ,u i d => 4711 ,

7 g i d => 100 ,}

9package { ’ emacs−nox ’ :

11 e n s u r e => i n s t a l l e d} −>

13 package { ’ vim−enhanced ’ :e n s u r e => absent ,

15 }}

Page 6: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Zuordnung von Klassen

I uber /etc/puppet/manifests/site.pp

node /ˆ( f o o | bar )\ . l i n u x w o c h e n \ . a t$ / {2 i n c l u d e l i n u x w o c h e n 2 0 1 4

}

I uber Hiera (hiera include(’classes’,[““]))

I uber einen External Node Classifier (Foreman)

Page 7: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Node classification

1 −−−c l a s s e s :

3 b l a c k :puppetmgmt :

5 m a n a g e c o n f i g : t r u epuppetmaste r : puppetd

7 p u p p e t v e r s i o n : 3 . 2 . 4sudo :

9 c o n f i g d i r : / e t c / s u d o e r s . d/c o n f i g f i l e : / e t c / s u d o e r s

11 c o n f i g f i l e r e p l a c e : f a l s epackage : sudo

13 p a c k a g e s o u r c e : ’ ’purge : f a l s e

Page 8: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Puppet Environments

I Environments sind unabhangige Puppet Umgebungen

I Ein Master kann mehrere Environments zur Verfugung stellen

/ e t c / puppet / modules / . . .2 / e t c / puppet / m a n i f e s t s / s i t e . pp

4 / e t c / puppet / e n v i r o n m e n t s / l i n u x w o c h e n / modules/ e t c / puppet / e n v i r o n m e n t s / l i n u x w o c h e n / m a n i f e s t s / s i t e . pp

Page 9: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Was ist Foreman?

Page 10: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Puppet run

Hiera

Puppet Master

Puppet Agent

Puppet CAPuppetDB REST API

Theforeman

2

3

4 1 5

4

5

6

6

3

2

1

Puppet

Facts / ReportsCatalog

Node classification

Facts / Reports

Upload reports to foreman

Upload reports to puppet master

Compile / send catalog

Node classifiction

Upload facts to foreman

Upload facts to puppet master

Page 11: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Und jetzt?

Page 12: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen
Page 13: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

I Wie soll eine Entwicklungsumgebung aussehen?

I Wie testen wir den Puppet Code?

I Wie verwalten wir unseren Puppet Code?

I Wie soll unsere Puppet Umgebung aussehen?

I Wie erfolgt das Deployment des Codes?

I Wie verwalten wir Module von PuppetForge?

Page 14: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Wie soll eine Entwicklungsumgebungaussehen?

Page 15: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Vagrant

I http://vagrantup.com

I Ermoglicht virtuelle Entwicklungsumgebungen

I Vagrant Box ist ein vorkonfiguriertes Image

I Default VirtualBox andere Provider via Plugins (VMWare,KVM)

Page 16: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Demo

Page 17: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Wie testen wir den Puppet Code?

Page 18: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

rspec-puppet

I Ruby RSpec Tests fur Puppet

I Jedes Module muss RSpec Tests mitbringen

1 r e q u i r e ’ s p e c h e l p e r ’d e s c r i b e ’ l inuxwochen2014 ’ do

3 l e t : f a c t s { { : o s f a m i l y => ’ RedHat ’ } }

5 c o n t e x t ’ e n s u r e i s s e t to absent ’ dol e t : params { { : e n s u r e => ’ absent ’} }

7i t do

9 s h o u l d c o n t a i n u s e r ( ’ t o n i ’ ) . w i t h ({’ en s ur e ’ => ’ absent ’ ,

11 ’ u id ’ => ’ 4 7 1 1 ’ ,’ g id ’ => ’ 1 0 0 ’ ,

13 })end

15i t { s h o u l d c o n t a i n p a c k a g e ( ’ emacs−nox ’ ) . w i t h e n s u r e ( ’ i n s t a l l e d ’ ) }

17 i t { s h o u l d c o n t a i n p a c k a g e ( ’ vim−enhanced ’ ) . w i t h e n s u r e ( ’ absent ’ ) }i t { s h o u l d c o n t a i n p a c k a g e ( ’ emacs−nox ) . t h a t c o m e s b e f o r e ( ’ Package [ vim−enhanced ] ’ ) }

19 endend

Page 19: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Demo

Page 20: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Wie verwalten wir unseren PuppetCode?

Page 21: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

GIT

I Ein zentrales GIT RepositoryI 3 Hauptbranches

I MasterI TestingI Production

I Feature Branches fur neue Module

I Berechtigungssystem mit Gitolite

Page 22: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Wie soll unsere Puppet Umgebungaussehen?

Wie erfolgt das Deployment desCodes?

Page 23: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Umgebungen

I Development (Master)I Test auf 7 EntwicklungsserverI Push auf Remote Master Branch lost Deployment ausI RedHat 5,6 / Solaris sparc,i386 10,11 / AIX

I TestingI ca. 30 “Produktions” ServerI Annotated Tags werden automatisch deployed (test *)

I ProductionI ca 1000 HostsI Annotated Tags werden automatisch deployed (prod *)

Page 24: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Jenkins CI

I Continuous Integration Server

I Fuhrt Jobs aus (z.b. Shell Scripts)

I Monitored und liefert Status Jobs

I Es konnen Abhangigkeiten zwischen Jobs definiert werden

Page 25: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Puppet Umgebung und Deployment

Puppet developer

Development

Puppet Master

Testing

Puppet Master

Production

Puppet Master

Feature

Branch

Master

Branch

Testing

Branch

Production

Branch

4

3

2

1

Production Nodes

Testing Nodes (25−30)

Dev Nodes (7−8)

1

3

2

4

1 Features Branches get automatically created on Puppet Master (Dynamic Environments)

4

a normal commit to the Prodcution branch only runs tests

Production Branch gets deployed via GIT tag (prod_*)

3 Testing Branch gets deployed via GIT tag (test_*)

a normal commit to the Testing branch only runs tests

2 Master Branch gets deployed on commit via Jenkins

GIT

Jenkins

It’s all the same for Hiera yaml files, except dynamic environments!

Page 26: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Deployment

Page 27: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Monitoring

Page 28: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Wie verwalten wir Module vonPuppetForge?

Page 29: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Puppetforge Module

I Eigenes GIT Repository (puppetforge.git)

I Download der Module in der Enwicklungsumgebung viapuppet module install ...

I Staging GIT pull (bah!)

I Dies andert sich allerdings (dazu spater)

Page 30: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

I Wie soll eine Entwicklungsumgebung aussehen? DONE

I Wie testen wir den Puppet Code? DONE

I Wie verwalten wir unseren Puppet Code? DONE

I Wie soll unsere Puppet Umgebung aussehen? DONE

I Wie erfolgt das Deployment des Codes? DONE

I Wie verwalten wir Module von PuppetForge? DONE

Page 31: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen
Page 32: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Probleme, Probleme, Probleme...

I Ein GIT Repo funktioniert nicht bei Anderungen vonUpstream Modulen

I Andere Abteilungen sollen ihre Module unabhangig testen

I Unittests sagen noch nichts aus, wie sich der Code amLive-System verhalt

I Wir sollten eigentlich das Zusammenspiel aller Module testen(Forge und eigene)

Page 33: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Was haben wir geplant?

I r10k fur Deployment(https://github.com/adrienthebo/r10k)

I Ein Repository pro Module

I Nur interne Module bleiben im Hauptrepo

I Acceptance Tests mit Beaker

Page 34: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Links und Bucher

I http://github.com/tosmi/linuxwochen2014

I http://github.com/tosmi/puppet-devel

I Puppet Learning VM: http://puppetlabs.com/download-learning-vm

I Foreman: http://theforeman.org

I Vagrant: http://vagrantup.com

I rspec-puppet: http://rspec-puppet.com/

I puppet-lint: http://puppet-lint.com/

I Gitolite: http://gitolite.com/

I r10k: https://github.com/adrienthebo/r10k

I Roles and Profiles: http://www.craigdunn.org/2012/05/239/

I Dynamische Puppet Umgebungen:http://puppetlabs.com/blog/git-workflow-and-puppet-environments

I puppet-sync: https://github.com/pdxcat/puppet-sync

I Instant Puppet 3 Starter

I Pro Puppet 2nd

I The RSpec Book

I Pulling Strings with Puppet

I Continuous Delivery

Page 35: System Automation mit Puppet und Foremanschmidbauer.cc/files/foreman_puppet_development2014.pdf · rspec-puppet I Ruby RSpec Tests f ur Puppet I Jedes Module muss RSpec Tests mitbringen

Danke fur die Aufmerksamkeithttp://stderr.at/foreman_puppet_development2014.pdf