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
About the Authors
About the Reviewers

Passing parameters from Hiera

Like the parameter defaults we introduced in the previous chapter, Hiera may be used to provide default values to classes. This feature requires Puppet Version 3 and higher.

Getting ready

Install and configure hiera as we did in Chapter 2, Puppet Infrastructure. Create a global or common yaml file; this will serve as the default for all values.

How to do it...

  1. Create a class with parameters and no default values:

    t@mylaptop ~/puppet $ mkdir -p modules/mysql/manifests t@mylaptop ~/puppet $ vim modules/mysql/manifests/init.pp
    class mysql ( $port, $socket, $package ) {
      notify {"Port: $port Socket: $socket Package: $package": }
  2. Update your common .yaml file in Hiera with the default values for the mysql class:

    mysql::port: 3306
    mysql::package: 'mysql-server'
    mysql::socket: '/var/lib/mysql/mysql.sock'

    Apply the class to a node, you can add the mysql class to your default node for now.

    node default {
      class {'mysql': }
  3. Run puppet agent and verify the output...