Like the parameter defaults we introduced in the previous chapter Puppet Infrastructure , Hiera may be used to provide default values to classes. Automatic parameter lookup via Hiera has been on by default since version 3 of Puppet.
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.
- We'll create a class with parameters and no default values. Create the directory
modules/mysql/manifests
and then createmodules/mysql/manifests/init.pp
with the following content:
class mysql ( Integer $port, String $socket, Variant[String,Array[String]] $package ) { notify {"Port: ${port} Socket: ${socket} Package: ${package}": } }
- Update your
common.yaml
file in Hiera with the default values for themysql
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...