Home Page Icon
Home Page
Table of Contents for
Cover
Close
Cover
by Jo Rhett, Chris Barbour
Puppet Best Practices
Preface
What Is a Best Practice?
Who Should Read This Book
Why We Wrote This Book
A Word on Puppet Today
Navigating This Book
Online Resources
Conventions Used in This Book
Using Code Examples
O’Reilly Safari
How to Contact Us
Acknowledgments
1. The Puppet Design Philosophy
Declarative Code
What Is Declarative Code, Anyway?
Resource Types and Providers
Procedural Example
Nondeclarative Code with Puppet
Idempotency
Side Effects
Resource-Level Idempotence
Run-Level Idempotence
Nondeterministic Code
Stateless
Benefits of Stateless Design
Sources of State Information
Summary
2. High-Level Code and Data Design
Code and Data Organization
Code and Data Categories
Types of Code Logic
Examples of Logic Types
Mapping Data Types to Puppet Use Cases
Application Logic and Puppet Modules
Business Logic Should Not Be Written into Component Modules
Business Logic with Roles and Profiles
Business, Service, Site, Node, and Application Data
Hiera Data Sources
Node Classification
Summary
3. Coding Practices
The Style Guide
Coding Principles
KISS: Keep It Simple
The Single Responsibility Principle
Separation of Concerns
Interface-Driven Design
DRY: Don’t Repeat Yourself
Don’t Reinvent the Wheel
Code Practices
Balance of Resources Versus Logic
Balance of Code Versus Data
Conditional Logic
Iteration
Generating Lists
Variables
Variable Naming
Referencing Variables
Other Variable Use Cases
Trusted Variables
Order of Assignment for Top-Level Variables
Assignment with Selectors
Attribute Values Chosen by Conditional Evaluation
Variable Inheritance
Strict Variables
Function Calls
Always Use Parentheses
Functions for Logging and Debugging
String Manipulation Functions
Path Manipulation
Input Validation Functions
Catalog Tests
Data Transformation
Templates
ERB Templates
EPP Templates
EPP Versus ERB
Other Language Features
Summary
4. Puppet Module Design
The Puppet Development Kit
Installing the Puppet Agent
Using the Ruby that Comes Bundled with Puppet
Installing the Puppet Development Kit
Favor Editors or IDEs with Puppet Plugins
Using Vendor-Provided or Community Modules
Picking Good Modules
Module Checklist
Module Applicability to Your Needs
Contributing Modules
Designing Modules Well
Make Use of Module Structure
Keep the Module Focused
Design Modules for Public Consumption
Planning and Scoping Your Module
Basic Module Layout
The Module’s Main Class
Module Parameters
Input Validation
Data in the Module
The params.pp Pattern
Hiera Data in Modules
Modularizing Classes
Dependencies
Class Relationships
Class Containment
Interfacing with Classes
Reusing Defined Types
Providing Clean Service Interfaces with Defined Types
Simplify Complex Operations with a Defined Type
Interacting with Other Resouces in the Module
Creating Useful Documentation
README, REFERENCE, and Other Markdown
REFERENCE Markdown
Summary
5. Resources
Using Resources to Implement Change
Resource Types Abstract Implementation Details
Use the Most Specific Resource Type
Examining a Naked Resource
Exploring Resources with Tools
Resource Declaration
Ensure states
Use Variables for Data-Driven Declaration
Use Arrays for Similar Resources
Using Automatic Resource Relationships for Clean Code
Resource Declaration by Functions
Resources Metatypes
Resource Metaparameters
Avoid Parse-Order Problems by Using Virtual Resources
Exporting Resources
Overriding and Modifying Declared Resources
Resource Default Statements
Resource Chaining
Resource Collectors
Resource Best Practices
Custom Resource Types
Useful Defined Types
Summary
6. Hiera Data
Separating Code and Data
Global, Environment, and Module Data
Hiera Backends
Designing the Hiera Hierarchy
Variable Interpolation
Design Guidelines
Useful Hierarchy Levels
Eliminating Data
Accessing Hiera
Automatic Parameter Lookups
Hiera Function Calls
Converting Serialized Hiera Data into Resource Declarations
Interpolation in Your Data
The Built-In Backends
YAML
JSON
HOCON
eYAML
Custom Hiera Backends
Database and NoSQL Engines
Service Discovery Backends
Encrypted Key/Value Storage
Summary
7. Roles and Profiles
Roles
Creating Readable Roles
Design Roles for a Singular Use Case
Provide the Role for Use in Data Lookups
Profiles
A Sample Service Profile
Providing Actionable Data in Profile Parameters
Implementing Business Logic in Profiles
Defining Module Relationships in Profiles
Creating Metaprofiles to Group Configurations
Designing an Appropriate Profile Structure
Testing Roles and Profiles
Validating Profiles by Using Unit Tests
Confirming Profile Implementation with Acceptance Tests
Summary
8. Node Classification
What Data Should the Node Classifier Provide?
Roles and Profiles
Node-Specific Data
Node Statements
Node Statement Matching
Replacing Node Inheritance
Node Parameters Within Node Blocks
Fact-Based Classification
Fact-Based Role Assignment
Security and Fact-Selected Roles or Profiles
Fact-Based Hiera Classification
Node Parameters with Hiera Classification
Avoiding Node Data in Manifests
Serverless Classification
ENCs
What Data Can an ENC Provide?
Puppet Management Consoles
Inventory and Infrastructure Management ENCs
Summary
9. Release Engineering and r10k
Puppet Environments in Depth
Puppet Directory Environments
Selectable Blocks for Catalog Building
Environment Configuration
Environment Independence and Isolation
Deploying with r10k
What Does r10k Actually Do?
The Control Repository
Control Repository Branch Contents
r10k Configuration File
Puppetfile
r10k Deployment Walkthrough
Uses for r10k
Build Development Environments
Simplifying Acceptance Testing
Implement Continuous Integration, Delivery, and Deployment
Deploy Production Environments
Build and Package
Release Management Strategies with r10k
Stage/Production Branches
Single Branch (GitHub Flow)
GitFlow
Invoking r10k
Puppet Prerun Command
Deploying on Receipt of a WebHook
Orchestrating Deployments with MCollective/Choria
Invoking r10k in Testing Frameworks
Combining Multiple Invocation Methods
Migrating to r10k
Repository-per-Module Benefits
Configuring an Environment in the Control Repository
Enabling Monolithic and Per-module Hybrid Deployment
Moving Modules to their Own Repositories
Placing Roles and Profiles in the site/ Module Directory
Remove Fully Qualified Paths
Moving Shared Tools to Their Own Repository
Implementing Test Cases
Best Practices for Puppet Deployments
Using Repository Access Control to Enforce Deployment Policy
Enabling Multiteam Coordination
Pinning Module Versions
Isolating Puppet Extensions
Utilizing Standard Environment Configuration Practices
Git Best Practices
Deployment Practices
Summary
10. Extending Puppet
The Cost of Extending Puppet
Minimizing Development Costs
Reducing Upgrade Costs
Testing
Static Code Analysis
Unit Testing
Acceptance Testing
Creating Facts
Distributing Facts in Modules
Facts Puppet Can’t Know
Structured Facts
Abusing Facts
Trusted Certificate Attributes
Custom Types and Providers
Avoiding Creation of Duplicate Types
Creating a New Resource Type
Custom Resource Providers
Reuse Existing Frameworks
Creating Custom Hiera Backends
Choose the Appropriate Backend Type
Creating a High-Performance Backend
Using Puppet’s Public Classes and Method Calls
Puppet Faces
Indirection
Deploying Extensions
pluginsync
Deploying Gem Dependencies
Deploying Ruby Gem Extensions on Puppet Server
Summary
Index
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Next
Next Chapter
Puppet Best Practices
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset