2. Welcome to Intro to PDK!
System Integrity Management Platform (SIMP) Open Source stewards
DevOps, Compliance, and Automation consulting
Professional services for SIMP, Puppet, Red Hat®, and GitLab
Puppet Gold Partners
Steven Pritchard
Senior Consultant
Puppet Certified Professional (2017)
Linux and Open Source geek for over 20 years
Southern Illinois Linux Users Group
Vim Geeks
3. What is PDK?
The Puppet Development Kit (PDK) is an All‑In‑One set of tools for developing and testing Puppet
modules.
PDK includes a bundled version of Ruby plus various gems and utilities required for creating and
testing Puppet modules.
PDK was announced in August of 2017 with the goal of making it easier to build high‑quality
Puppet modules that follow best practices and use the available testing frameworks to avoid
deploying bad code to live infrastructure.
4. Installation
PDK packages for various Linux distributions, Windows, and MacOS X can be downloaded from
https://puppet.com/download‑puppet‑development‑kit.
https://puppet.com/docs/pdk/latest/pdk.html
5. Creating a Module - The Old Way
$ puppet module generate author-modulename --skip-interview
$ cd modulename
...Lots of editing...
$ puppet module build
...Upload to Forge...
6. What's Wrong With the Old Way?
Module skeleton quality varied wildly.
Often easier to create everything from scratch.
The skeleton was only used as an initial template.
puppet module generate was deprecated in Puppet 5.4.0.
7. Creating a Module - The New Way
$ pdk new module author-modulename
$ cd modulename
$ pdk new class modulename
...Lots of editing...
$ pdk validate
$ pdk test unit
$ pdk build
...Upload to Forge...
8. Why is this better?
Generated code follows best practices.
pdk new class classname creates manifests/classname.pp and
spec/classes/classname_spec.rb.
Testing out of the box!
The default templates (https://github.com/puppetlabs/pdk‑templates) include lots of
goodies:
CI configurations for Travis CI, GitLab CI/CD, and AppVeyor
operatingsystem_support and requirements in metadata.json
Git configuration (.gitignore, .gitattributes)
Puppet Strings in generated code
Updates to the templates can be applied to (some files in) the module.
Interaction with Ruby tooling ( bundle , rake ) is not required.
Did I mention that puppet module generate was deprecated in Puppet 5.4.0?
9. Using PDK
Create a new module
$ pdk new module mynewmodule
(Or you can skip the interview...)
$ pdk new module mynewmodule --skip-interview
Convert an existing module to PDK format
$ pdk convert
(Note that this does not add tests for existing classes, defined types, etc.)
Update from the templates in an existing PDK-format module
$ pdk update
10. Using PDK
Create a new class
$ pdk new class classname
Create a new defined type
$ pdk new defined_type typename
Create a new task
$ pdk new task taskname
11. Testing
Smoke tests (simple lint , rubocop , and parser checks) can be run with the following command:
$ pdk validate
Unit tests (Ruby scripts that use rspec‑puppet to test the contents of a compiled catalog) can be
executed with the following command:
$ pdk test unit
The default tests use rspec‑puppet‑facts to test catalog compilation on each supported OS.
https://puppet.com/docs/pdk/1.x/pdk_testing.html
12. pdk bundle
PDK allows you to run arbitrary bundle commands with pdk bundle . For example, to see what
rake tasks are available, you can run the following command:
$ pdk bundle exec rake -- -T
To see all output of the rake tasks run by pdk test unit , you can run the following command:
$ pdk bundle exec rake spec
13. Acceptance Tests
Acceptance tests spin up VMs or Docker containers to test the behavior of a module on a live
system.
PDK currently has no direct support for acceptance tests, but if you have an existing module with
working tests, you should be able to make some minor additions to Gemfile and run the
following:
$ pdk bundle exec rake beaker
For more information on acceptance tests, see the following:
beaker‑rspec
beaker
Serverspec
14. PDK Templates
The default PDK templates can be found here:
https://github.com/puppetlabs/pdk‑templates
Files in the moduleroot_init directory are created only if they don't exist.
Files in the moduleroot directory will replace any existing file when you run pdk update or pdk
convert .
Files in the object_templates directory are used by the various pdk new commands.
The default settings for the template output can be found in the file config_defaults.yml.
15. Customizing Template Output
Settings in the file .sync.yml in the root of your module can be used to customize the output of
the templates.
.sync.yml contains a hash. The keys of the hash are the names of the generated files. The exact
values can be found by looking at the PDK templates README.md, config_defaults.yml in the
templates, and the code of the templates.
After updating .sync.yml, run pdk update to regenerate files from the templates.
16. Example .sync.yml
---
Gemfile:
optional:
':acceptance':
- gem: beaker
- gem: beaker-rspec
- gem: beaker-puppet_install_helper
- gem: beaker-module_install_helper
- gem: vagrant-wrapper
.gitignore:
paths:
- /update_report.txt
spec/spec_helper.rb:
spec_overrides: |-
# Add coverage report.
RSpec.configure do |c|
c.after(:suite) do
RSpec::Puppet::Coverage.report!
end
end
17. Future of PDK
PDK has experimental support for creating a new provider with pdk new provider . See
https://github.com/puppetlabs/puppet‑resource_api#getting‑started for more information.
Other interesting features that may be coming soon:
More module features
pdk new function PDK‑700
pdk new fact PDK‑683
Multi‑Puppet Support PDK‑414
Support for additional platforms PDK‑399
Testing on multiple Puppet and Ruby versions PDK‑785, PDK‑840, etc.
Data in modules by default PDK‑908
CLI ability to update metadata.json PDK‑878
Improved CI/CD support PDK‑477
Control repo support PDK‑564, puppetlabs/pdk#333
Bundled git support