Here are the slides from Tim Cinel's PuppetConf 2016 presentation called Writing Custom Types to Manage Web-Based Applications. Watch the videos at https://www.youtube.com/playlist?list=PLV86BgbREluVjwwt-9UL8u2Uy8xnzpIqa
4. Atlassian BambooSonatype Nexus
Atlassian’s Build Engineering team uses Puppet
to manage manage many services, including…
• Repositories
• Security
• Proxy features
• Variables
• Global defaults
• Security
5. Managing config files has drawbacks…
• Nexus’s config file changes
are picked up after restart
• Changes require brief service
outage
• Changes made using Nexus
and Bamboo UI during
runtime not detected by
Puppet
• Risk of configuration drift
• Most Bamboo configuration is
in its database, not
configuration files
• Ability to manage service is
limited
Uptime Drift Limited
6. How do we address
these drawbacks?
Custom Types.
8. Concept and terminology refresher
• Type
• Name
• Attributes
Can be considered as
instances of types
Native Type
• Ruby implementation
• Attributes
• Provider(s)
Allows the representation of a
type of resource in Puppet DSL
• Ruby implementation
• Type
Providers interact with target
system to manage resources
Resource Type Provider
9. What Are Custom Types?
user Type
(Default)
useradd Provider
for user Type
Manifest
bamboo_agent Type
(Custom)
rest Provider for
bamboo_agent Type
Manifest
10. What Are Custom Types?
user Type
(Default)
useradd Provider
for user Type
Manifest
bamboo_agent Type
(Custom)
rest Provider for
bamboo_agent Type
Manifest
12. Custom
Types
The Good Fine Configuration
No need to restart or reload services
to pick up configuration changes.
No More Drift
Custom types can directly query the
application state runtime.
Fewer Restarts
If it’s configurable, a custom type can
manage it. No need to manually
tweak service configuration.
13. Custom
Types
The Bad Authentication
Somebody has to create and
maintain the custom types
More Dependencies
The module containing the custom
types, custom providers and libraries
Engineering Cost
Configuration APIs often require
credentials
14. It’s not OK to manually configure
Bamboo instances
20
15. bamboo_rest
Automated away
These properties used to be
configured on each server manually.
Not anymore. Thanks Custom Types!
https://forge.puppetlabs.com/atlassian/bamboo_rest
17. nexus_rest
Seamless changes
Changes to these properties used to
cause Nexus to restart, resulting in
down time.
Not anymore. Thanks Custom Types!
https://forge.puppetlabs.com/atlassian/nexus_rest
18. Configuration
Only
These modules are only responsible
for configuring installed services via
REST APIs.
Installation of these services is
managed by another module.
19. IMPLEMENT A TYPE
SET UP
WRITE A PROVIDER
ADDING MORE PROPERTIES
Worked Example
INTERACTION BETWEEN TYPES
20. IMPLEMENT A TYPE
SET UP
WRITE A PROVIDER
ADDING MORE PROPERTIES
Worked Example
INTERACTION BETWEEN TYPES
22. What makes Nexus 3 a good
candidate?
• Completely different API to Nexus 2
• Easy to run using Docker
• A repository manager is a good fit
with the Puppet resource model
Nexus 3
We’e going to create custom types
for Nexus 3 in our worked example.
23. Our Nexus 3 Types
Hosted Maven repository.
Attributes
• name
• online
• blobstore
Abstract storage used by
repositories.
Attributes
• name
• path
nexus3_repository nexus3_blobstore
24. Discover
Service
Endpoints
Useful Endpoints
• Query all resources
• Create new resource
• Delete existing resource
• Update existing resource
Before starting work on a custom
type, we should confirm the
necessary endpoints are available.
43. Oops. We broke it again.
Looks like we need to implement a provider.
ensurable resources have state, so their
provider must have logic to determine state
tag: step-03
44. Oops. We broke it again.
Looks like we need to implement a provider.
ensurable resources have state, so their
provider must have logic to determine state
tag: step-03
45. IMPLEMENT A TYPE
SET UP
WRITE A PROVIDER
ADDING MORE PROPERTIES
Worked Example
INTERACTION BETWEEN TYPES
46. Before we start writing the provider…
We could do with some helper classes so we don’t get bogged
down in implementation details.
tag: step-04
47. Before we start writing the provider…
We could do with some helper classes so we don’t get bogged
down in implementation details.
helper classes in puppet_x
tag: step-04
48. Before we start writing the provider…
We could do with some helper classes so we don’t get bogged
down in implementation details.
providers only need to use
this class method
tag: step-04
49. Before we start writing the provider…
We could do with some helper classes so we don’t get bogged
down in implementation details.
lazily load application
config from file
tag: step-04
105. Relationships between Types
Types can define soft require relationships with arbitrary resources
if puppet manages this config file, then all nexus3_repository
resources will depend on it
tag: step-11
106. Relationships between Types
Types can define soft require relationships with arbitrary resources
the associated nexus3_blobstore resource will become a
dependency (if it exists)
tag: step-11
117. Areas for
Improvement
Publish to Forge
Incorporate better error handling,
logging.
Tests
Unit tests with RSpec, acceptance
tests with Beaker and some CI.
Robustness
Make the module and its glorious
types available to the community.
118. Puppet SourceShit Garry SaysPuppet Types
and Providers http://garylarizza.com/blog/
Other Resources