|
1 |
| -A working demo of Hiera with YAML and Puppet backends. |
| 1 | +A working demo of Hiera with YAML backend. |
2 | 2 | ======================================================
|
3 | 3 |
|
4 | 4 | This demo consists of:
|
5 | 5 |
|
6 |
| - * A NTP module that has defaults for pool.ntp.org servers |
7 |
| - * A common data module where module users can create override data in pp files |
8 |
| - * A YAML data source in etc/hieradb where users can override data in yaml files |
9 |
| - * A couple of users modules that just notify the fact that they are being included |
10 |
| - * In Hiera data files a key called _classes_ that decides what to include on a node |
| 6 | +- A **NTP** module that has defaults for *pool.ntp.org* servers |
| 7 | +- A **YAML** data source in the *data/* directory where users can override data in yaml files |
| 8 | +- A **Users** module that has a few manifests that simply notify that they are being included |
| 9 | +- In Hiera data files a key called **classes** that decides what to include on a node |
11 | 10 |
|
12 | 11 | Below various usage scenarios can be tested using this module.
|
13 | 12 |
|
14 |
| -The examples below assume you have Hiera already installed and that you have |
15 |
| -hiera-puppet cloned from github and running these commands in _hiera-puppet/example_ as cwd. |
| 13 | +The examples below assume you: |
| 14 | +- Have the puppet-agent already installed |
| 15 | +- You have this repository cloned from github |
| 16 | +- Are running these commands from within the *examples/hiera* directory as cwd. |
16 | 17 |
|
17 | 18 | Module from forge with module defaults
|
18 | 19 | --------------------------------------
|
19 | 20 |
|
20 |
| - * Move the _modules/data_ directory to _modules/data.bak_ to avoid overrides |
21 |
| - used further in the example |
22 |
| - * Run puppet, creates _/etc/ntp.conf_ with ntp.org addresses |
23 |
| - * The _hiera\_include()_ function includes just _users::common_ |
24 |
| - |
25 |
| -<pre> |
26 |
| -$ mv modules/data modules/data.bak |
27 |
| -$ puppet apply --config etc/puppet.conf site.pp |
28 |
| -notice: /Stage[main]/Ntp::Config/File[/tmp/ntp.conf]/ensure: defined content as '{md5}7045121976147a932a66c7671939a9ad' |
29 |
| -notice: /Stage[main]/Users::Common/Notify[Adding users::common]/message: defined 'message' as 'Adding users::common' |
| 21 | +- Comment out lines 6-8 of [data/common.yaml](data/common.yaml#L6-8) to avoid overrides used further in the example |
| 22 | +- Run a `puppet apply` to create a */tmp/ntp.conf* file containing the two *pool.ntp.org* addresses |
| 23 | +- The *users::common* class should also be present in your catalog |
| 24 | + |
| 25 | +```shell |
| 26 | +$ sed -i '6,8 s/^/#/' data/common.yaml |
| 27 | +$ puppet apply site.pp --hiera_config=hiera.yaml --modulepath=modules |
| 28 | +Notice: Compiled catalog for node.corp.com in environment production in 0.04 seconds |
| 29 | +Notice: Adding users::common |
| 30 | +Notice: /Stage[main]/Users::Common/Notify[Adding users::common]/message: defined 'message' as 'Adding users::common' |
| 31 | +Notice: /Stage[main]/Ntp::Config/File[/tmp/ntp.conf]/ensure: defined content as '{sha256}949c7247dbe0870258c921418cc8b270afcc57e1aa6f9d9933f306009ede60d0' |
| 32 | +Notice: Applied catalog in 0.02 seconds |
30 | 33 | $ cat /tmp/ntp.conf
|
31 | 34 | server 1.pool.ntp.org
|
32 | 35 | server 2.pool.ntp.org
|
33 |
| -</pre> |
| 36 | +``` |
34 | 37 |
|
35 | 38 | Site wide override data in _data::common_
|
36 | 39 | -----------------------------------------
|
37 | 40 |
|
38 |
| - * Restore the _modules/data_ directory that has a class _data::common_ that declares site wide overrides |
39 |
| - * The _hiera_include()_ function includes just _users::common_ |
40 |
| - |
41 |
| -<pre> |
42 |
| -$ mv modules/data.bak modules/data |
43 |
| -$ puppet apply --config etc/puppet.conf site.pp |
44 |
| -notice: /Stage[main]/Ntp::Config/File[/tmp/ntp.conf]/content: content changed '{md5}7045121976147a932a66c7671939a9addc2' to '{md5}8f9039fe1989a278a0a8e1836acb8d23' |
45 |
| -notice: /Stage[main]/Users::Common/Notify[Adding users::common]/message: defined 'message' as 'Adding users::common' |
| 41 | +- Remove the comments on lines 6-8 of [data/common.yaml](data/common.yaml#L6-8) |
| 42 | +- Run a `puppet apply` to update */tmp/ntp.conf* to contain the two *ntp.example.com* addresses |
| 43 | +- The *users::common* class should also be present in your catalog |
| 44 | +
|
| 45 | +```shell |
| 46 | +$ sed -i '6,8 s/^#//' data/common.yaml |
| 47 | +$ puppet apply site.pp --hiera_config=hiera.yaml --modulepath=modules |
| 48 | +Notice: Compiled catalog for node.corp.com in environment production in 0.04 seconds |
| 49 | +Notice: Adding users::common |
| 50 | +Notice: /Stage[main]/Users::Common/Notify[Adding users::common]/message: defined 'message' as 'Adding users::common' |
| 51 | +Notice: /Stage[main]/Ntp::Config/File[/tmp/ntp.conf]/content: content changed '{sha256}949c7247dbe0870258c921418cc8b270afcc57e1aa6f9d9933f306009ede60d0' to '{sha256}28ced955a8ed9efd7514b2364fe378ba645ab947f26e8c0b4d84e8368f1257a0' |
| 52 | +Notice: Applied catalog in 0.02 seconds |
46 | 53 | $ cat /tmp/ntp.conf
|
47 | 54 | server ntp1.example.com
|
48 | 55 | server ntp2.example.com
|
49 |
| -</pre> |
| 56 | +``` |
50 | 57 |
|
51 | 58 | Fact driven overrides for location=dc1
|
52 | 59 | --------------------------------------
|
53 | 60 |
|
54 |
| - * Set a fact location=dc1 that uses the YAML data in _etc/hieradb/dc1.yaml_ to override |
55 |
| - * Show that machines in dc2 would use site-wide defaults |
56 |
| - * The _hiera_include()_ function includes _users::common_ and _users::dc1_ as the data file for dc1 adds that |
57 |
| - |
58 |
| -<pre> |
59 |
| -$ FACTER_location=dc1 puppet apply --config etc/puppet.conf site.pp |
60 |
| -notice: /Stage[main]/Ntp::Config/File[/tmp/ntp.conf]/content: content changed '{md5}8f9039fe1989a278a0a8e1836acb8d23' to '{md5}074d0e2ac727f6cb9afe3345d574b578' |
61 |
| -notice: /Stage[main]/Users::Common/Notify[Adding users::common]/message: defined 'message' as 'Adding users::common' |
62 |
| -notice: /Stage[main]/Users::Dc1/Notify[Adding users::dc1]/message: defined 'message' as 'Adding users::dc1' |
| 61 | +- Override the location fact to `dc1` to demonstrate *data/dc1.yaml* overrides the *ntp::config::ntpservers* values in *data/common.yaml* |
| 62 | +- `dc1` nodes will |
| 63 | + - have the *users::common* and *users::dc1* in their catalogs |
| 64 | + - */tmp/ntp.conf* will contain the two *ntp.dc1.example.com* addresses |
| 65 | +- Show that the nodes in `dc2` would use the site-wide defaults |
| 66 | +
|
| 67 | +```shell |
| 68 | +$ FACTER_location=dc1 puppet apply site.pp --hiera_config=hiera.yaml --modulepath=modules |
| 69 | +Notice: Compiled catalog for node.corp.com in environment production in 0.04 seconds |
| 70 | +Notice: Adding users::dc1 |
| 71 | +Notice: /Stage[main]/Users::Dc1/Notify[Adding users::dc1]/message: defined 'message' as 'Adding users::dc1' |
| 72 | +Notice: Adding users::common |
| 73 | +Notice: /Stage[main]/Users::Common/Notify[Adding users::common]/message: defined 'message' as 'Adding users::common' |
| 74 | +Notice: /Stage[main]/Ntp::Config/File[/tmp/ntp.conf]/content: content changed '{sha256}28ced955a8ed9efd7514b2364fe378ba645ab947f26e8c0b4d84e8368f1257a0' to '{sha256}39227f1cf8d09623d2e66b6622af2e8db01ab26f77a5a2e6d6e058d0977f369b' |
| 75 | +Notice: Applied catalog in 0.02 seconds |
63 | 76 | $ cat /tmp/ntp.conf
|
64 | 77 | server ntp1.dc1.example.com
|
65 | 78 | server ntp2.dc1.example.com
|
66 |
| -</pre> |
67 |
| - |
68 |
| -Now simulate a machine in _dc2_, because there is no data for dc2 it uses the site wide defaults and |
69 |
| -does not include the _users::dc1_ class anymore |
70 |
| - |
71 |
| -<pre> |
72 |
| -$ FACTER_location=dc2 puppet apply --config etc/puppet.conf site.pp |
73 |
| -warning: Could not find class data::dc2 for nephilim.ml.org |
74 |
| -notice: /Stage[main]/Ntp::Config/File[/tmp/ntp.conf]/content: content changed '{md5}074d0e2ac727f6cb9afe3345d574b578' to '{md5}8f9039fe1989a278a0a8e1836acb8d23' |
75 |
| -notice: /Stage[main]/Users::Common/Notify[Adding users::common]/message: defined 'message' as 'Adding users::common' |
| 79 | +``` |
| 80 | +
|
| 81 | +Now simulate a machine in `dc2`, because there is no data for `dc2` it uses the site wide defaults and |
| 82 | +does not include the *users::dc1* class anymore |
| 83 | +
|
| 84 | +```shell |
| 85 | +$ FACTER_location=dc2 puppet apply site.pp --hiera_config=hiera.yaml --modulepath=modules |
| 86 | +Notice: Compiled catalog for node.corp.com in environment production in 0.04 seconds |
| 87 | +Notice: Adding users::common |
| 88 | +Notice: /Stage[main]/Users::Common/Notify[Adding users::common]/message: defined 'message' as 'Adding users::common' |
| 89 | +Notice: /Stage[main]/Ntp::Config/File[/tmp/ntp.conf]/content: content changed '{sha256}39227f1cf8d09623d2e66b6622af2e8db01ab26f77a5a2e6d6e058d0977f369b' to '{sha256}28ced955a8ed9efd7514b2364fe378ba645ab947f26e8c0b4d84e8368f1257a0' |
| 90 | +Notice: Applied catalog in 0.02 seconds |
76 | 91 | $ cat /tmp/ntp.conf
|
77 | 92 | server ntp1.example.com
|
78 | 93 | server ntp2.example.com
|
79 |
| -</pre> |
| 94 | +``` |
80 | 95 |
|
81 |
| -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. |
| 96 | +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. |
82 | 97 |
|
83 |
| - * file etc/hieradb/dc2.yaml |
84 |
| - * file etc/hieradb/common.yaml |
85 |
| - * class data::dc2 |
86 |
| - * class data::production |
87 |
| - * class data::common |
88 |
| - * class ntp::config::data |
89 |
| - * class ntp::data |
| 98 | +- file data/dc2.yaml |
| 99 | +- file data/<environment>.yaml |
| 100 | +- file data/common.yaml |
90 | 101 |
|
91 |
| -In this example due to the presence of _common.yaml_ that declares _ntpservers_ the classes will never be searched, it will have precedence. |
| 102 | +In this example due to the presence of *common.yaml* that declares *ntpservers* the classes will never be searched, it will have precedence. |
0 commit comments