Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Extending Puppet
Extending Puppet

Extending Puppet: Design, manage, and deploy your Puppet architecture with the help of real-world scenarios.

Arrow left icon
Profile Icon Alessandro Franceschi
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.9 (16 Ratings)
Paperback Jun 2014 328 pages 1st Edition
eBook
$12.99 $18.99
Paperback
$29.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Alessandro Franceschi
Arrow right icon
$19.99 per month
Full star icon Full star icon Full star icon Full star icon Half star icon 4.9 (16 Ratings)
Paperback Jun 2014 328 pages 1st Edition
eBook
$12.99 $18.99
Paperback
$29.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$12.99 $18.99
Paperback
$29.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Extending Puppet

Chapter 2. Hiera

The history of Puppet is an interesting example of how best practices have evolved with time, following new usage patterns and contributions from the community.

Once people started to write manifests and express the desired state of their systems with Puppet's DSL, they found themselves placing custom variables and parameters that expressed various resources of their infrastructures (IP addresses, hostnames, paths, URLs, names, properties, lists of objects, and so on) inside the code used to create the needed resource types.

At times, variables were used to classify and categorize nodes (systems' roles, operational environments, and so on); at other times, facts (such as $::operatingsystem) were used to provide resources with the right names and paths according to the underlying OS.

Variables could be defined in different places; they could be set via an ENC, inside node declarations, or inside classes.

There wasn't (and actually, still there isn&apos...

Installing and configuring Hiera

From Puppet 3.x, Hiera has been officially integrated, and it is installed as a dependency when we install Puppet.

On Puppet 2.x, we need to install Hiera separately on the node where the Puppet Master resides: we need both the hiera and hiera-puppet packages, either via the OS native packaging system or via gem.

Hiera is not required on the clients unless they operate in a Masterless setup.

Its configuration file is hiera.yaml, and its path depends on how it is invoked, which can be either of the following ways:

  • When invoked from Puppet, the path will be /etc/puppet/hiera.yaml (/etc/puppetlabs/puppet/hiera.yaml for Puppet Enterprise)
  • When invoked from the CLI or when used within Ruby code, the path is /etc/hiera.yaml

It makes sense to create a symlink, and be sure to always use and edit the same file using the following command:

ln -s /etc/hiera.yaml /etc/puppet/hiera.yaml

The file is a YAML hash, where the top-level keys are Ruby symbols with a colon (:) prefix...

Working with the command line on a YAML backend

When we use a backend based on files such as JSON or YAML, which are the most commonly used, we have to recreate on the filesystem the hierarchy defined in our hiera.yaml file; the files that contain Hiera data must be placed in these directories.

Let's see Hiera in action. Provide a sample hierarchy configuration as follows:

:hierarchy:
  - "nodes/%{::fqdn}"
  - "env/%{::env}"
  - common

:yaml:
  :datadir: /etc/puppet/hieradata

We have to create a directory structure as follows:

mkdir -p /etc/puppet/hieradata/nodes
mkdir -p /etc/puppet/hieradata/env

Then, work on the YAML files as shown:

vi /etc/puppet/hieradata/nodes/web01.example42.com.yaml
vi /etc/puppet/hieradata/env/production.yaml
vi /etc/puppet/hieradata/env/test.yaml
vi /etc/puppet/hieradata/common.yaml

The previous files are plain YAML files where we can specify the values for any Hiera-managed variable. These values can be strings, arrays, or hashes.

We can place...

Using Hiera in Puppet

Using the Hiera functions, the data stored in Hiera can be retrieved by the Puppet Master while compiling the catalog. In our manifests, we can have something like the following:

$dns_servers = hiera("dns_servers")

Note that the name of the Puppet variable need not be the same as that of the Hiera one, so the previous code can also be as follows:

$my_dns_servers = hiera("dns_servers")

This assigns to the variable $my_dns_servers the top value (the first one found while crossing the hierarchy of data sources) retrieved by Hiera for the key dns_servers.

We can also merge arrays and hashes here; so in order to retrieve an array of all the values in the hierarchy's data sources of a given key and not just the first one, we can use hiera_array() as follows:

$my_dns_servers = hiera_array("dns_servers")

If we expect a hash value for a given key, we can use the hiera() function to retrieve the top value found, or we can use hiera_hash() to merge...

Additional Hiera backends

The possibility of creating and adding different backends where data is to be stored is one of the strong points of Hiera as it allows storing Puppet data in any possible source.

This allows integrations with existing tools and gives more options to provide data in a safe and controlled way, for example, a custom web frontend or a CMDB.

Let's review some of the most interesting backends that exist.

The hiera-file backend

The hiera-file backend (https://github.com/adrienthebo/hiera-file) conceived by Adrien Thebo to manage a type of data that previously couldn't be stored in a sane way in Hiera, that is, plain files.

To install it, just clone the previous git repository in modulepath or use its gem as follows:

gem install hiera-file

We configure it by specifying the file backend, the hierarchy setting we want, and the datadir path where our files are placed:

---
:backends:
  - file
:hierarchy:
  - "fqdn/%{fqdn}"
  - "role/%{role}"
  - &quot...

Using Hiera as an ENC

Hiera provides an interesting function called hiera_include, which allows users to include all the classes defined for a given key.

This, in practice, exploits the Hiera flexibility to provide classes to nodes as an External Node Classifier does.

It's enough to place the following line in our site.pp file at /etc/puppet/manifests/:

hiera_include('classes')

Define in our data sources a classes key with an array of the classes to be included.

In a YAML-based backend, it would look like the following:

---
classes:
  - apache
  - mysql
  - php

This is exactly the same as having some declarations in our site.pp as follows:

include apache
include mysql
include php

The classes key (can have any name, but classes is a standard de facto) contains an array that is merged along the hierarchy. So we can define in a common.yaml file the classes that we want to include in all our nodes, and include specific classes for specific servers, adding them to the different layers...

Installing and configuring Hiera


From Puppet 3.x, Hiera has been officially integrated, and it is installed as a dependency when we install Puppet.

On Puppet 2.x, we need to install Hiera separately on the node where the Puppet Master resides: we need both the hiera and hiera-puppet packages, either via the OS native packaging system or via gem.

Hiera is not required on the clients unless they operate in a Masterless setup.

Its configuration file is hiera.yaml, and its path depends on how it is invoked, which can be either of the following ways:

  • When invoked from Puppet, the path will be /etc/puppet/hiera.yaml (/etc/puppetlabs/puppet/hiera.yaml for Puppet Enterprise)

  • When invoked from the CLI or when used within Ruby code, the path is /etc/hiera.yaml

It makes sense to create a symlink, and be sure to always use and edit the same file using the following command:

ln -s /etc/hiera.yaml /etc/puppet/hiera.yaml

The file is a YAML hash, where the top-level keys are Ruby symbols with a colon (:) prefix...

Left arrow icon Right arrow icon

Description

This book is a clear, detailed and practical guide to learn about designing and deploying you puppet architecture, with informative examples to highlight and explain concepts in a focused manner. This book is designed for users who already have good experience with Puppet, and will surprise experienced users with innovative topics that explore how to design, implement, adapt, and deploy a Puppet architecture. The key to extending Puppet is the development of types and providers, for which you must be familiar with Ruby.

What you will learn

  • Use Puppet to manage network, cloud, and virtualization devices
  • Become a Hiera and PuppetDB power user
  • Study the different approaches to Puppet architecture design
  • Master the art of writing and maintaining reusable modules
  • Explore strategies and patterns on how to introduce Puppet automation
  • Manage and test a Puppet code workflow
  • Design scalable Puppet infrastructures

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 24, 2014
Length: 328 pages
Edition : 1st
Language : English
ISBN-13 : 9781783981441
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jun 24, 2014
Length: 328 pages
Edition : 1st
Language : English
ISBN-13 : 9781783981441
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 110.97
Extending Puppet
$29.99
Mastering Puppet
$47.99
Puppet Reporting and Monitoring
$32.99
Total $ 110.97 Stars icon

Table of Contents

13 Chapters
1. Puppet Essentials Chevron down icon Chevron up icon
2. Hiera Chevron down icon Chevron up icon
3. PuppetDB Chevron down icon Chevron up icon
4. Designing Puppet Architectures Chevron down icon Chevron up icon
5. Using and Writing Reusable Modules Chevron down icon Chevron up icon
6. Higher Abstraction Modules Chevron down icon Chevron up icon
7. Deploying and Migrating Puppet Chevron down icon Chevron up icon
8. Code Workflow Management Chevron down icon Chevron up icon
9. Scaling Puppet Infrastructures Chevron down icon Chevron up icon
10. Writing Puppet Plugins Chevron down icon Chevron up icon
11. Beyond the System Chevron down icon Chevron up icon
12. Future Puppet Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.9
(16 Ratings)
5 star 87.5%
4 star 12.5%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Michael D. Simpson Mar 13, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Well written and very useful. Gives a great set of best practices for how to use Puppet the right way. Not for the absolute beginner, but great for someone like me who knew the basics but wasn't clear on how to best to use Hira, parametrize modules, test modules, do node classification, use Puppet DB, etc. It helps connect the dots in the Puppet ecosystem. I felt a lot more confident after reading this book.
Amazon Verified review Amazon
Peter Van Bouwel Oct 04, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a great book. When you are reading the book it becomes clear that the author has good knowledge of Puppet and that he has been in the puppet world for a long time (and evolved with it).I really enjoy how he gives solutions to problems. Rather than giving solely his own view he gives multiple approaches and explains what he thinks are the advantages/disadvantages of a certain approach.One of the best technical books I have read.
Amazon Verified review Amazon
Monica Aug 20, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is probably the ultimate guide to a complete vision of your sysadmin/devop/puppetmaster daily work in complex infrastructures. It offers some extremely interesting ideas about all the challenges that sooner or later I had to face in my daily work on Puppet in the last years. It's nicely balanced between advanced tools descriptions and architectural choices explanation, and it's so clearly written that I couldn't stop reading until the end, almost like a novel, basically because Alessandro often also tells how he came to certain conclusions and it's just like he's sitting next to you and he's giving you some advices from his wide experience. Definitely a must-have!
Amazon Verified review Amazon
Edwin Biemond Jul 21, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I really like this book because finally there is a puppet book not about writing puppet modules but over designing your own puppet architecture, all the hiera possible backend you can have, writing reusable modules, High Availability, the development process toegether with code quality & testing and Future Puppet.When you read this book you will notice that Alessandro has seen it all, done it all. He explains every option you can have with some explaining examples. Especially the Designing Puppet architectures chapter is a must have, this can save you so much time and future problems when you start with your own Puppet environment.
Amazon Verified review Amazon
Michael Aug 15, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I've purchased and read about 4 or 5 puppet books previously, and i've found them to all be pretty good.This book however is on another level. It's FANTASTIC!It summarises a book like 'pro-puppet' in the 1st chapter alone, before then taking a deep dive into technologies like hiera, puppetdb and coding styles and some the future changes to Puppet.It's a must for any seasoned Puppet user who wants to learn a bit more. I've used puppet for many years now, but still learnt so many new things from this book.Just buy it now.Michael
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.