Konfigurationsmanagement mit Opscode Chef

53
Konfigurationsmanagement mit Chef 1 / 47 Konfigurationsmanagement mit Chef Konrad F. Heimel Zentrum für Informations- und Medientechnologie, Universität Siegen 8. September 2014

Transcript of Konfigurationsmanagement mit Opscode Chef

Page 1: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 1 / 47

Konfigurationsmanagement mit Chef

Konrad F. Heimel

Zentrum für Informations- und Medientechnologie, Universität Siegen

8. September 2014

Page 2: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 2 / 47

Warum eigentlich Konfigurationsmanagment?

Inhalt

1 Warum eigentlich Konfigurationsmanagment?Das Project EduprobeLösungsmöglichkeiten

2 Welches Konfigurationsmanagmentsystem ist das Beste?

3 Einführung in Opscode Chef

4 Die Begriffswelt von Chef

5 Ein paar unserer Cookbooks

Page 3: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 3 / 47

Warum eigentlich Konfigurationsmanagment?

Das Project Eduprobe

Eduprobes

Ziel

Messung der Verfügbarkeit von Eduroam in den Liegenschaften mitRaspberry Pi’s

Page 4: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 4 / 47

Warum eigentlich Konfigurationsmanagment?

Das Project Eduprobe

Abbildung: Die Cacti-Graphen der Eduprobe-AR

Page 5: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 5 / 47

Warum eigentlich Konfigurationsmanagment?

Konfigurationsaufwand

Pro Gerät zu konfigurieren

SSH, public keysNTP, DNS ServerRaspian RepositorySNMPDfail2banWeitere Packete müssen installiert werden:

macchangerwpasupplicantsyslog-ng

Die Skripte zum messen von Eduroam und zur Bereitstellungder Messwerte via SNMPDcronjobs

Page 6: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 6 / 47

Warum eigentlich Konfigurationsmanagment?

Lösungsmöglichkeiten

Warum kein “Golden Image“?

Nachträgliche ÄnderungenVeraltet sehr schnellBlack Box

Page 7: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 7 / 47

Warum eigentlich Konfigurationsmanagment?

Lösungsmöglichkeiten

Warum nicht Skripten?

Für andere schwer nachzuvollziehenHoher AufwandWarum das Rad neu erfinden?

Page 8: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 8 / 47

Warum eigentlich Konfigurationsmanagment?

Lösungsmöglichkeiten

$ knife bootstrap eduprobe-ar -d raspbian -N eduprobe-ar -x pi -r’ role[eduprobe]’ –sudo

Mit einer Zeile

Chef-Client

SSH, public keys

NTP, DNS Server

Raspian Repository

SNMPD

fail2ban

alle notwendigen Pakete werden installiert

Skripte werden kopiert

cronjobs

Page 9: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 9 / 47

Welches Konfigurationsmanagmentsystem ist das Beste?

Inhalt

1 Warum eigentlich Konfigurationsmanagment?

2 Welches Konfigurationsmanagmentsystem ist das Beste?Die vier verbreitetesten KonfigurationsmanagementsystemeEckdatenPopularitätsvergleich

3 Einführung in Opscode Chef

4 Die Begriffswelt von Chef

5 Ein paar unserer Cookbooks

Page 10: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 10 / 47

Welches Konfigurationsmanagmentsystem ist das Beste?

Die vier verbreitetesten Konfigurationsmanagementsysteme

Die vier verbreitetesten Konfigurationsmanagementsysteme

Page 11: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 11 / 47

Welches Konfigurationsmanagmentsystem ist das Beste?

Eckdaten

Eckdaten

Grundlegendesbasiert auf der Erstes Wechselseitige

Lizenz Sprache Release Auth. Encrypt.Puppet GPL Ruby 2005-08-30 Ja JaChef Apache Ruby 2009-01-15 Ja Ja

Ansible Apache Python 2012-03-08 Ja JaSalt Apache Python 2011-03-17 Ja Ja

KompatibilitätLinux Mac OS X Windows Solaris *BSD

Puppet Ja Ja Teilweise Ja JaChef Ja Ja Ja Ja Ja

Ansible Ja Ja Ja Ja JaSalt Ja Ja Ja Ja Ja

Page 12: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 12 / 47

Welches Konfigurationsmanagmentsystem ist das Beste?

Popularitätsvergleich

Popularitätsvergleich

Chef ist hier unterrepräsentiert, da die präferierte Installationsmethode sog. ruby-gemssind

Quelle: http://redmonk.com/sogrady/2013/12/06/configuration-management-2013/

Page 13: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 13 / 47

Welches Konfigurationsmanagmentsystem ist das Beste?

Popularitätsvergleich

Quelle: http://redmonk.com/sogrady/2013/12/06/configuration-management-2013/

Page 14: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 14 / 47

Welches Konfigurationsmanagmentsystem ist das Beste?

Popularitätsvergleich

Quelle: http://redmonk.com/sogrady/2013/12/06/configuration-management-2013/

Page 15: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 15 / 47

Welches Konfigurationsmanagmentsystem ist das Beste?

Popularitätsvergleich

Fazit:

Puppet ist Marktführer, dicht gefolgt von Chef

Anisble und Salt sind sehr wachstumsstarkDie Entscheidung ist daher vor allem eine Geschmacksfrage

Page 16: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 15 / 47

Welches Konfigurationsmanagmentsystem ist das Beste?

Popularitätsvergleich

Fazit:

Puppet ist Marktführer, dicht gefolgt von ChefAnisble und Salt sind sehr wachstumsstark

Die Entscheidung ist daher vor allem eine Geschmacksfrage

Page 17: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 15 / 47

Welches Konfigurationsmanagmentsystem ist das Beste?

Popularitätsvergleich

Fazit:

Puppet ist Marktführer, dicht gefolgt von ChefAnisble und Salt sind sehr wachstumsstarkDie Entscheidung ist daher vor allem eine Geschmacksfrage

Page 18: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 16 / 47

Einführung in Opscode Chef

Inhalt

1 Warum eigentlich Konfigurationsmanagment?

2 Welches Konfigurationsmanagmentsystem ist das Beste?

3 Einführung in Opscode ChefEinige FaktenPrinzipien

4 Die Begriffswelt von Chef

5 Ein paar unserer Cookbooks

Page 19: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 17 / 47

Einführung in Opscode Chef

Opscode Chef

Page 20: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 18 / 47

Einführung in Opscode Chef

Einige Fakten

Initial release: 15.1.2009Basiert auf der Programmiersprache RubySupport für Linux, Windows, Mac OS, Solaris und FreeBSD10,000+ Nodes auf einem Chef-Server managenOpen-Source-Chef ist kostenlos (es gibt aber auch eineCloud-Option namens “Hosted Chef“Chef wird z.B. benutzt von Mozilla, Facebook, HP PublicCloud

Page 21: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 19 / 47

Einführung in Opscode Chef

Prinzipien

Prinzipien

IdempotentReasonabilitySane defaultsHackabilityTMTOWTDI

Page 22: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 20 / 47

Die Begriffswelt von Chef

Inhalt

1 Warum eigentlich Konfigurationsmanagment?

2 Welches Konfigurationsmanagmentsystem ist das Beste?

3 Einführung in Opscode Chef

4 Die Begriffswelt von ChefChef-ClientChef-ServerChef-SoloKnifeAttributeRolleRezeptRessourceProviderCookbook

5 Ein paar unserer Cookbooks

Page 23: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 21 / 47

Die Begriffswelt von Chef

Chef-Client

Chef-Client läuft auf den Clients, also z.B. denEduprobes.

Ein Client nennt sich dabei aber Node.

Page 24: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 22 / 47

Die Begriffswelt von Chef

Chef-Server

1 kheimel@vagrantbox:~$ sudo chef-client2 [sudo] password for kheimel:3 Starting Chef Client, version 11.8.24 resolving cookbooks for run list: ["debian-minimal", "motd"]5 Synchronizing Cookbooks:6 - motd7 - debian-minimal8 Compiling Cookbooks...9 Converging 25 resources

10 Recipe: debian-minimal::default11 * user[assmann] action create (up to date)12 * directory[/home/assmann/.] action create (up to date)13 * directory[/root/.ssh/] action create (up to date)14 * service[ssh] action reload15 - reload service service[ssh]16 * service[fail2ban] action reload17 - reload service service[fail2ban]18 * cron[chef-client] action create (up to date)19 ...20 Recipe: motd::default21 ...22 Chef Client finished, 2 resources updated

Page 25: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 22 / 47

Die Begriffswelt von Chef

Chef-Server

Chef-Client authentifiziert dabei beimChef-Server

Page 26: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 23 / 47

Die Begriffswelt von Chef

Chef-Server

Abbildung: Die Chef-Server WebGui

Page 27: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 24 / 47

Die Begriffswelt von Chef

Chef-Solo

Es funktioniert aber auch ganz ohne Chef-Serveroder Opscodes Hosted Chef mit Chef-Solo

Page 28: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 25 / 47

Die Begriffswelt von Chef

Knife

Dass Command-Line-Tool Knife ist die Schnittstellezum Chef-Server

Page 29: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 26 / 47

Die Begriffswelt von Chef

Knife

Mit Knife lassen sich

Nodes und Clients verwaltenCookbooks und Rezepte erstellen und hochladenRollen definieren und anwendenChef auf Nodes installieren und konfigurierenAttribute anzeigen und suchenuvm.

Page 30: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 27 / 47

Die Begriffswelt von Chef

Knife

Die Nodes haben AttributeDiese werden automatisch während jedem Chef-Client-Run

mit dem Tools Ohai aktualisiert.

Page 31: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 28 / 47

Die Begriffswelt von Chef

Knife

Abbildung: Nur ein kleiner Ausschnitt der verfügbaren Attribute

Page 32: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 29 / 47

Die Begriffswelt von Chef

Attribute

Die Attribute sind natürlich suchbar

Page 33: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 30 / 47

Die Begriffswelt von Chef

Attribute

1 knife search node ’etc_passwd:alex’ -a etc.passwd.alex.uid2 10 items found3

4 ah-mon:5 etc.passwd.alex.uid: 10016

7 us-mon:8 etc.passwd.alex.uid: 10019

10 eduprobe-ae:11 etc.passwd.alex.uid: 100212

13 chefserver:14 etc.passwd.alex.uid: 100215

16 eduprobeh:17 etc.passwd.alex.uid: 100218

19 eduprobe-ar:20 etc.passwd.alex.uid: 100221

22 enc-mon:23 ...

Page 34: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 30 / 47

Die Begriffswelt von Chef

Attribute

Beispiel

knife ssh -x uname︸ ︷︷ ︸Username

–attribute ipaddress︸ ︷︷ ︸uname@ipadress statt uname@fqdn

tags:vsphere︸ ︷︷ ︸Suchparameter

“sudo chef-client“

Das Kommando sudo chef-client wird auf allen Nodes mit dem Tag vsphereausgeführt.

Page 35: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 31 / 47

Die Begriffswelt von Chef

Attribute

Nodes haben eine Runlist.Rollen oder Rezepte werden hier nacheinander angewandt.

Page 36: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 32 / 47

Die Begriffswelt von Chef

Attribute

1 knife node show eduprobe-ar2 Node Name: eduprobe-ar3 Environment: _default4 FQDN: eduprobe-ar5 IP: 10.5.71.106 Run List: role[eduprobe]7 Roles: eduprobe8 Recipes: eduprobe, motd, makeusers, eduprobe::default,9 logrotate::default, motd::default, makeusers::default

10 Platform: raspbian 7.611 Tags: ZIMT, RaspberryPi

Page 37: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 32 / 47

Die Begriffswelt von Chef

Attribute

Eine Rolle besteht aus Rollen und Rezepten

Page 38: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 33 / 47

Die Begriffswelt von Chef

Rezept

In den Rezepten werden Ressourcen verwaltetund definiert.

Page 39: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 34 / 47

Die Begriffswelt von Chef

Rezept

Ausschnitt aus einem Rezept

(später mehr zu Rezepten...)

1 package "wpasupplicant"2 package "macchanger"34 directory "/home/pi/.ssh/" do5 owner "pi"6 group "pi"7 mode 007008 action :create9 end

1011 cookbook_file "authorized_keys" do12 path "/home/pi/.ssh/authorized_keys"13 owner "pi"14 group "pi"15 mode 0060016 action :create17 end1819 cookbook_file "snmpd.conf" do20 path "/etc/snmp/snmpd.conf"21 owner "root"22 group "root"23 mode 0064424 action :create25 end2627 service "snmpd" do28 supports :status => true, :restart => true, :reload => true29 ...

Page 40: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 35 / 47

Die Begriffswelt von Chef

Ressource

Eine Ressource hat

einen Typ

einen Namen

Parameter

sogenannte Actions, diedefinieren, wie eineÄnderung durchgeführtwerden soll

19 cookbook_file "snmpd.conf" do20 path "/etc/snmp/snmpd.conf"21 owner "root"22 group "root"23 mode 0064424 action :create25 end

27 service "snmpd" do28 supports :status => true,29 :restart => true,30 :reload => true31 action :reload32 end

Page 41: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 36 / 47

Die Begriffswelt von Chef

Provider

Ressourcen führen Änderungen mithilfe von sogenannten Providern durch.

Page 42: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 37 / 47

Die Begriffswelt von Chef

Provider

Ressourcen führen Änderungen mithilfe von sogenannten Providern durch.

Page 43: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 38 / 47

Die Begriffswelt von Chef

Provider

Es kann mehrere Provider pro Ressourcentyp geben

Es kann mehrere Provider pro Resourcentyp geben

Z.B. die Ressource Package:Apt, Yum, Rubygems, Portage, Macports, FreeBSD Ports,Pacman, etc.

Kann überschrieben werden mit dem Attribut Provider

1 package "sudo" do2 provider Chef::Provider::Package::Apt3 action: install4 end

Page 44: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 39 / 47

Die Begriffswelt von Chef

Cookbook

Cookbooks sind Pakete für Rezepte und allezugehörigen Objekte

Page 45: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 40 / 47

Die Begriffswelt von Chef

Cookbook

Ordnerstruktur eines Cookbooksattributes

definitions← Definitions sind Code, der in mehereren

Rezepten verwendet werden kann

files ← Dateien

librariesprovidersrecipes ← Rezepteresources

templates← Ruby-Templates, um z.B. Textdateien

zu generieren

CHANGELOG.mdmetadata.rb ← Maintainer, Beschreibung, VersionsnummerREADME.md

Page 46: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 41 / 47

Ein paar unserer Cookbooks

Inhalt

1 Warum eigentlich Konfigurationsmanagment?

2 Welches Konfigurationsmanagmentsystem ist das Beste?

3 Einführung in Opscode Chef

4 Die Begriffswelt von Chef

5 Ein paar unserer Cookbooksmakeusersdebian-defaultDie Rolle MonitoringEine neue Monitoring-Node anlegen

Page 47: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 42 / 47

Ein paar unserer Cookbooks

Was wir zum Beispiel bisher mit Chef gemachthaben

Page 48: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 43 / 47

Ein paar unserer Cookbooks

makeusers

Das Cookbook makeusers

Legt User incl. Passwort an. assmann, alex, kheimelerstellt /home/(username) OrdnerKopiert SSH authorized keys

Löschen von Usern auf allen Maschinen

user "kheimel" doaction :delete

end

Page 49: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 43 / 47

Ein paar unserer Cookbooks

makeusers

Das Cookbook makeusers

Legt User incl. Passwort an. assmann, alex, kheimelerstellt /home/(username) OrdnerKopiert SSH authorized keysLöschen von Usern auf allen Maschinen

user "kheimel" doaction :delete

end

Page 50: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 44 / 47

Ein paar unserer Cookbooks

motd

Das Cookbook motd

Linux us -mon 3.14-1- amd64 #1 SMP Debian 3.14.12 -1(2014 -07 -11) x86_64

_ _ ___ _ __ ___ ___ _ __| | | / __|_____| ’_ ‘ _ \ / _ \| ’_ \| |_| \__ \_____| | | | | | (_) | | | |\__ ,_|___/ |_| |_| |_|\___/|_| |_|

Interface IP -Addresses(IPv4)eth0 10.5.56.20

(IPv6)eth0 fe80 ::21d:9ff:fe6b :913eth1 fe80 ::21d:9ff:fe6b :915

System information as of: Thu Sep 4 13:25:53 CEST2014

System load: 0.00 Memory usage: 3.1%Usage on /: 12% Swap usage: 0.0%Local users: 0

Last login: Thu Sep 4 11:02:26 2014 from192.168.80.154

Page 51: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 45 / 47

Ein paar unserer Cookbooks

debian-default

Das Cookbook debian-default

check-mk-agent-zimt wird installiertsnmpd

fail2ban

dns, ntp → 141.99.2.2

sources.list → 141.99.2.19

Page 52: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 46 / 47

Ein paar unserer Cookbooks

Die Rolle Monitoring

Die Rolle mon

Besteht aus makeusers, motd, debian-default. Zusätzlichwahlweise das Cookbook smokeping-client oder smokepingserver

Fünf physikalische Maschinen sind derzeit produktiv

ah-monar-monenc-monpb-monus-mon

Page 53: Konfigurationsmanagement mit Opscode Chef

Konfigurationsmanagement mit Chef 47 / 47

Ein paar unserer Cookbooks

Eine neue Monitoring-Node anlegen

Ein neuer Monitoring-Node wird mit der folgenden Zeile angelegt:

knife bootstrap pb-mon -d debian︸ ︷︷ ︸Bootstrap-Template

-N pb-mon︸ ︷︷ ︸Nodename

-x root︸ ︷︷ ︸SSH-

Username

-r role[mon]︸ ︷︷ ︸Runlist