Writing and Publishing Puppet Modules

2,081 views

Published on

"Writing and Publishing Puppet Modules" by Colleen Murphy, of Portland State University at Puppet Camp Portland 2014.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,081
On SlideShare
0
From Embeds
0
Number of Embeds
29
Actions
Shares
0
Downloads
51
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Writing and Publishing Puppet Modules

  1. 1. Writing and Publishing Puppet Modules Colleen Murphy, Portland State University freenode: crinkle github: cmurphy
  2. 2. Hello This is a beginner’s approach. This is an outsider’s approach.
  3. 3. Hello PSU’s College of Engineering’s IT department, aka The Computer Action Team (TheCAT), uses puppet to manage a diverse infrastructure. http://github.com/pdxcat
  4. 4. What is a puppet module? ● An encapsulation of configuration for a service ● A structure containing an organized set of puppet code and data ● Analogous to a package, gem, python library ● The place where your code goes
  5. 5. What should a module do? ● Set up a service, such as: ○ ssh ○ mysql ○ apache ○ sudo ● Extend puppet functionality. Examples: ○ puppetlabs/stdl ib ○ puppetlabs/concat
  6. 6. The strategy Set up the service… without puppet. Then iterate.
  7. 7. Layout of a module yourmodule/ ➔ ➔ ➔ ➔ ➔ ➔ manifests/ files/ templates/ lib/ | tests/ spec/ # # # # where your puppet code goes flat configuration files dynamic configuration files plugins: types and providers, functions, facts, etc # example usage, smoke tests # automated tests
  8. 8. Layout of a module yourmodule/ ➔ ➔ ➔ ➔ ➔ ➔ manifests/ files/ templates/ lib/ | tests/ spec/ # # # # where your puppet code goes flat configuration files dynamic configuration files plugins: types and providers, functions, facts, etc # example usage, smoke tests # automated tests
  9. 9. Starting out # puppet module generate cmurphy-ssh Generating module at /etc/puppet/modules/cmurphy-ssh cmurphy-ssh cmurphy-ssh/manifests cmurphy-ssh/manifests/init.pp cmurphy-ssh/spec cmurphy-ssh/spec/spec_helper.rb cmurphy-ssh/tests cmurphy-ssh/tests/init.pp cmurphy-ssh/README cmurphy-ssh/Modulefile
  10. 10. Writing your first module class ssh { package { 'openssh-server': ensure => installed, } file { '/etc/ssh/sshd_config': source => "puppet:///modules/ssh/sshd_config", require => Package['openssh-server'], } service { 'ssh': ensure => running, enable => true, subscribe => File['/etc/ssh/sshd_config'], } } node default { include ssh }
  11. 11. Drop in a configuration file # Managed by Puppet # What ports, IPs and protocols we listen for Port 22 Protocol 2 # Logging SyslogFacility AUTH LogLevel INFO # Authentication: LoginGraceTime 120 PermitRootLogin no StrictModes yes ...
  12. 12. Needs more portability! No one should have to change your code or your files in order to use your module.
  13. 13. Update your module # Managed by Puppet # What ports, IPs and protocols we listen for Port <%= @port %> Protocol 2 # Logging SyslogFacility <%= @syslog_facility %> LogLevel <%= @log_level %> # Authentication: LoginGraceTime 120 PermitRootLogin <%= @permit_root_login %> StrictModes yes ...
  14. 14. Update your module class ssh ( $port = 22, $syslog_facility = 'AUTH', $log_level = 'INFO', $permit_root_login = 'no', ) { ... file { '/etc/ssh/sshd_config': content => template('ssh/sshd_config.erb'), require => Package['openssh-server'], } ... node default { class { 'ssh': permit_root_login => 'yes', } }
  15. 15. Beyond templates Working with tricky configuration files ● Take advantage of Include conf/* directives file { 'conf_file': ensure => present, content => 'Include "conf.d/*.conf"n', } … define collectd::plugins::exec { file { "${name}.load": path => "${conf_dir}/${name}.conf", content => template('collectd/exec.conf.erb'), } }
  16. 16. Beyond templates ● puppetlabs/concat concat { '/etc/motd': } concat::fragment { 'welcome': target => '/etc/motd', content => 'Welcome to Redhat', order => '01', } concat::fragment { 'legal': … }
  17. 17. Beyond templates ● puppetlabs/inifile ini_setting { 'puppetdbserver': ensure => present, section => 'main', path => "${puppet_confdir}/puppetdb.conf", setting => 'server', value => $server, } ini_setting { 'puppetdbport': … }
  18. 18. Parameterize your module class ssh::params { case $::osfamily { 'Debian': { $ssh_svc = 'ssh' class ssh ( ... ) { include ssh::params } 'Redhat': { $ssh_svc = 'sshd' } default: { fail("${::osfamily} is not supported.") } } } service { $ssh::params::ssh_svc: ensure => running, enable => true, } ...
  19. 19. The Forge
  20. 20. Publishing your module Modulefile name 'cmurphy-ssh' version '0.0.1' source 'https://github.com/cmurphy/puppet-module-ssh.git' author 'Colleen Murphy' license 'Apache License, Version 2.0' summary 'Puppet module for ssh' description 'Demonstration of parameterized ssh module' project_page 'https://github.com/cmurphy/puppet-module-ssh' ## Add dependencies, if any: # dependency 'username/name', '>= 1.2.0'
  21. 21. Publishing your module README ● docs.puppetlabs.com/puppet/3/reference/READMEtemplate.markdown license ● choosealicense.com
  22. 22. Publishing your module Changelog ## 2013-12-05 Release 0.10.0 ### Summary: This release adds FreeBSD osfamily support and various other improvements to some mods. ### Features: - Add suPHP_UserGroup directive to directory context - Add support for ScriptAliasMatch directives ... ## 2013-09-06 Release 0.9.0 ### Summary: ...
  23. 23. Publishing your module Use semantic versioning! semver.org Major.Minor.Patch
  24. 24. Publishing your module $ cd ssh/ $ puppet module build . $ ls pkg/ cmurphy-ssh-0.0.1 cmurphy-ssh-0.0.1. tar.gz
  25. 25. Testing your module Add tests ● rspec-puppet ○ rspec-puppet.com ● rspec-system ○ github.com/puppetlabs/rspec-system
  26. 26. Maintaining your module Update your code ● fix bugs ● add features ● manage pull requests
  27. 27. Installing modules Search for modules on forge.puppetlabs.com or puppet module search Then install with puppet module install
  28. 28. Thanks! Learn more at docs.puppetlabs.com/guides/module_guides/bgtm.html Colleen Murphy freenode: crinkle github: cmurphy

×