puppet camp dc 2015: stop writing puppet modules: a guide to best practices in the puppet community...
TRANSCRIPT
STOP WRITING PUPPET MODULESBest Practices In The Puppet Community
Assembled by Lucas Yamanishi / [email protected]
http://lucas.yamanishi.us/stop_writing_puppet_modules
Bona Fides
Systems Administrator - ADNET Systems, Inc.NASA SESDA PMO(Space and Earth Science Analysis Project Management Office)
Minor contributions made to...
Gentoovim-puppetvarious Puppet modulesThis presentation software ( )reveal-ck
AGENDA
IntroFree & Open Source SoftwareCommunity WorkflowsBuilding with Community in mindFinding & building great Puppet modules
Community Benefits
Large ecosystemLinus's Law (many eyes)Reduced maintenance costs*Easier to troubleshoot*Better overall quality*
Software Policy
(use and contribution)
What content is OK? What's off limits?Who signs off?Acceptable license features
Use permissionRedistribution rightsAttribution requirementsPatent protectionDisclaimer of liability
Acceptable licenses (MIT, BSD, Apache, GPL, etc.)Display of license (LICENSE file, file headers, etc.)Contributor License Agreements (CLAs)Quality control
Feature branches
Image courtesy of - .Atlassian Creative Commons Attribution 2.5
Australia License
environment.conf
Puppet >= 3.6 required
Older versions
modulepath = site:modules:$basemodulepath
basemodulepath = $confdir/$environment/site:$confdir/$environment/modules
manifests/site.pp
Facter >= 2.2 required for $::os structured facts
$os_name = $::os['name']$os_major = $::os['release']['major']$os_minor = $::os['release']['minor']
node default { $host_group = 'default' $security_policy = 'high'
include 'base'
warning("Node ${::certname} does not match any host groups")}
node /^ntp[[:digit:]]{2}\.dca\.example\.net$/ { $host_group = 'ntp' $location = 'DCA' $security_policy = 'medium'
include 'base'}
site/base/manifests/init.pp
Puppet >= 3.0 required
# A base class to manage Puppet runs class base { $hiera_classes = hiera_array('classes', []) include $hiera_classes}
hiera.yaml
Puppet >= 3.0 required
---:backends: - 'eyaml' - 'yaml':merge_behavior: 'deeper':hierarchy: - "nodes/%{::clientcert}" - "host_groups/%{::host_group}" - "os/%{::kernel}/%{::osfamily}/%{::os_name}/%{::os_major}/%{::os_minor}" - "os/%{::kernel}/%{::osfamily}/%{::os_name}/%{::os_major}" - "os/%{::kernel}/%{::osfamily}/%{::os_name}" - "os/%{::kernel}/%{::osfamily}" - "os/%{::kernel}" - "locations/%{::location}" - "security_policies/%{::security_policy}" - 'common':yaml: :datadir: "/etc/puppet/environments/%{::environment}/datadir":eyaml: :datadir: "/etc/puppet/environments/%{::environment}/datadir" :gpg_gnupghome: '/etc/puppet/gpg' :extension: 'yaml'
host_groups/ntp_stratum2.yaml
Hiera >= 1.3 required for hiera() function in data
---classes: - 'ntp'
ntp::preferred_servers: - %{hiera('ntp_local_master', '')}ntp::servers: - 0.us.pool.ntp.org - 1.us.pool.ntp.org - 2.us.pool.ntp.org - 3.us.pool.ntp.org
Puppetfile
(for use with )
r10k / librarian-puppet file
r10k
##################### Site-local modules#mod 'root_account', git: '[email protected]:puppet/site-local/root_account.git'
mod 'really_awesome_product', svn: 'https://svn-server.example.net/puppet/site-local/really_awesome_product/trunk', rev: '539'
##################### Third-party modules#mod 'docker', git: '[email protected]:puppet/third-party/garethr-docker.git', tag: 'v4.0.2'
# TODO:# - find an NTP module
Operating System Portability
Structureparams.pp
Puppet Labs ticket:Data in modules
PUP-42
Cross-module compatibility
conf.d
Augeas resourcesconcat
Augeas Providers
Semantic Versioningpuppetforgepuppetforge v0.9.0v0.9.0
MajorMinorBugfix
http://SemVar.org
Style Guide
Every major [software] project has its own style guide: a set of conventions(sometimes arbitrary) about how to write code for that project. It is mucheasier to understand a large codebase when all the code in it is in aconsistent style.
google-styleguide
https://docs.puppetlabs.com/guides/style_guide.html
rspec-puppet
coveragecoverage 98%98%
http://rspec-puppet.com
require 'spec_helper'
describe 'example_module' do context 'on CentOS' do let(:facts) {{ operatingsystem: 'CentOS' }}
context "example_module class with default parameters" do let(:params) {{ }}
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('example_module::params') }
it { is_expected.to contain_service('example_module') } it { is_expected.to contain_file('/path/to/example_file').with_ensure('file') } end endend
Skeletons & Other Standards
https://github.com/garethr/puppet-module-skeletonStdMod
© Lucas Yamanishi 2015
RESOURCES
(book in pre-release)Blogs:
Mailing list:IRC: on
Beginner's Guide to ModulesPuppetBestPractices.comThe Puppet design philosophy - Brian AndersonPuppet Best Practices - Chris Barbour
Tim SharpeAdrien TheboJoe TopjianGary LarizzaPlanet PuppetPuppet Labs
puppet-users#puppet freenode
This work is licensed under a .
Creative Commons Attribution-ShareAlike4.0 International License