examples/hiera/README.md
This demo consists of:
Below various usage scenarios can be tested using this module.
The examples below assume you:
puppet apply to create a /tmp/ntp.conf file containing the two pool.ntp.org addresses$ sed -i '6,8 s/^/#/' data/common.yaml
$ puppet apply site.pp --hiera_config=hiera.yaml --modulepath=modules
Notice: Compiled catalog for node.corp.com in environment production in 0.04 seconds
Notice: Adding users::common
Notice: /Stage[main]/Users::Common/Notify[Adding users::common]/message: defined 'message' as 'Adding users::common'
Notice: /Stage[main]/Ntp::Config/File[/tmp/ntp.conf]/ensure: defined content as '{sha256}949c7247dbe0870258c921418cc8b270afcc57e1aa6f9d9933f306009ede60d0'
Notice: Applied catalog in 0.02 seconds
$ cat /tmp/ntp.conf
server 1.pool.ntp.org
server 2.pool.ntp.org
puppet apply to update /tmp/ntp.conf to contain the two ntp.example.com addresses$ sed -i '6,8 s/^#//' data/common.yaml
$ puppet apply site.pp --hiera_config=hiera.yaml --modulepath=modules
Notice: Compiled catalog for node.corp.com in environment production in 0.04 seconds
Notice: Adding users::common
Notice: /Stage[main]/Users::Common/Notify[Adding users::common]/message: defined 'message' as 'Adding users::common'
Notice: /Stage[main]/Ntp::Config/File[/tmp/ntp.conf]/content: content changed '{sha256}949c7247dbe0870258c921418cc8b270afcc57e1aa6f9d9933f306009ede60d0' to '{sha256}28ced955a8ed9efd7514b2364fe378ba645ab947f26e8c0b4d84e8368f1257a0'
Notice: Applied catalog in 0.02 seconds
$ cat /tmp/ntp.conf
server ntp1.example.com
server ntp2.example.com
dc1 to demonstrate data/dc1.yaml overrides the ntp::config::ntpservers values in data/common.yamldc1 nodes will
dc2 would use the site-wide defaults$ FACTER_location=dc1 puppet apply site.pp --hiera_config=hiera.yaml --modulepath=modules
Notice: Compiled catalog for node.corp.com in environment production in 0.04 seconds
Notice: Adding users::dc1
Notice: /Stage[main]/Users::Dc1/Notify[Adding users::dc1]/message: defined 'message' as 'Adding users::dc1'
Notice: Adding users::common
Notice: /Stage[main]/Users::Common/Notify[Adding users::common]/message: defined 'message' as 'Adding users::common'
Notice: /Stage[main]/Ntp::Config/File[/tmp/ntp.conf]/content: content changed '{sha256}28ced955a8ed9efd7514b2364fe378ba645ab947f26e8c0b4d84e8368f1257a0' to '{sha256}39227f1cf8d09623d2e66b6622af2e8db01ab26f77a5a2e6d6e058d0977f369b'
Notice: Applied catalog in 0.02 seconds
$ cat /tmp/ntp.conf
server ntp1.dc1.example.com
server ntp2.dc1.example.com
Now simulate a machine in dc2, because there is no data for dc2 it uses the site wide defaults and
does not include the users::dc1 class anymore
$ FACTER_location=dc2 puppet apply site.pp --hiera_config=hiera.yaml --modulepath=modules
Notice: Compiled catalog for node.corp.com in environment production in 0.04 seconds
Notice: Adding users::common
Notice: /Stage[main]/Users::Common/Notify[Adding users::common]/message: defined 'message' as 'Adding users::common'
Notice: /Stage[main]/Ntp::Config/File[/tmp/ntp.conf]/content: content changed '{sha256}39227f1cf8d09623d2e66b6622af2e8db01ab26f77a5a2e6d6e058d0977f369b' to '{sha256}28ced955a8ed9efd7514b2364fe378ba645ab947f26e8c0b4d84e8368f1257a0'
Notice: Applied catalog in 0.02 seconds
$ cat /tmp/ntp.conf
server ntp1.example.com
server ntp2.example.com
You could create override data in the following places for a machine in location=dc2, they will be searched in this order and the first one with data will match.
In this example due to the presence of common.yaml that declares ntpservers the classes will never be searched, it will have precedence.