37
DevOps Meeting Karlsruhe 13.11.2014

DevOps Meeting Karlsruhe, 13.11.2014

Embed Size (px)

Citation preview

DevOps MeetingKarlsruhe

13.11.2014

Heute

• Kennenlernrunde

• Kleine Einführung in DevOps, Chef & Vagrant

• Offene Diskussion

Was ist DevOps?• „Set von Paradigmen“

• „No more Run-Books!“

• „You build it, you run it!“

• „Infrastructure as Code“

• „Automate Everything!“

Warum Configuration Management?

• Wir wollen Reproduzierbarkeit, Automatisierung

• Portabilität?

• Infrastruktur als Code ermöglicht

• Versionierung!

• Testing (Continuous Integration / Delivery?)

• Einsatz von Frameworks

Configuration Management Tools

Am Beispiel Chef

Agenda• Übersicht von CM Tools

• Chef Architektur

• Grundkonzepte von Chef

• Chef-Kochbuch-Entwicklung mit Vagrant

• Infrastruktur-Tests mit Serverspec

Übersicht CM Tools• Puppet [Ruby]

• Meines Wissens das erste Tool

• Chef [Ruby]

• Wir haben’s auf Empfehlung benutzt

• Ansible [Python, YAML]

• Sehr schlank - andere finden’s toll

Und drumrum…• VirtualBox [Oracle]

• Open Source Virtualisierung

• Vagrant [Ruby]

• „Fernsteuerung“ für VirtualBox

• Packer [Go]

• Image-Bau

Chef Architektur

• Client-Server Ansatz

• Kann in „standalone“ Modus betrieben werden

• Node = zu provisionierende (virtuelle) Maschine

„Standalone“

Nodegit clone

Git Repository

Chef Kochbücherchef-solo run

Chef Server

Node

Chef ServerNodeNodeNodeNode

Entwickler

knife upload

chef-clie

nt run

Grundkonzepte von Chef• „Deklarative“ Zustandsbeschreibung

• „Wie soll’s am Ende aussehen?“

• Idempotenz —> Konvergenz

• f(f(x)) = f(x)

• Pull-Mechanismus

• Nodes holen ihre Konfiguration ab

Chef-Client Installation

Kochbücher• Ein Kochbuch ist eine Verzeichnisstruktur

• Attribute

• Rezepte

• Templates

• Metadaten

!"" cookbook_name    #"" attributes $ !"" default.rb   #"" recipes $ !"" default.rb   #"" templates $ !"" default $ !"" template.erb !"" metadata.rb

Attribute

• Attribute beinhalten Konfigurationswerte

• können vielfältig überschrieben werden

• stehen in Rezepten & Templates zur Verfügung

default['apache']['root_dir'] = '/var/apache' default['apache']['vhosts_config_dir'] = 'vhosts.d' default['apache']['listen_ports'] = [80]

Rezepte• Rezepte sind die Zustands-Beschreibungen

• Formuliert in Form von Ressourcen

• werden in der Reihenfolge des Auftretens ausgeführt

• Ressourcen wissen, „wie’s geht“

• Kochbuch kann mehrere Rezepte enthalten

• Rezepte können sich untereinander aufrufen

jar_path = '/var/tika/tika/tika.jar' tmp_path = '/tmp/tika.tar.gz' tika_version = #{node['tika']['tika_version']} remote_file tmp_path do source 'http://www.tika.org/download' action :create_if_missing not_if { File.exists?(jar_path) } end directory node['tika']['base_dir'] do mode 0755 action :create end execute "install-tika-#{tika_version}" do command "mv #{tmp_path} #{node['tika']['base_dir']}/; chown -R tika:tika #{node['tika']['base_dir']}" not_if { File.exists?(jar_path) } end execute "tika start" do command "java -jar #{jar_path} -t --server --port 12345" end

Templates

• Templates sind „Dateivorlagen“

• Können mit Variablen „gefüllt“ werden

• Können einfache Logik enthalten

• Ruby .erb files

<VirtualHost <%= vhost[:name_virtual_host] || '*' %>> ServerName <%= vhost[:server_name] %> DocumentRoot <%= vhost[:document_root] %> DirectoryIndex index.html index.htm index.php <Directory <%= vhost[:document_root]%>> Options FollowSymlinks AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>

Chef Config (client.rb)

• Beinhaltet Konfiguration für Chef Client

• Speicherort(e) für Cache Files

• Speicherort für Kochbücher

• Speicherort für Rollen

file_cache_path "/var/chef-cache" cookbook_path [ # "/var/chef/cookbooks", # „/var/chef/site-cookbooks“] role_path "/var/chef/roles"

Chef Run• Ausgeführt durch chef-client

• Als Daemon auf Node

• Per CRON

• „Von Hand“

• Auch converging genannt

sudo /usr/local/bin/chef-client \ -z -o recipe[apache] -c /var/chef/zero.rb

Rollen

• Beschreiben die Rolle eines Nodes

• Beinhalten eine Run-List (welche Rezepte)

• Können Attribute überschreiben

{ # "name": "jenkins", "description": „Set up Jenkins", "run_list":[ "recipe[tomcat]", "recipe[jenkins]" ] }

sudo /usr/local/bin/chef-client \ -z -o role[jenkins] -c /var/chef/zero.rb

Chef-Entwicklung• Virtualisierung durch VirtualBox & Vagrant

• vagrant up#

• Box runterladen, importieren und booten

• vagrant provision#

• Laufende Box neu provisionieren

Vagrant.configure("2") do |config|# config.vm.define :vagrantbox, primary: true do |vagrantbox|#! vagrantbox.vm.box = "ubuntu-box"# vagrantbox.vm.box_url = "http://vagrantbox.es/ubuntu-box"#! vagrantbox.vm.provider "virtualbox" do |v|# v.name = “Ubuntu-Box"# v.customize ["modifyvm", :id, "--memory", 2048, "--cpus", 2]# end#! vagrantbox.vm.hostname = "vagrant.localhost"# vagrantbox.vm.network :private_network, ip: "10.20.30.40", netmask: "255.255.255.0"#! vagrantbox.vm.provision :shell do |s|# s.inline = "sudo /usr/local/bin/chef-client -z -o role[jenkins] -c /var/chef/zero.rb"# end#! end#end

Chef KochbücherEntwickler

Virtueller Node

vagrant up

import image start machine

run chef-solo

develop recipes vagrant provision

git push

Git Repository

git pull

ServerSpec• Akzeptanz-Tests für Chef

• Beschreibung des SOLL-Zustands

• Rot, wenn IST ≠ SOLL

• „Von außen“ über SSH

• „Von innen“, z.B. über Busser

describe user('codecoon') do it {should exist} end#

!

describe file('/…/typo3_src-6.1.7') do it {should be_directory} end

Continuous Integration

Fragen?