SlideShare a Scribd company logo
1 of 116
Download to read offline
TIM CINEL • BUILD WHISPERER • ATLASSIAN • @TIMCINEL
Writing Custom Types to
Manage Web-Based Applications
OUR SITUATION
WORKED EXAMPLE
DEMO
This Talk
NEXT STEPS
Our Situation
Atlassian BambooSonatype Nexus
Atlassian’s Build Engineering team uses Puppet
to manage manage many services, including…
• Repositories
• Security
• Proxy features
• Variables
• Global defaults
• Security
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
How do we address
these drawbacks?
Custom Types.
Concepts Refresher
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
What Are Custom Types?
user Type

(Default)
useradd Provider
for user Type
Manifest
bamboo_agent Type

(Custom)
rest Provider for
bamboo_agent Type
Manifest
What Are Custom Types?
user Type

(Default)
useradd Provider
for user Type
Manifest
bamboo_agent Type

(Custom)
rest Provider for
bamboo_agent Type
Manifest
Custom Types can be
created to manage
web-based services.
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.
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
It’s not OK to manually configure
Bamboo instances
20
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
Nexus instances
18
It’s not OK to allow config to drift on
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
Configuration
Only
These modules are only responsible
for configuring installed services via
REST APIs.
Installation of these services is
managed by another module.
IMPLEMENT A TYPE
SET UP
WRITE A PROVIDER
ADDING MORE PROPERTIES
Worked Example
INTERACTION BETWEEN TYPES
IMPLEMENT A TYPE
SET UP
WRITE A PROVIDER
ADDING MORE PROPERTIES
Worked Example
INTERACTION BETWEEN TYPES
https://bitbucket.org/TCinel/puppet-camp-example/
Helpful Tools
• Puppet
• Ruby
• Bundler
• irb
• curl and Firebug
• Docker
"Tools" (CC BY-NC-ND 2.0) by jlgriffiths
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.
Our Nexus 3 Types
Hosted Maven repository.
Attributes
• name
• online
• blobstore
Abstract storage used by
repositories.
Attributes
• name
• path
nexus3_repository nexus3_blobstore
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.
Query Repositories
Nexus Endpoint Example
File Structure
• lib/ - All code
• lib/puppet/ Puppet API code
• lib/puppet/provider/<type>/<provider>.rb

Provider definition
• lib/puppet/type/<type>.rb

Type definition
• lib/puppet_x helper code
IMPLEMENT A TYPE
SET UP
WRITE A PROVIDER
ADDING MORE PROPERTIES
Worked Example
INTERACTION BETWEEN TYPES
Creating a new type
It’s as simple as adding these two lines.
tag: step-01
Creating a new type
It’s as simple as adding these two lines.
tag: step-01
Creating a new type
It’s as simple as adding these two lines.
tag: step-01
It’s not quite ready.
At least we have our dev loop now.
tag: step-01
Make sure RUBYLIB contains the path
to lib/ before running puppet
It’s not quite ready.
At least we have our dev loop now.
tag: step-01
puppet resource and puppet
apply are your friends
It’s not quite ready.
At least we have our dev loop now.
tag: step-01
Add namevar
A type’s namevar acts like a primary key
tag: step-02
Add namevar
A type’s namevar acts like a primary key
tag: step-02
tag: step-02
`puppet resource` won’t work until we
implement a provider
tag: step-02
`puppet apply` works because currently
nexus3_repository is not ensurable
tag: step-02
Inline documentation and ensurableness
Non-ensurable types (like exec) do not have persistent state.
tag: step-03
Inline documentation and ensurableness
Non-ensurable types (like exec) do not have persistent state.
tag: step-03
Inline documentation and ensurableness
Adding inline documentation is easy.
tag: step-03
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
IMPLEMENT A TYPE
SET UP
WRITE A PROVIDER
ADDING MORE PROPERTIES
Worked Example
INTERACTION BETWEEN TYPES
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
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
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
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
A basic provider
tag: step-05
A basic provider
the provider name is usually the name of the
underlying tool used to manage resources
tag: step-05
A basic provider
if implemented, self.instances is
used to enumerate all resources of type
tag: step-05
A basic provider
exists? provides logic for determining
the presence of a resource
tag: step-05
Aw yeah.
now that we’ve implemented a basic
provider, puppet resource is working
tag: step-05
Aw yeah.
now that we’ve implemented a basic
provider, puppet resource is working
tag: step-05
Ability to create and destroy
tag: step-06
Ability to create and destroy
method used when Puppet determines
that a resource should be created
tag: step-06
Ability to create and destroy
method used when Puppet wants to
destroy a resource
tag: step-06
Now we’re getting somewhere.
tag: step-06
Now we’re getting somewhere.
purges any discovered resources
that are not in the manifest
tag: step-06
Now we’re getting somewhere.
ensures that repo_1 and number-
two are present
tag: step-06
Now we’re getting somewhere.
destroyed unmanaged resources
tag: step-06
Now we’re getting somewhere.
created new resources
tag: step-06
Now we’re getting somewhere.
tag: step-06
Well, sort of.
resources are being created again
even though they already exist
tag: step-06
Implement prefetch
`prefetch` must be defined if your `exists?` and getter methods don’t
query the system.
tag: step-07
Implement prefetch
`prefetch` must be defined if your `exists?` and getter methods don’t
query the system.
tag: step-07
Yep, now we’ve got it.
tag: step-07
Yep, now we’ve got it.
no resources recreated
tag: step-07
IMPLEMENT A TYPE
SET UP
WRITE A PROVIDER
ADDING MORE PROPERTIES
Worked Example
INTERACTION BETWEEN TYPES
Adding an attribute to the Type
tag: step-08
Adding an attribute to the Type
nexus3_repository type now has an online attribute
tag: step-08
Adding an attribute to the Type
input value restriction
tag: step-08
Adding an attribute to the Type
input value normalisation
tag: step-08
Adding an attribute to the Provider
tag: step-08
Adding an attribute to the Provider
fetch the new attribute value from system and normalise it
tag: step-08
Adding an attribute to the Provider
submit the new attribute to the system on create and update
tag: step-08
Adding an attribute to the Provider
tag: step-08
Adding an attribute to the Provider
property getters and setters
tag: step-08
Adding an attribute to the Provider
flush can be used to implement update logic
tag: step-08
Aw yeah.
tag: step-08
Aw yeah.
puppet resource is reporting online status
tag: step-08
Aw yeah.
puppet apply updated the online attribute
tag: step-08
Aw yeah.
puppet apply updated the online attribute
tag: step-08
Adding another attribute to the Type
tag: step-09
Adding another attribute to the Type
custom input validation logic
tag: step-09
Adding another attribute to the Provider
tag: step-09
Adding another attribute to the Provider
immutable property using fail method
tag: step-09
puppet resource is reporting blobstore value
tag: step-09
puppet resource is reporting blobstore value
tag: step-09
changing the blobstore value for an existing repository is failing
tag: step-09
changing the blobstore value for an existing repository is failing
tag: step-09
That’s
nexus3_repository
done.
"Silbury Hill" (CC BY 2.0) by rightee
We’re over the hump.
IMPLEMENT A TYPE
SET UP
WRITE A PROVIDER
ADDING MORE PROPERTIES
Worked Example
INTERACTION BETWEEN TYPES
We’ve created another Type
This one is called nexus3_blobstore
We won’t walk through it like we did for nexus3_repository.
tag: step-10
Mostly good. But…
tag: step-10
tag: step-10
tag: step-10
nexus3_repositorys instances are being created before
nexus3_blobstore instances. not good.
tag: step-10
nexus3_repository instances are being created before
nexus3_blobstore instances. not good.
tag: step-10
Relationships between Types
Types can define soft require relationships with arbitrary resources
tag: step-11
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
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
Better.
tag: step-11
blobstore created before each dependent repository
tag: step-11
Even better.
tag: step-11
allow Puppet to manage the config file
tag: step-11
prefetch fails due to missing provider configuration file
tag: step-11
Puppet creates config file, then succeeds to create resources in the
right order using our custom types and providers
tag: step-11
IMPLEMENT A TYPE
SET UP
WRITE A PROVIDER
ADDING MORE PROPERTIES
Worked Example
INTERACTION BETWEEN TYPES
Done 👌
Demo
Next Steps
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.
Puppet SourceShit Garry SaysPuppet Types 

and Providers http://garylarizza.com/blog/
Other Resources
Now go, and write
some custom types
already!
Thank you
TIM CINEL • BUILD WHISPERER • ATLASSIAN • @TIMCINEL
https://bitbucket.org/TCinel/puppet-camp-example/

More Related Content

What's hot

What's hot (20)

Puppet Systems Infrastructure Construction Kit
Puppet Systems Infrastructure Construction KitPuppet Systems Infrastructure Construction Kit
Puppet Systems Infrastructure Construction Kit
 
Karma - JS Test Runner
Karma - JS Test RunnerKarma - JS Test Runner
Karma - JS Test Runner
 
Puppet at GitHub / ChatOps
Puppet at GitHub / ChatOpsPuppet at GitHub / ChatOps
Puppet at GitHub / ChatOps
 
Testing Ansible
Testing AnsibleTesting Ansible
Testing Ansible
 
Puppet at Pinterest
Puppet at PinterestPuppet at Pinterest
Puppet at Pinterest
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
 
Javascript TDD with Jasmine, Karma, and Gulp
Javascript TDD with Jasmine, Karma, and GulpJavascript TDD with Jasmine, Karma, and Gulp
Javascript TDD with Jasmine, Karma, and Gulp
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit Test
 
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
Kicking off with Zend Expressive and Doctrine ORM (ZendCon 2016)
 
Angular JS Unit Testing - Overview
Angular JS Unit Testing - OverviewAngular JS Unit Testing - Overview
Angular JS Unit Testing - Overview
 
Puppet Camp Paris 2016 Data in Modules
Puppet Camp Paris 2016 Data in ModulesPuppet Camp Paris 2016 Data in Modules
Puppet Camp Paris 2016 Data in Modules
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Learning Puppet Chapter 1
Learning Puppet Chapter 1Learning Puppet Chapter 1
Learning Puppet Chapter 1
 
React Native One Day
React Native One DayReact Native One Day
React Native One Day
 
Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with Puppet
 
Angular testing
Angular testingAngular testing
Angular testing
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Mastering PowerShell Testing with Pester
Mastering PowerShell Testing with PesterMastering PowerShell Testing with Pester
Mastering PowerShell Testing with Pester
 
Cooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with JitterbugCooking Perl with Chef: Real World Tutorial with Jitterbug
Cooking Perl with Chef: Real World Tutorial with Jitterbug
 
RSpec 2 Best practices
RSpec 2 Best practicesRSpec 2 Best practices
RSpec 2 Best practices
 

Similar to Writing Custom Puppet Types and Providers to Manage Web-Based Applications

Acceptance Testing of Web UI
Acceptance Testing of Web UIAcceptance Testing of Web UI
Acceptance Testing of Web UI
Vladimir Tsukur
 

Similar to Writing Custom Puppet Types and Providers to Manage Web-Based Applications (20)

PuppetConf 2016: Writing Custom Types to Manage Web-Based Applications – Tim ...
PuppetConf 2016: Writing Custom Types to Manage Web-Based Applications – Tim ...PuppetConf 2016: Writing Custom Types to Manage Web-Based Applications – Tim ...
PuppetConf 2016: Writing Custom Types to Manage Web-Based Applications – Tim ...
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
 
DevOps on AWS: Accelerating Software Delivery with the AWS Developer Tools
DevOps on AWS: Accelerating Software Delivery with the AWS Developer ToolsDevOps on AWS: Accelerating Software Delivery with the AWS Developer Tools
DevOps on AWS: Accelerating Software Delivery with the AWS Developer Tools
 
Acceptance Testing of Web UI
Acceptance Testing of Web UIAcceptance Testing of Web UI
Acceptance Testing of Web UI
 
Is Serverless The New Swiss Cheese? - AWS Seattle User Group
Is Serverless The New Swiss Cheese? - AWS Seattle User GroupIs Serverless The New Swiss Cheese? - AWS Seattle User Group
Is Serverless The New Swiss Cheese? - AWS Seattle User Group
 
Devops
DevopsDevops
Devops
 
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
Performance Tuning Your Puppet Infrastructure - PuppetConf 2014
 
Bootstrapping Puppet and Application Deployment - PuppetConf 2013
Bootstrapping Puppet and Application Deployment - PuppetConf 2013Bootstrapping Puppet and Application Deployment - PuppetConf 2013
Bootstrapping Puppet and Application Deployment - PuppetConf 2013
 
AWS re:Invent 2016: DevOps on AWS: Accelerating Software Delivery with the AW...
AWS re:Invent 2016: DevOps on AWS: Accelerating Software Delivery with the AW...AWS re:Invent 2016: DevOps on AWS: Accelerating Software Delivery with the AW...
AWS re:Invent 2016: DevOps on AWS: Accelerating Software Delivery with the AW...
 
InteropWG Intro & Vertical Programs (May. 2017)
InteropWG Intro & Vertical Programs (May. 2017)InteropWG Intro & Vertical Programs (May. 2017)
InteropWG Intro & Vertical Programs (May. 2017)
 
Ember addons, served three ways
Ember addons, served three waysEmber addons, served three ways
Ember addons, served three ways
 
PaaSTA: Running applications at Yelp
PaaSTA: Running applications at YelpPaaSTA: Running applications at Yelp
PaaSTA: Running applications at Yelp
 
Angular 2 overview in 60 minutes
Angular 2 overview in 60 minutesAngular 2 overview in 60 minutes
Angular 2 overview in 60 minutes
 
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
Strategies and Tips for Building Enterprise Drupal Applications - PNWDS 2013
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
Trusting the Unknown
Trusting the UnknownTrusting the Unknown
Trusting the Unknown
 
Trusting the Unknown
Trusting the UnknownTrusting the Unknown
Trusting the Unknown
 
DefCore: The Interoperability Standard for OpenStack
DefCore: The Interoperability Standard for OpenStackDefCore: The Interoperability Standard for OpenStack
DefCore: The Interoperability Standard for OpenStack
 
Puppet getting started by Dirk Götz
Puppet getting started by Dirk GötzPuppet getting started by Dirk Götz
Puppet getting started by Dirk Götz
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Writing Custom Puppet Types and Providers to Manage Web-Based Applications