You are previewing Puppet Best Practices.
O'Reilly logo
Puppet Best Practices

Book Description

If you're already up to speed on Puppet and know how to write a basic module, this practical book takes you a critical step further with best practices for building out your Puppet infrastructure. You’ll learn how to avoid pitfalls that often leave many teams struggling to maintain what they already have. Ideal for DevOps engineers—and written to cover the upcoming Puppet 4 release—this book shows you how best to deploy Puppet with long-term maintenance and future growth in mind.

Table of Contents

  1. 1. Introduction
  2. 2. The Puppet Design Philosophy
    1. Declarative Code
      1. What is declarative code anyway?
      2. A practical example
      3. Non-Declarative Code with Puppet
    2. Idempotency
      1. Side Effects
      2. Resource Level Idempotence
      3. Run Level Idempotence
      4. Non-deterministic code
    3. Stateless
      1. Sources of State
    4. Summary
  3. 3. Code and Data; High Level Design
    1. Code and Data
    2. Breaking it down
      1. Application Logic & Puppet Modules
      2. Business logic with Roles and Profiles
      3. Hiera & Site Specific Data
      4. Node Classification
      5. Exported Resources & Service Discovery
    3. Summary
  4. 4. Coding Practices
    1. The Style Guide
    2. Coding Principles
      1. KISS
      2. The Single Responsibility Principle
      3. Seperation of Concerns
      4. Interface Driven Design
      5. Don’t Repeat Yourself (the DRY principle)
    3. General Coding Recommendations
      1. The balance of Code and Resources
    4. Conditional Logic
      1. Selectors
    5. Variables
      1. Variable Naming
      2. Referencing Variables
      3. Other Variable Use Cases
    6. Function Calls
      1. Functions for logging and Debugging
      2. String manipulation functions
      3. Path Manipulation
      4. Input validation functions
      5. Catalog tests
    7. Iteration
      1. Iteration with Puppet 3
      2. Iteration with Puppet 4 and the Future Parser
    8. Generating lists
    9. Data Transformation
    10. Templates
      1. ERB Templates
      2. EPP Templates
      3. EPP vs. ERB
      4. Template abuse
      5. The puppet::file defined type
    11. Other Language Features
    12. Summary
  5. 5. Puppet Module Design
    1. Design modules for public consumption
    2. Using public modules
      1. Picking good modules
      2. Module checklist
      3. Module Applicability
      4. Contributing Modules
    3. Planning and scoping your module
    4. Basic Module Layout
    5. manifests/init.pp; the module entry point
      1. An example init class
      2. Parameterizing your module
      3. Input validation
    6. params.pp pattern
      1. Module data sources; the alternative to params.pp
    7. Subclasses
      1. Subclass relationships
      2. Subclass containment
      3. Interfacing with subclasses.
    8. Defined Types
      1. Iteration and DRY with defined types
      2. Module Interfaces with defined types
      3. Providing services with defined types
      4. Defined types for simplifying complex tasks
      5. Interacting with the rest of the module
    9. Documentation
      1. Markdown
      2. In-line documentation
    10. Rake tasks
    11. Testing
      1. Rspec
      2. Acceptance testing
      3. Module testing best practices
      4. Continuous Integration
    12. Dependencies
    13. Summary
  6. 6. Types and Providers
    1. The Basics
      1. Understanding Types and Providers
      2. Tools for exploring native resources
    2. Resource Declaration
      1. Conventional
      2. Function
      3. Meta-Resources
      4. Virtual Resources
      5. Exported Resources
    3. Overriding and modifying declared resources
      1. Resource Defaults
      2. Resource Overrides
      3. Resource Collectors
    4. Meta-parameter Basics
      1. Alias
      2. Audit
      3. before, require, notify, subscribe and resource chains
      4. noop
      5. Schedule
      6. Stage
      7. Tag
    5. Ensure states
    6. Resource Scope
      1. Resource scope and performance
    7. Resource Best Practices
      1. Built-in resources
      2. Common add-on types
      3. Useful defined types
      4. JSON and YAML
    8. Summary
  7. 7. Hiera
    1. Seperation of Code and Data
    2. Choosing a Hiera backend
      1. The YAML back-end
      2. The JSON back end
      3. The Puppet backend
      4. Database backend
      5. Service discovery backends
      6. Encryption Backends
      7. Custom Hiera backends
    3. Hierarchy Design
      1. General Design Recommendations
      2. An example Hierarchy
      3. Other Hierarchies
      4. Problematic hierarchies
    4. Eliminating Data
      1. Hierarchy design
      2. Package Management
      3. User Management
      4. Service Discovery
    5. Interpolation
      1. Variable interpolation in your Hierarchy
      2. Interpolation in your data
    6. Accessing Hiera
      1. Automatic Parameter Lookups
      2. Hiera Function Calls
      3. Converting Hiera data into resource declaration
    7. Summary
  8. 8. Roles and Profiles
    1. Profiles
      1. Example Profile
      2. Parameterized Profiles
      3. Conditional logic
      4. Profiles and Hiera
      5. Using run stages
      6. Profile subclasses
      7. Relationships in profiles
      8. The Base Profile
      9. Service Profiles
      10. Profile Structures
      11. Profile testing
      12. The relationship between module test manifests and profiles
    2. Roles
      1. Roles and Profiles example
      2. Parameterized Roles
      3. Profile Relationships in Roles
      4. ENC groups as roles
    3. A-la-cart provisioning
    4. Summary
  9. 9. Node Classification
    1. What should be managed by an ENC?
      1. The node role or class list
      2. Basic node properties
      3. The Puppet Environment
    2. Node Statements
      1. Inheritance
      2. Wild-card and regex node statements
      3. Node per manifest
      4. Node properties within node statements
    3. Fact based classification
      1. Security and fact based classification
      2. Node properties with fact based classification
    4. Hiera as a node classifier
      1. Hash, array, and recursive lookups
      2. Node properties with Hiera classification
    5. Management Consoles
      1. Console Review
    6. Other ENCs
    7. site.pp
    8. Standalone self-classification
    9. Summary