33,59 €
Start pulling the strings of your infrastructure with Puppet – learn how to configure, customize, and manage your systems more intelligently
If you are a Puppet user, this book will help you on different levels. If you a beginner, we summarize the key Puppet components and give you the elements to have a broader vision. For more experienced users, you will be surprised by with topics on designing, implementing, adapting, and deploying Puppet architectures. If you are expert, you will find topics and information that is rarely exposed in other books, giving you an insight into Puppet's future and its usage on alternative devices.
Puppet has changed the way we manage our systems, but Puppet itself is changing and evolving, and so are the ways we are using it. To tackle our IT infrastructure challenges and avoid common errors when designing our architectures, an up-to-date, practical, and focused view of the current and future Puppet evolution is what we need. With Puppet, you define the state of your IT infrastructure, and it automatically enforces the desired state.
This book will be your guide to designing and deploying your Puppet architecture. It will help you utilize Puppet to manage your IT infrastructure. Get to grips with Hiera and learn how to install and configure it, before learning best practices for writing reusable and maintainable code. You will also be able to explore the latest features of Puppet 4, before executing, testing, and deploying Puppet across your systems. As you progress, Extending Puppet takes you through higher abstraction modules, along with tips for effective code workflow management.
Finally, you will learn how to develop plugins for Puppet - as well as some useful techniques that can help you to avoid common errors and overcome everyday challenges.
This is a collection of specific information about multiple topics related to Puppet and its ecosystem. Starting from a review of the very basics to more advanced topics, mixing practical advice with important theory and broader perspective, along with implementation details.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 432
Veröffentlichungsjahr: 2016
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: June 2016
Production reference: 1170616
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-568-6
www.packtpub.com
Authors
Alessandro Franceschi
Jaime Soriano Pastor
Reviewer
Jeroen Hooyberghs
Commissioning Editor
Priya Singh
Acquisition Editors
Chaitanya Nair
Shaon Basu
Content Development Editor
Merint Thomas Mathew
Technical Editor
Deepti Tuscano
Copy Editor
Merilyn Pereira
Project Coordinator
Francina Pinto
Proofreader
Safis Editing
Indexer
Mariammal Chettiyar
Production Coordinator
Arvindkumar Gupta
Cover Work
Arvindkumar Gupta
Alessandro Franceschi is a long time Puppet user, trainer, and consultant.
He started using Puppet in 2007, automating a remarkable amount of customers' infrastructures of different sizes, natures, and complexities.
He has attended several PuppetConf and PuppetCamps as both speaker and participant, always enjoying the vibrant and friendly community, each time learning something new.
Over the years, he started to publish his Puppet code, trying to make it reusable in different scenarios. The result of this work is the example42 Puppet modules and control repo, complete, feature rich, sample Puppet environment. You can read about example42 at www.example42.com.
You can follow Franceschi on his Twitter account at @alvagante.
Jaime Soriano Pastor was born in Teruel, a small city in Spain. He has always been a passionate about technology and sciences. While studying computer science at the university in his hometown, he had his first encounter with Linux and free software, which is what shaped his career.
He worked for several companies on different and interesting projects, from operating systems in embedded devices to the cloud, giving him a wide view on several fields of software development and systems administration.
Currently, automation, configuration management, and continuous integration form a part of his daily work in the SRE team at Tuenti Technologies.
Jeroen Hooyberghs is an open source and Linux enthusiast, available as consultant at Open-Future in Belgium. In this position, as well as in previous jobs in Linux system administration, he built his technical expertise in a lot of open source solutions. In the last couple of years he's been focusing on system automization and configuration management, mainly using Puppet. Since 2014, he's been a Puppet Certified Professional and Puppet trainer.
As a technical reviewer, he contributed to other Packt Publishing books, such as Mastering Puppet by Thomas Uphill and Puppet Cookbook by John Arundel and Thomas Uphill.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
Puppet has changed the way we manage our systems.
When it was released, other configuration management tools were around, but it was clear that it had something special. It came at the right time with the right approach. The challenges of IT infrastructures were beginning to step up to a new level, and the need to automate common activities such as a quick setup and configuration of systems was becoming a requirement. Puppet presented a sane model, based on the abstraction of resources and the definition of the expected state of a system, using a clear and sysadmin-friendly language.
There are various books about Puppet around, and most of them are very good. This one tries to contribute with solid, no frills content (few pictures, few large blocks of copied and pasted text) and some new perspectives and topics. It begins with an intense technical overview of Puppet, Hiera, and PuppetDB, so that you can use them to design appropriate Puppet architectures that fit your IT infrastructure.
We will explore where our data can be placed, how to design reusable modules, and how they can be used as building blocks for higher abstraction classes. We will try to give a clearer and wider view of what it means to work with Puppet and what are the challenges to face when we introduce it in our systems, from code management to deployment rollouts. We will dive into Puppet's internals and its extension points, showing the multiple ways we can tweak, extend, and hack with it. We will also look at less traditional fields, such as Puppet as a configuration management tool for network devices or cloud services.
Since the first edition of this book was published by Alessandro in 2014, it has been a reference for both learners that wanted to start with Puppet and for experienced users that were looking for a deeper understanding of this tool. During these years, some things have changed in Puppet and the content of the book needed to be refreshed. Probably the most important release of Puppet till now, version 4, happened and it introduced some changes in several aspects. This edition covers the main differences that appeared with this new version, how it is installed, compatibility between versions, and so on. It also adds descriptions for the new language features so it can continue being used as a reference for learners of all levels. Some of the contents that may have become obsolete have been updated or replaced by new implementations or better practices. Some sections have been extended to provide further details on things that have proven to be of interest to the community. And in the last chapter, we will also analyze some of the steps Puppet is taking or will take in the future.
Chapter 1, Puppet Essentials, is an intense and condensed summary of the most important Puppet concepts; it acts as the baseline needed to understand the chapters that follow and a good occasion to refresh and maybe enrich knowledge about the Puppet language and model.
Chapter 2, Managing Puppet Data with Hiera, is dedicated to how to manage our data with Hiera, define the lookup hierarchy, organize data, and use different backends.
Chapter 3, Introducing PuppetDB, covers the installation, configuration, and usage of PuppetDB, and explores the great possibilities that it may enable in the next generations of modules.
Chapter 4, Designing Puppet Architectures, outlines the components to manage when defining a Puppet architecture: the available tools, how to integrate them, how to cope with data and code, and how to organize resources to be applied to nodes.
Chapter 5, Using and Writing Reusable Modules, covers the most important Puppet element from the user's perspective: modules and how to write them in order to be able to reuse them in different infrastructures.
Chapter 6, Higher Abstraction Modules, takes a step further and focuses on modules that use different application modules to compose more complex and wider scenarios.
Chapter 7, Puppet Migration Patterns, analyzes the approaches that can be taken when introducing Puppet in a new or existing infrastructure: methodologies, patterns, techniques, and tips for a successful deployment.
Chapter 8, Code Workflow Management, focuses on how to manage Puppet code, from when is written in an editor, to its management with an SCM, its testing and deployment, and into production.
Chapter 9, Scaling Puppet Infrastructures, faces the challenges in growing infrastructures and how it is possible to make Puppet scale with them.
Chapter 10, Extending Puppet, covers the many available possibilities to extend the core code with custom plugins and gives a deeper view of how Puppet's internals are organized.
Chapter 11, Beyond the System, takes a journey outside the traditional territories, exploring how we can manage with the Puppet network, as well as storage equipment and cloud instances.
Chapter 12, Future Puppet, is a step beyond Puppet 4 and how the project may evolve in future versions.
You can test the Puppet code present in this book on any Linux system connected to the Internet.
This book is accessible to any Puppet user.
If you are totally new to Puppet, be sure to thoroughly read Chapter 1, Puppet Essentials, and have properly understood its principles before continuing.
If you are an intermediate user, it is recommended that you read the chapters in order.
If you are an advanced user, you may pick from different pages useful information and new insights on topics you should already know.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "When the Master receives a connection then it looks in its manifests (starting from /etc/puppet/manifests/site.pp) what resources have to be applied for that client host, also called node."
A block of code is set as follows:
Any command-line input or output is written as follows:
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
There are moments in our professional life when we meet technologies that trigger an inner wow effect. We realize there's something special in them and we start to wonder how they can be useful for our current needs and, eventually, wider projects. Puppet, for me, has been one of these turning point technologies. I have reason to think that we might share a similar feeling.
If you are new to Puppet, you are probably starting from the wrong place, there are better fitting titles around to grasp its basic concepts.
This book won't indulge too much on the fundamentals, but don't despair, this chapter might help for a quick start. It provides the basic Puppet background needed to understand the rest of the contents and may also offer valuable information to more experienced users.
We are going to review the following topics:
The contents of this chapter are quite dense, so take your time to review and assimilate them if they sound new or look too complex; the path towards Puppet awareness is never too easy.
Puppet is a configuration management and automation tool; we use it to install, configure, and manage components of our servers.
Initially written in Ruby, some parts were rewritten in version 4 in Clojure. Released with an open source license (Apache 2), it can run on any Linux distribution, many other UNIX variants (Solaris, *BSD, AIX, and Mac OS X), and Windows. Its development started in 2005 by Luke Kanies as an alternative approach to the existing configuration management tools (most notably CFEngine and BladeLogic). The project has grown year after year; Kanies' own company, Reductive Labs, renamed in 2010 to Puppet Labs, has received a total funding of $ 45.5 million in various funding rounds (among the investors there are names such as VMware, Google, and Cisco).
Now, it is one of the top 100 fastest growing companies in the US. It employs more than 150 people and it has a solid business based on open source software, consisting of consulting services, training, certifications, and Puppet Enterprise. Puppet Enterprise is the commercial version that is based on the same open source Puppet codebase, but it provides an integrated stack with lots of tools, such as a web GUI that improves and makes Puppet usage and administration easier, and more complete support for some major Linux distributions, Mac OS X, and Microsoft Windows Server.
The Puppet ecosystem features a vibrant, large, and active community, which discusses on the Puppet Users and Puppet Developers Google groups, on the crowded free node #puppet IRC channel, at the various Puppet Camps that are held multiple times a year all over the world, and at the annual PuppetConf, which is improving and getting bigger year after year.
Various software products are complementary to Puppet; some of them are developed by Puppet Labs:
The community has produced other tools and resources. The most noticeable ones are:
IT operations have changed drastically in the past few years. Virtualization, cloud, business needs, and emerging technologies have accelerated the pace of how systems are provisioned, configured, and managed.
The manual setup of a growing number of operating systems is no longer a sustainable option. At the same time, in-house custom solutions to automate the installation and the management of systems cannot scale in terms of required maintenance and development efforts.
For these reasons, configuration management tools such as Puppet, Chef, CFEngine, Rudder, Salt, and Ansible (to mention only the most known open source ones) are becoming increasingly popular in many infrastructures.
They show infrastructure as code, that allows, in systems management, the use of some of the same best practices in software development for decades, such as maintainability, code reusability, testability, or version control.
Once we can express the status of our infrastructure with versioned code, there are powerful benefits:
With these kinds of tools, we can have a system provisioned from zero to production in a few minutes, or we can quickly propagate a configuration change over our whole infrastructure automatically.
Their power is huge and has to be handled with care; as we can automate massive and parallelized setups and configurations of systems; we might automate distributed destructions.
With great power comes great responsibility.
Before diving into installation and configuration details, we need to clarify and explain some Puppet terminology to get the whole picture.
Puppet features a declarative Domain Specific Language (DSL), which expresses the desired state and properties of the managed resources.
Resources can be any component of a system, for example, packages to install, services to start, files to manage, users to create, and also custom and specific resources, such as MySQL grants, Apache virtual hosts, and so on.
Puppet code is written in manifests, which are simple text files with a .pp extension. Resources can be grouped in classes (do not consider them classes as in OOP, they aren't). Classes and all the files needed to define the configurations required are generally placed in modules, which are directories structured in a standard way that are supposed to manage specific applications or system's features (there are modules to manage Apache, MySQL, sudo, sysctl, networking, and so on).
When Puppet is executed, it first runs facter, a companion application, which gathers a series of variables about the system (IP address, hostname, operating system, and MAC address), which are called facts and are sent to the Master.
Facts and user-defined variables can be used in manifests to manage how and what resources to provide to clients.
When the Master receives a connection, then it looks in its manifests (starting from /etc/puppet/manifests/site.pp) what resources have to be applied for that client host, also called node.
The Master parses all the DSL code and produces a catalog, which is sent back to the client (in PSON format, a JSON variant used in Puppet). The production of the catalog is often referred to as catalog compilation.
Once the client receives the catalog, it starts to apply all the resources declared there; packages are installed (or removed), services started, configuration files created or changed, and so on. The same catalog can be applied multiple times, if there are changes on a managed resource (for example, a manual modification of a configuration file) they are reverted back to the state defined by Puppet; if the system's resources are already at the desired state, nothing happens.
This property is called idempotence and is at the root of the Puppet declarative model; since it defines the desired state of a system, it must operate in a way that ensures that this state is obtained whatever are the starting conditions and the number of times Puppet is applied.
Puppet can report the changes it makes on the system and audit the drift between the system's state and the desired state as defined in its catalog.
