Preface
Puppet is a configuration management tool that has enjoyed phenomenal growth over the last few years. Propelled by increasing demands on sysadmins, and the continuous growth of infrastructure (both physical and virtual), Puppet has been one of the key technology components of the DevOps movement. This cultural shift focuses on breaking down the silo between development and operations. Tools like Puppet are important to this movement because it allows application deployment knowledge to be expressed as code to build automated release platforms.
Puppet is also helping lead the path towards software-defined infrastructure (or infrastructure as code). As more systems in data centers support better APIs, the importance of centralized configuration management increases. Puppet is leading this trend by leveraging its model to manage more than the roles of individual systems. It also supports network devices, load balancers, and managing virtual machine instances.
All system configurations in Puppet are expressed as resources that model complex configurations using Puppets Domain Specific Language (DSL). Puppet supports a large set of native resources for modeling the desired state of a system. Resources already exist for managing most common elements of a system (users, groups, packages, services). These native resources are implemented in Ruby using Puppets type and provider APIs.
The power of Puppet lies in its ability to manage the state of complex systems using this simple resource model. This book discusses the highly extensible resource model and the framework around it. It explores the extension points and how to leverage them to expand Puppets functionality.
Puppet has a vibrant user community, and has seen an explosion of content in the last few years. Puppets online documentation and existing books serve as great references for language constructs and architecture. We have always considered the type and provider APIs as one of the most important and least documented aspects of Puppet. This book is aimed at lowering the barrier for writing types and providers by providing sufficient instructions and examples.
Most of what we learned about types and providers has been through trial and error following the evolution of Puppets source code changes. The experience of writing a large number of types and providers has really opened us to the potential of Puppet. Learning how to do it by reading source code, however, has been a long and painful process fraught with many mistakes and poor implementations.
The goal of this book is to explain all of the concepts of types and providers in detail along with many of the lessons we have learned. We hope this helps Puppet users better understand why they should be writing types and providers, and also arm them with enough information on how to properly implement them.
The book walks through examples to demonstrate concepts and also shows the user how to delve into Puppets source code to get a better understanding of how types and providers are implemented internally.
Its also worth noting that when we explore the APIs for developing custom types and providers (in , respectively), we occasionally reimplement functionality that already exists in the Puppet source code. The examples in this book are not intended to be replacement code per sethey are intentionally simplified and intended to serve as an reference on how to implement the important features from the type and provider APIs.
Who Is This Book For?
This book is targeted at users who have a fundamental understanding of Linux/Unix systems and familiarity with basic Puppet concepts. This book is not intended to provide details of the basic language constructs of Puppet, simply enough details to discuss implementing custom Puppet resources via Ruby. It assumes that readers already have experience writing Puppet manifests and does not cover these concepts. For more information on topics specific to the Puppet DSL (classes, defines, nodes, etc.), we recommend checking out the official documentation at the Puppet Labs website.
This book was also written to serve as a reference for developers who are writing and maintaining custom resource types. It explains the concepts required for extending Puppet by implementing custom resources as types and providers, and contains many code examples written in Ruby. It assumes that readers have some familiarity with coding, but it also explains most Ruby concepts as they are introduced.
What Does This Book Cover?
This book focuses on how Puppet is extended by creating custom resource types using the type and provider APIs. We provide an overview on Puppet resources and terminology then dive into writing types and providers in Ruby. This book is broken down into the following chapters:
- , Puppet Resources : This chapter provides an in-depth explanation of the characteristics of resources. In Puppet, resources are the basic building blocks used to model configuration state. A basic understanding of resources is required to understand what the rest of this book will be teaching about the type and provider APIs.
- , Types : This chapter covers Puppets type API, focusing on how it is used to create new resource types that Puppet can manage, along with the list of attributes used to describe them.
- , Providers : This chapter covers the provider API, explaining how providers interact with the underlying system in order to achieve the desired state of a declared resource.
- , Advanced Types and Providers : This chapter expands the discussion of the type and provider APIs with some more advanced concepts.
Resources
- Puppet online documentation
- Twitter, @bodepd
- Twitter, @sesshin
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width
Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold
Shows commands or other text that should be typed literally by the user. Constant width italic
Shows text that should be replaced with user-supplied values or by values determined by context.
Tip
This icon signifies a tip, suggestion, or general note.
Warning
This icon indicates a warning or caution.
Using Code Examples
This book is here to help you get your job done. In general, if this book includes code examples, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless youre reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from OReilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your products documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: Puppet Types and Providers