www.it-ebooks.info Mastering Puppet Second Edition Master Puppet for configuration management of your systems in an enterprise deployment Thomas Uphill BIRMINGHAM - MUMBAI www.it-ebooks.info Mastering Puppet Second Edition 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 author, 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: July 2014 Second edition: February 2016 Production reference: 1220216 Published by Packt Publishing Ltd Livery Place 35 Livery Street Birmingham B3 2PB, UK ISBN 978-1-78588-810-6 www.packtpub.com www.it-ebooks.info Credits Author Project Coordinator Thomas Uphill Kinjal Bari Reviewer Proofreader Bas Grolleman Safis Editing Commissioning Editor Priya Singh Tejal Daruwale Soni Acquisition Editor Production Coordinator Nadeem Bagban Aparna Bhagat Content Development Editor Mehvash Fatima Indexer Cover Work Aparna Bhagat Technical Editor Taabish Khan Copy Editors Ting Baker Sneha Singh www.it-ebooks.info About the Author Thomas Uphill is a long-time user of Puppet He has presented Puppet tutorials at LOPSA-East, Cascada, and PuppetConf He has also been a system administrator for over 20 years, working primarily with RedHat systems; he is currently a RedHat Certified Architect (RHCA) When not running the Puppet User Group of Seattle (PUGS), he volunteers for the LOPSA board and his local LOPSA chapter, SASAG He blogs at http://ramblings.narrabilis.com www.it-ebooks.info About the Reviewer Bas Grolleman works as a self-taught freelance Puppet professional in the Netherlands, he has his name in the code of many large-scale deployments He learned the pain of scaling Puppet the hard way, that is, trial and error and spending hours going through a maze of dependencies Now, he mostly tells people to take the time to it right www.it-ebooks.info www.PacktPub.com eBooks, discount offers, and more 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 customercare@packtpub.com 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 TM 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 Why subscribe? • Fully searchable across every book published by Packt • Copy and paste, print, and bookmark content • On demand and accessible via a web browser www.it-ebooks.info Table of Contents Preface v Chapter 1: Dealing with Load/Scale Divide and conquer Certificate signing Reporting Storeconfigs Catalog compilation puppetserver 3 Building a Puppet master Certificates systemd Creating a load balancer Keeping the code consistent 14 One more split One last split or maybe a few more Conquer by dividing Creating an rpm 17 18 21 22 Using Puppet resource to configure cron 24 Creating the yum repository 25 Summary 27 Chapter 2: Organizing Your Nodes and Data Getting started Organizing the nodes with an ENC A simple example Hostname strategy Modified ENC using hostname strategy 29 29 29 30 33 35 LDAP backend 39 OpenLDAP configuration 39 [i] www.it-ebooks.info Table of Contents Hiera 44 Configuring Hiera 45 Using hiera_include 48 Summary 54 Chapter 3: Git and Environments 55 Environments 55 Environments and Hiera 58 Multiple hierarchies Single hierarchy for all environments 58 60 Using post-receive to set up environments Puppet-sync 76 79 Directory environments 61 Git 64 Why Git? 65 A simple Git workflow 66 Git hooks 75 Using Git hooks to play nice with other developers 82 Not playing nice with others via Git hooks 85 Git for everyone 89 Summary 92 Chapter 4: Public Modules 93 Getting modules 93 Using GitHub for public modules 93 Updating the local repository 95 Modules from the Forge 96 Using Librarian 98 Using r10k 100 Using Puppet-supported modules 106 concat 106 inifile 112 firewall 117 Logical volume manager 121 Standard library 124 Summary 126 Chapter 5: Custom Facts and Modules Module manifest files Module files and templates Naming a module Creating modules with a Puppet module Comments in modules Multiple definitions 127 128 131 132 133 135 138 [ ii ] www.it-ebooks.info Table of Contents Custom facts 141 Creating custom facts 141 Creating a custom fact for use in Hiera 148 CFacter 150 Summary 151 Chapter 6: Custom Types 153 Chapter 7: Reporting and Orchestration 175 Chapter 8: Exported Resources 201 Parameterized classes 153 Data types 154 Defined types 155 Types and providers 166 Creating a new type 167 Summary 174 Turning on reporting 175 Store 176 Logback 177 Internet relay chat 177 Foreman 182 Installing Foreman 182 Attaching Foreman to Puppet 183 Using Foreman 185 Puppet GUIs 187 mcollective 187 Installing ActiveMQ 189 Configuring nodes to use ActiveMQ 192 Connecting a client to ActiveMQ 195 Using mcollective 198 Ansible 199 Summary 199 Configuring PuppetDB – using the Forge module Manually installing PuppetDB Installing Puppet and PuppetDB Installing and configuring PostgreSQL Configuring puppetdb to use PostgreSQL Configuring Puppet to use PuppetDB Exported resource concepts Declaring exported resources Collecting exported resources Simple example – a host entry [ iii ] www.it-ebooks.info 201 205 205 206 207 208 209 210 210 210 Chapter 10 To compile for another environment, specify the environment with –environment, as shown in the following command: [root@stand ~]# puppet master compile client.example.com debug trace logdest /var/log/puppetlabs/client.example.com.log environment sandbox The classes.txt file The /opt/puppetlabs/puppet/cache/state/classes.txt file contains a list of classes applied to the machine If you are having trouble with a node, you can search here for the last set of classes that were successfully applied to a node But, when you are having trouble, you are most interested in the classes in the current catalog and the classes that are different or missing We can use jq again to query the JSON of the current catalog, as shown in the following command: [root@client ~]# jq classes[]