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

966 views

Published on

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

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

  1. 1. Greenfield Puppet David Danzilio @djdanzilio
  2. 2. $(whoami)
  3. 3. What’s this all about?
  4. 4. A collection of wisdom that I wish I had available when I first started using Puppet
  5. 5. This could change in future releases
  6. 6. Don’t just take my word for it
  7. 7. – Wikipedia “a greenfield is a project that lacks any constraints imposed by prior work”
  8. 8. A (not so) hypothetical scenario…
  9. 9. Department of BasketweavingFUFoo University
  10. 10. 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’],! ]! }! }
  11. 11. I want to use Graphite for all my! basket data
  12. 12. OH NOES!
  13. 13. –Doug McIlroy “Write programs that do one thing and do it well. Write programs to work together.”
  14. 14. Modules
  15. 15. Don’t write modules unless you absolutely have to!
  16. 16. Check the Forge first
  17. 17. 2,617
  18. 18. Don’t customize Forge modules!
  19. 19. Use the Roles and Profiles pattern
  20. 20. Roles and Profiles
  21. 21. Craig Dunn’s blog post: “Designing Puppet – Roles and Profiles”
  22. 22. A node includes one role
  23. 23. node db01.example.com { include role::db::server } ! node db02.example.com { include role::db::server::dev }
  24. 24. A role includes one or more profiles
  25. 25. 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 }
  26. 26. A profile manages modules
  27. 27. class profile::mysql { ! $mysql_version = hiera(‘mysql_version’) ! class { ‘mysql::server’: package_ensure => $mysql_version } ! class { ‘mysql::backup’: } class { ‘nagios::mysql’: } ! }
  28. 28. Like MVC for Puppet
  29. 29. The Forge
  30. 30. Look for modules with lots of downloads and recent updates
  31. 31. Lots of downloads Recent update
  32. 32. Do some background research on the author of the module
  33. 33. Give priority to modules written by Puppet Labs
  34. 34. Be weary of modules with strange dependencies
  35. 35. WHY!??!?!
  36. 36. Don’t use a module without vetting it
  37. 37. Puppet Deployment
  38. 38. Have a solid deployment pipeline
  39. 39. Use librarian-puppet or r10k to deploy your code to your Puppet masters
  40. 40. Reliable metadata is key to a successful Puppet deployment
  41. 41. $ cat /etc/facter/facts.d/metadata.json { "datacenter": "Boston", "rack": "R23", "role": "webserver", "cluster": "C89" }
  42. 42. Use environments to keep your nodes safe
  43. 43. Understand the lifecycle of a module
  44. 44. Use Hiera from the start
  45. 45. Don’t get too crazy with your hierarchy
  46. 46. :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}”
  47. 47. Puppet Development
  48. 48. Puppet code is real code
  49. 49. Puppet is Ruby
  50. 50. Puppet modules need a design specification
  51. 51. rspec-puppet for TDD
  52. 52. Design modules with other people in mind
  53. 53. Fail fast
  54. 54. fail(“${::osfamily} is not supported by this module.”)
  55. 55. Public classes should expose a stable API
  56. 56. Semantic Versioning is your friend
  57. 57. Major.Minor.Patch
  58. 58. X.0.0
  59. 59. 0.X.0
  60. 60. 0.0.X
  61. 61. Remember the UNIX philosophy
  62. 62. Share your custom modules with the community!
  63. 63. Manage your dependencies with care
  64. 64. Keep artifacts out of your Puppet modules
  65. 65. Embedding data makes your modules less modular
  66. 66. class foo ( $pkg_version = $foo::params::pkg_version, $pkg_name = $foo::params::pkg_name, ) inherits foo::params { ! ... ! }
  67. 67. Keep business logic out of templates
  68. 68. <% if @app == ‘foo’ %> ... <% else %> ... <% end %>
  69. 69. $template = ? $app { ‘foo’ => ‘foo.conf.erb’, default => ‘generic.conf.erb’, } ! file { ‘/path/to/app.conf’: ensure => file, content => template(“module/${template}”), }
  70. 70. Standard Library
  71. 71. Use the standard library to level-up your modules
  72. 72. Avoid duplicate resources with ensure_packages and ensure_resource
  73. 73. package { ‘apache2’: ensure => present, }
  74. 74. ensure_packages([‘apache2’])
  75. 75. Validate inputs with validate_array, validate_bool, validate_hash, validate_re, and validate_string
  76. 76. Protect private classes with private
  77. 77. Modules should be easy to use and hard to abuse
  78. 78. Style Substance
  79. 79. Style is important
  80. 80. puppet-lint
  81. 81. puppet-syntax
  82. 82. source 'https://rubygems.org' ! gem 'rake' gem 'puppet' gem 'puppet-lint' gem 'puppet-syntax'
  83. 83. 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
  84. 84. $ 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.
  85. 85. $ bundle exec rake -T rake lint # Run puppet-lint rake syntax # Syntax check Puppet manifests and rake syntax:hiera # Syntax check Hiera config files rake syntax:manifests # Syntax check Puppet manifests rake syntax:templates # Syntax check Puppet templates
  86. 86. Documentation is important
  87. 87. We’re all Keynesians now. developers
  88. 88. Keeping Up
  89. 89. Puppet is evolving really fast
  90. 90. There is a fantastic community out there
  91. 91. Pay attention to thought leaders
  92. 92. Refactor your code as the language evolves
  93. 93. Contribute to modules on the Forge!
  94. 94. Questions?
  95. 95. Thank you!
  96. 96. 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
  97. 97. 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

×