Book Image

Puppet 5 Cookbook - Fourth Edition

By : Thomas Uphill
Book Image

Puppet 5 Cookbook - Fourth Edition

By: Thomas Uphill

Overview of this book

Puppet is a configuration management system that automates all your IT configurations, giving you control of managing each node. Puppet 5 Cookbook will take you through Puppet's latest and most advanced features, including Docker containers, Hiera, and AWS Cloud Orchestration. Updated with the latest advancements and best practices, this book delves into various aspects of writing good Puppet code, which includes using Puppet community style, checking your manifests with puppet-lint, and learning community best practices with an emphasis on real-world implementation. You will learn to set up, install, and create your first manifests with version control, and also learn about various sysadmin tasks, including managing configuration files, using Augeas, and generating files from snippets and templates. As the book progresses, you'll explore virtual resources and use Puppet's resource scheduling and auditing features. In the concluding chapters, you'll walk through managing applications and writing your own resource types, providers, and external node classifiers. By the end of this book, you will have learned to report, log, and debug your system.
Table of Contents (16 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

Using resource defaults


Resource defaults allow you to specify the default attribute values for a resource. Resource defaults are valid for a given resource type and within the current scope. If you define a resource default in a class, then all resources of that type within the class will be given those defaults. In this example, we'll show you how to specify a resource default for the File type.  

How to do it...

To show you how to use resource defaults, we'll create an apache module. Within this module, we will specify that all file resources require the httpd package and the default owner and group are the apache user:

  1. Create an apache module and create a resource default for the File type:
class apache {
  File {
    owner   => 'apache',
    group   => 'apache',
    mode    => '0644',
    require => Package['httpd']
  }
  package {'httpd': ensure => 'installed'}
}
  1. Create html files within the /var/www/html directory:
$index = @(INDEX)
  <html>
    <body>
      ...