puppet camp boston 2014: greenfield puppet: getting it right from the start (beginner)

109
Greenfield Puppet David Danzilio @djdanzilio

Upload: puppet-labs

Post on 10-May-2015

625 views

Category:

Documents


0 download

DESCRIPTION

Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner) given by David Danzilio, Constant Contact

TRANSCRIPT

Page 1: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Greenfield PuppetDavid Danzilio

@djdanzilio

Page 2: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

$(whoami)

Page 3: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

What’s this all about?

Page 4: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

A collection of wisdom that I wish I had available when I first started using Puppet

Page 5: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

This could change in future releases

Page 6: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Don’t just take my word for it

Page 7: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)
Page 8: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

– Wikipedia

“a greenfield is a project that lacks any constraints imposed by prior work”

Page 9: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)
Page 10: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

A (not so) hypothetical scenario…

Page 11: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Department of BasketweavingFU

Foo University

Page 12: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

class apache {! package { [‘apache2’, ‘rails’, ‘libapache2-mod-passenger’]:! ensure => present,! }! file { ‘/etc/apache2/sites-enabled/bw-app.conf’:! ensure => file,! source => ‘puppet:///apache/bw-app.conf',! require => Package[‘apache2’],! }! file { ‘/var/www/bw-app’:! ensure => directory,! owner => www-data,! group => www-data,! source => ‘puppet:///apache/bw-app',! recurse => true,! require => File[‘/etc/apache2/sites-enabled/bw-app.conf’]! }! service { ‘apache2’:! ensure => running,! require => [! File[‘/var/www/bw-app’],! Package[’rails’, ‘libapache2-mod-passenger’],! ]! }!}

Page 13: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

I want to use Graphitefor all my!

basket data

Page 14: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

OH NOES!

Page 15: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)
Page 16: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

–Doug McIlroy

“Write programs that do one thing and do it well. Write programs to work together.”

Page 17: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Modules

Page 18: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Don’t write modules unless you absolutely have to!

Page 19: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)
Page 20: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Check the Forge first

Page 21: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

2,617

Page 22: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Don’t customize Forge modules!

Page 23: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Use the Roles and Profiles pattern

Page 24: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Roles and Profiles

Page 25: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Craig Dunn’s blog post: “Designing Puppet – Roles

and Profiles”

Page 26: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

A node includes one role

Page 27: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

node db01.example.com { include role::db::server } !

node db02.example.com { include role::db::server::dev }

Page 28: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

A role includes one or more profiles

Page 29: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

class role::base { include profile::base } !class role::db::server inherits role::base { include profile::mysql include profile::application::database } !class role::db::server::dev inherits role::base { include profile::mysql include profile::percona }

Page 30: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

A profile manages modules

Page 31: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

class profile::mysql { ! $mysql_version = hiera(‘mysql_version’) ! class { ‘mysql::server’: package_ensure => $mysql_version } ! class { ‘mysql::backup’: } class { ‘nagios::mysql’: } !}

Page 32: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Like MVC for Puppet

Page 33: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

The Forge

Page 34: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Look for modules with lots of downloads and recent

updates

Page 35: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Lots of downloadsRecent update

Page 36: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Do some background research on the author of the

module

Page 37: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Give priority to modules written by Puppet Labs

Page 38: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Be weary of modules with strange dependencies

Page 39: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

WHY!??!?!

Page 40: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Don’t use a module without vetting it

Page 41: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)
Page 42: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Puppet Deployment

Page 43: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Have a solid deployment pipeline

Page 44: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)
Page 45: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Use librarian-puppet or r10k to deploy your code to your

Puppet masters

Page 46: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Reliable metadata is key to a successful Puppet deployment

Page 47: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

$ cat /etc/facter/facts.d/metadata.json { "datacenter": "Boston", "rack": "R23", "role": "webserver", "cluster": "C89" }

Page 48: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Use environments to keep your nodes safe

Page 49: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Understand the lifecycle of a module

Page 50: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Use Hiera from the start

Page 51: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Don’t get too crazy with your hierarchy

Page 52: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

:hierarchy: - “%{::app}/%{::environment}/%{::datacenter}/%{::fqdn}” - “%{::app}/%{::environment}/%{::datacenter}” - “%{::app}/%{::environment}” - “%{::app}” - “%{::cluster}/%{::environment}/%{::datacenter}/%{::fqdn}” - “%{::cluster}/%{::environment}/%{::datacenter}” - “%{::cluster}/%{::environment}” - “%{::cluster}” - “%{::environment}/%{::datacenter}/%{::fqdn}” - “%{::environment}/%{::datacenter}” - “%{::environment}” - “%{::realm}/%{::region}/%{::datacenter}/%{::fqdn}” - “%{::realm}/%{::region}/%{::datacenter}” - “%{::realm}/%{::region}” - “%{::realm}” - “%{::region}” - “%{::datacenter}/%{::rack}/%{::cluster}/%{::fqdn}” - “%{::datacenter}/%{::rack}/%{::cluster}” - “%{::datacenter}/%{::rack}” - “%{::datacenter}” - “%{::rack}” - “%{::cluster}”

Page 53: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Puppet Development

Page 54: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Puppet code is real code

Page 55: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Puppet is Ruby

Page 56: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)
Page 57: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Puppet modules need a design specification

Page 58: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

rspec-puppet for TDD

Page 59: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Design modules with other people in mind

Page 60: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Fail fast

Page 61: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

fail(“${::osfamily} is not supported by this module.”)

Page 62: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Public classes should expose a stable API

Page 63: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Semantic Versioning is your friend

Page 64: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Major.Minor.Patch

Page 65: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

X.0.0

Page 66: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

0.X.0

Page 67: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

0.0.X

Page 68: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Remember the UNIX philosophy

Page 69: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Share your custom modules with the community!

Page 70: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Manage your dependencies with care

Page 71: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Keep artifacts out of your Puppet modules

Page 72: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Embedding data makes your modules less modular

Page 73: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

class foo ( $pkg_version = $foo::params::pkg_version, $pkg_name = $foo::params::pkg_name, ) inherits foo::params { ! ... !}

Page 74: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Keep business logic out of templates

Page 75: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

<% if @app == ‘foo’ %> ... <% else %> ... <% end %>

Page 76: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

$template = ? $app { ‘foo’ => ‘foo.conf.erb’, default => ‘generic.conf.erb’, } !file { ‘/path/to/app.conf’: ensure => file, content => template(“module/${template}”), }

Page 77: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Standard Library

Page 78: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Use the standard library to level-up your modules

Page 79: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Avoid duplicate resources with ensure_packages and ensure_resource

Page 80: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

package { ‘apache2’: ensure => present, }

Page 81: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

ensure_packages([‘apache2’])

Page 82: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Validate inputs with validate_array, validate_bool, validate_hash, validate_re, and validate_string

Page 83: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Protect private classes with private

Page 84: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)
Page 85: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Modules should be easy to use and hard to abuse

Page 86: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

StyleSubstance

Page 87: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Style is important

Page 88: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

puppet-lint

Page 89: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

puppet-syntax

Page 90: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

source 'https://rubygems.org' !

gem 'rake' gem 'puppet' gem 'puppet-lint' gem 'puppet-syntax'

Page 91: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

require 'puppet-lint/tasks/puppet-lint' require 'puppet-syntax/tasks/puppet-syntax' !exclude_paths = [ "pkg/**/*", "vendor/**/*", "spec/**/*", ] !PuppetLint.configuration.ignore_paths = exclude_paths PuppetSyntax.exclude_paths = exclude_paths

Page 92: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

$ bundle install Fetching gem metadata from https://rubygems.org/........ Resolving dependencies... Installing rake 10.3.2 Installing CFPropertyList 2.2.8 Installing facter 2.1.0 Installing json_pure 1.8.1 Installing hiera 1.3.4 Installing rgen 0.6.6 Installing puppet 3.6.2 Installing puppet-lint 0.3.2 Installing puppet-syntax 1.3.0 Using bundler 1.6.2 Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

Page 93: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

$ bundle exec rake -T rake lint # Run puppet-lint rake syntax # Syntax check Puppet manifests and templates rake syntax:hiera # Syntax check Hiera config files rake syntax:manifests # Syntax check Puppet manifests rake syntax:templates # Syntax check Puppet templates

Page 94: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Documentation is important

Page 95: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)
Page 96: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)
Page 97: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

We’re all Keynesians now.developers

Page 98: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Keeping Up

Page 99: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Puppet is evolving really fast

Page 100: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

There is a fantastic community out there

Page 101: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Pay attention to thought leaders

Page 102: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)
Page 103: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Refactor your code as the language evolves

Page 104: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)
Page 105: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Contribute to modules on the Forge!

Page 106: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Questions?

Page 107: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Thank you!

Page 108: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Image Credits• http://officeimg.vo.msecnd.net/en-us/images/MP900430517.jpg • http://imgur.com/gallery/YNI5wud • http://www.reddit.com/r/funny/comments/1jgxtq/new_york_and_boston_the_difference/ • http://openclipart.org/detail/195046/ubuntu-geek-by-stephencuyos-195046 • http://design.ubuntu.com/downloads?metadata=element-logo+brand-ubuntu • http://commons.wikimedia.org/wiki/File:Ruby_on_Rails-logo.png • https://github.com/phusion/passenger • http://kaleidos.net/weapons/apache-webserver/ • http://puppetlabs.com/company/news/media-kit • http://copiousnotes.bloginky.com/2014/06/17/summer-classic-dr-strangelove-2/ • http://imgur.com/iWKad22 • http://cheezburger.com/6230961920 • http://www.craigdunn.org/stuff/puppet_big.png • http://www.quickmeme.com/meme/362un7 • http://programmerryangosling.tumblr.com/image/22790837971 • http://www.quickmeme.com/meme/3sogf9 • http://wall.alphacoders.com/big.php?i=238266

Page 109: Puppet Camp Boston 2014: Greenfield Puppet: Getting it right from the start (Beginner)

Further Reading• http://www.craigdunn.org/2012/05/239/ • https://www.youtube.com/user/PuppetLabsInc/playlists • https://github.com/puppetlabs/puppetlabs-stdlib • http://continuousdelivery.com • http://www.slideshare.net/PuppetLabs/tddforpuppet • http://www.slideshare.net/PuppetLabs/roles-rofiles • http://www.slideshare.net/PuppetLabs/steamlining-

puppetdevelopmentpuppetconfny2014 • http://garylarizza.com/blog/2013/12/08/when-to-hiera/ • http://www.devco.net/archives/2013/12/09/the-problem-with-params-pp.php • http://www.devco.net/archives/2013/12/08/better-puppet-modules-using-hiera-data.php • http://puppet-lint.com • https://github.com/gds-operations/puppet-syntax