30
Programmare Infrastrutture IT con Puppet Alessandro Franceschi / Lab42

Developing IT infrastructures with Puppet

Embed Size (px)

DESCRIPTION

An introduction to DevOps, Configuration Management Software and Puppet logic and language.

Citation preview

Page 1: Developing IT infrastructures with Puppet

Programmare Infrastrutture IT con PuppetAlessandro Franceschi / Lab42

Page 2: Developing IT infrastructures with Puppet

Infrastructure progressiocum Puppet

Alessandro Franceschi / Lab42CodeMotion 2012 Roma

Creative Commons BY-NC-SA 3.0

IT Infrastructures development with Puppet

Page 3: Developing IT infrastructures with Puppet

From Opsto DevOps

Page 4: Developing IT infrastructures with Puppet

Tempus fugitFlexible... elastic... scalableWhat’s behind these cloudy words?

Page 5: Developing IT infrastructures with Puppet

Panta rei Automation is a matter of survival

Page 6: Developing IT infrastructures with Puppet

Alea iacta estOps like automation!

( since Bourne shell ... )

Page 7: Developing IT infrastructures with Puppet

Errarehumanum estFrom a bunch of custom scripts

to Standard Integrated Tools

Page 8: Developing IT infrastructures with Puppet

Factotum

Have you heard about this Puppet|Chef | CfEngine stuff?

Page 9: Developing IT infrastructures with Puppet

Doctum docesInfrastructure as code

Page 10: Developing IT infrastructures with Puppet

Scripta manent,verba volantServers Infrastructure Change under...

version control!

Page 11: Developing IT infrastructures with Puppet

Repetitia iuvantCode behaves always in the same way:

Consistent setups

Page 12: Developing IT infrastructures with Puppet

Ignorantia legis non excusatCode can be tested.

Infrastructure Code too.

Page 13: Developing IT infrastructures with Puppet

Mastersof Puppet

Page 14: Developing IT infrastructures with Puppet

GratisOpenSource from www.puppetlabs.com

Page 15: Developing IT infrastructures with Puppet

Cui prodest?

Source: www.puppetlabs.com

Page 16: Developing IT infrastructures with Puppet

Divide et ImperaMany Puppet nodes One Puppet Master

ServerUser: puppet

Process: /usr/bin/ruby /usr/sbin/puppetmasterdListen: TCP 0.0.0.0:8140

ClientsUser: rootProcess: /usr/bin/ruby /usr/sbin/puppetd -t

Page 17: Developing IT infrastructures with Puppet

Status Quo

“A declarative language to describe system status”

package { 'openssh-server': ensure => present, before => File['/etc/ssh/sshd_config'], } file { '/etc/ssh/sshd_config': ensure => file, mode => 600, source => '/root/learning-manifests/sshd_config', } service { 'sshd': ensure => running, enable => true, subscribe => File['/etc/ssh/sshd_config'], }

A declarative language

Page 18: Developing IT infrastructures with Puppet

Veni vidi vici

Page 19: Developing IT infrastructures with Puppet

Ex AequoOperating System Abstraction

Page 20: Developing IT infrastructures with Puppet

DeusExMachina

# This File is Managed by Puppet

Page 21: Developing IT infrastructures with Puppet

Mater semper certa est,pater nunquamO: Who changed that file?!

info: Filebucket[/var/lib/puppet/clientbucket]: Adding /etc/resolv.conf(d7fbc1695489ce896d30b7b04d72887c)info: //test/File[/etc/resolv.conf]: Filebucketed /etc/resolv.conf to main with sum d7fbc1695489ce896d30b7b04d72887c

Old file is copied in:/var/lib/puppet/clientbucket/d/7/f/b/c/1/6/9/d7fbc1695489ce896d30b7b04d72887c/content

Page 22: Developing IT infrastructures with Puppet

Enough graphics, show me some

Puppet code!

Page 23: Developing IT infrastructures with Puppet

Nodes definitionsIn Puppet code:/etc/puppet/manifests/site.pp

node 'prod-fep-1' { $status = "prod" include role_fep}

node 'prod-fep-2' { $status = "prod" include role_fep}

node 'test-fep-1' { $status = "test" include role_fep}

node 'dev-fep-1' { $status = "dev" include role_fep}

[...]

On an External Node Classifier (ENC)

The Foreman

Puppet Dashboard

Puppet Enterprise Console

Page 24: Developing IT infrastructures with Puppet

Classes (collections of resources)class role_fep { $role="fep"

include general # We see it in the next slide

include apache include php::pear include php::dev include php::oci8 apache::module { "rewrite": } apache::module { "proxy": templatefile => "proxy.conf.erb" } php::module { "gd": } php::pear::module { "apc": } php::pear::module { "XML_Serializer": use_package => "no" } php::pecl::config { "http_proxy": value => "$proxy_server" } [...]

# Sample custom files file { ‘/data’: ensure => directory, } file { ‘/data/www’: ensure => $::operatingsystem ? { /(?i:Centos|RedHat|Scientific|Fedora)/ => ‘/var/www/html’, /(?i:Debian|Ubuntu|Mint)/ => ‘/var/www’, }, require => File[‘/data’]: }}

Page 25: Developing IT infrastructures with Puppet

Classes ( a baseline common to all nodes ) class general {

include puppet include users include openssh include hosts include resolver include sudo include snmpd include nrpe include munin

case $::operatingsystem { ubuntu,debian: { include apt include exim } centos,redhat: { include yum } default: { } }

}

Page 26: Developing IT infrastructures with Puppet

Modules - Directory layout/etc/puppet/modules/ ($modulepath)

apache/

apache/manifests/ apache/manifests/init.pp apache/manifests/module.pp

apache/lib/ apache/lib/puppet/ apache/lib/puppet/parser/ apache/lib/puppet/parser/functions apache/lib/puppet/provider/ apache/lib/puppet/type/ apache/lib/facter/ apache/templates/

apache/files/

apache/spec/ apache/spec/classes/ apache/spec/defines/

apache/Modulefile

apache/README.md

Puppet Manifests ( code in the Puppet DSL )

Static filesErb Templates (files with dynamic content)

Puppet extensions ( code in Ruby )

One Application, One Module, One class

Rspec tests

Module’s metadata for the Puppet Forge

Page 27: Developing IT infrastructures with Puppet

Modules - Files autoloading

class autofs {

package { autofs: ensure => present, }

service { autofs: ensure => running, enable => true, }

file { "auto.homes": path => “/etc/auto.homes”, source => "puppet://$servername/modules/autofs/auto.homes" }

}

class autofs {

[...]

file { "/etc/auto.master": content => template("autofs/auto.master.erb") }

}

Sourced (static) files are searched in:$modulepath/autofs/files/auto.homes

Templates (Ruby ERB) are searched in:$modulepath/autofs/templates/auto.master.erb

Page 28: Developing IT infrastructures with Puppet

LINKSfor a better living

https://bitly.com/wnvqaN - How to start with Puppet - Useful links

http://puppetlabs.com/community/puppet-camp/ - PuppetCamps

http://www.example42.com/ - Example42 Puppet modules ( disclaimer ;-)

http://docs.puppetlabs.com/ - PuppetLabs documentation

http://planetpuppet.org/ - Planet Puppet - Feeds aggregator

Page 29: Developing IT infrastructures with Puppet

A new language to learnEffectiveness needs practice

If there’s code , there are bugsMake Puppet the Enforcer not the Violator

Discipline in Systems managementMore time to make things done (the first time)

Great Power gives Great Responsibilities

Automated Systems Setups Coherent InfrastructureTrack and History of ChangeInstallations ReplicabilityQuick propagation of changes Aligned Environments for Test/[...]/ProdAutomated monitoring

DO UT DES

Page 30: Developing IT infrastructures with Puppet

ad maiora

Graphics: www.tatlin.net

Questions?

@alvagante