Puppet 3 Cookbook - gbv.de

5
Puppet 3 Cookbook Build reliable, scalable, secure, and high-performance systems to fully utilize the power of cloud computing John Arundel f 1 open source I # W » > l \ I 1 community experience distilled 41^ PUBLISHING BIRMINGHAM - MUMBAI

Transcript of Puppet 3 Cookbook - gbv.de

Page 1: Puppet 3 Cookbook - gbv.de

Puppet 3 Cookbook

Build reliable, scalable, secure, and high-performance systems to fully utilize the power of cloud computing

John Arundel

f 1 open source I # W » > l \ I 1 community experience distilled

4 1 ^

P U B L I S H I N G BIRMINGHAM - MUMBAI

Page 2: Puppet 3 Cookbook - gbv.de

Table of Contents

Preface

Chapter 1 : Puppet Infrastructure introduction 7 Installing Puppet 8 Creating a manifest 10 Managing your manifests with Git 1 1 Creating a decentralized Puppet architecture 14 Writing a papply script 16 Running Puppet from cron 18 Deploying changes with Rake 22 Bootstrapping Puppet with Rake 26 Automatic syntax checking with Git hooks 29

Chapter 2: Puppet Language and Style 3 3 , Introduction 34 Using community Puppet style 34 Checking your manifests with puppet-lint 36 Using modules 38 Using standard naming conventions 42 Using inline templates 44 Iterating over multiple items 45 Writing powerful conditional statements 47 Using regular expressions in if statements 49 Using selectors and case statements 50 Using the in operator 53 Using regular expression substitutions 54

Page 3: Puppet 3 Cookbook - gbv.de

Table of Contents

Chapter 3: Writing Better Manifests 57 Introduction 58 Using arrays of resources 58 Using definitions 59 Using dependencies 61 Using tags 65 Using run stages 68 Using node inheritance 71 Passing parameters to classes 73 Using class inheritance and overriding 75 Writing reusable, cross-platform manifests 79 Getting information about the environment 8 1 Importing dynamic information 83 Passing arguments to shell commands 84

Chapter 4: Working with Files and Packages 87_ Introduction 87 Making quick edits to config files 88 Using Augeas to automatically edit config files 89 Building config files using snippets 9 1 Using ERB templates 94 Using array iteration in templates 96 Using GnuPG to encrypt secrets 98 Installing packages from a third-party repository 103 Building packages automatically from source 106 Comparing package versions 108

Chapter 5: Users and Virtual Resources 1 1 1 Introduction 112 Using virtual resources 112 Managing users with virtual resources 115 Managing users' SSH access 118 Managing users' customization files 121 Efficiently distributing cron jobs 126 Using schedules to limit when resources can be applied 129 Using host resources 132 Using multiple file sources 133 Distributing directory trees 135 Cleaning up old files 137

Page 4: Puppet 3 Cookbook - gbv.de

Table of Contents

Auditing resources 139 Temporarily disabling resources 140

Chapter 6: Applications 143 Introduction 143 Managing Apache servers 144 Creating Apache virtual hosts 145 Creating Nginx virtual hosts 150 Managing MySQL 153 Managing Ruby 158

Chapter 7: Servers and Cloud Infrastructure 165 Introduction 165 Building high-availability services using Heartbeat 166 Managing NFS servers and file shares 171 Using HAProxy to load-balance multiple web servers 174 Managing firewalls with iptables 178 Managing EC2 instances 188 Managing virtual machines with Vagrant 193

Chapter 8: External Tools and the Puppet Ecosystem 199 Introduction 200 Creating custom facts 200 Adding external facts 202 Setting facts as environment variables 205 Importing configuration data with Hiera 206 Storing secret data with hiera-gpg 210 Generating manifests with puppet resource 213 Generating manifests with other tools 214 Testing your manifests with rspec-puppet 218 Using public modules 221 Using an external node classifier 223 Creating your own resource types 226 Creating your own providers 228 Creating your own functions 231

Chapter 9: Monitoring. Reporting, and Troubleshooting 235 Introduction 235 Doing a dry run 236 Logging command output 237 Logging debug messages 239

Page 5: Puppet 3 Cookbook - gbv.de

Table of Contents

Generating reports 240 Producing automatic HTIVIL documentation 242 Drawing dependency graphs 245 Understanding Puppet errors 248 Inspecting configuration settings 251

Index 253

- c