Book Image

Puppet Cookbook - Third Edition

Book Image

Puppet Cookbook - Third Edition

Overview of this book

Table of Contents (17 chapters)
Puppet Cookbook Third Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Using arrays of resources


Anything that you can do to a resource, you can do to an array of resources. Use this idea to refactor your manifests to make them shorter and clearer.

How to do it…

Here are the steps to refactor using arrays of resources:

  1. Identify a class in your manifest where you have several instances of the same kind of resource, for example, packages:

      package { 'sudo' : ensure => installed }
      package { 'unzip' : ensure => installed }
      package { 'locate' : ensure => installed }
      package { 'lsof' : ensure => installed }
      package { 'cron' : ensure => installed }
      package { 'rubygems' : ensure => installed }
  2. Group them together and replace them with a single package resource using an array:

      package
      {
        [ 'cron',
        'locate',
        'lsof',
        'rubygems',
        'sudo',
        'unzip' ]:
        ensure => installed,
      }

How it works…

Most of Puppet's resource types can accept an array instead of a single name, and will create one instance for each of the elements...