hiera 2.0.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +202 -0
- data/LICENSE +18 -0
- data/README.md +276 -0
- data/bin/hiera +248 -0
- data/lib/hiera.rb +115 -0
- data/lib/hiera/backend.rb +325 -0
- data/lib/hiera/backend/json_backend.rb +58 -0
- data/lib/hiera/backend/yaml_backend.rb +63 -0
- data/lib/hiera/config.rb +90 -0
- data/lib/hiera/console_logger.rb +13 -0
- data/lib/hiera/error.rb +4 -0
- data/lib/hiera/fallback_logger.rb +41 -0
- data/lib/hiera/filecache.rb +86 -0
- data/lib/hiera/interpolate.rb +98 -0
- data/lib/hiera/noop_logger.rb +8 -0
- data/lib/hiera/puppet_logger.rb +17 -0
- data/lib/hiera/recursive_guard.rb +20 -0
- data/lib/hiera/util.rb +47 -0
- data/lib/hiera/version.rb +89 -0
- data/spec/spec_helper.rb +78 -0
- data/spec/unit/backend/json_backend_spec.rb +85 -0
- data/spec/unit/backend/yaml_backend_spec.rb +138 -0
- data/spec/unit/backend_spec.rb +743 -0
- data/spec/unit/config_spec.rb +118 -0
- data/spec/unit/console_logger_spec.rb +19 -0
- data/spec/unit/fallback_logger_spec.rb +80 -0
- data/spec/unit/filecache_spec.rb +142 -0
- data/spec/unit/fixtures/interpolate/config/hiera.yaml +6 -0
- data/spec/unit/fixtures/interpolate/data/niltest.yaml +2 -0
- data/spec/unit/fixtures/interpolate/data/recursive.yaml +3 -0
- data/spec/unit/fixtures/override/config/hiera.yaml +5 -0
- data/spec/unit/fixtures/override/data/alternate.yaml +1 -0
- data/spec/unit/fixtures/override/data/common.yaml +2 -0
- data/spec/unit/hiera_spec.rb +81 -0
- data/spec/unit/interpolate_spec.rb +36 -0
- data/spec/unit/puppet_logger_spec.rb +31 -0
- data/spec/unit/util_spec.rb +49 -0
- data/spec/unit/version_spec.rb +44 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1009a888af453aa872d1ebb4f9bd74aae3b69625
|
4
|
+
data.tar.gz: fd038d50edc2f8c3dd6d21d21d30cc9463b11c4c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c65c6bdbdce2bf2173eaca6a81eab423bd27dd65c95ef82745b40117985f6337d4e271cba32807f5fa6d8d3afe34024b0d4fb48af81b88767a0410796e3993f
|
7
|
+
data.tar.gz: 10d478df00b859bddf583631ae9fe9f2f1028b3394fda6dfd38d3e0a2a57ce32a1b41a681b814552594421d9b9b373b94c6300eccdd2291827abacf8f9c3a566
|
data/COPYING
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright 2010, 2011 R.I.Pienaar, Puppet Labs
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Puppet - Automating Configuration Management.
|
2
|
+
|
3
|
+
Copyright (C) 2012-2014 Puppet Labs Inc
|
4
|
+
|
5
|
+
Puppet Labs can be contacted at: info@puppetlabs.com
|
6
|
+
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
you may not use this file except in compliance with the License.
|
9
|
+
You may obtain a copy of the License at
|
10
|
+
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
|
13
|
+
Unless required by applicable law or agreed to in writing, software
|
14
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
See the License for the specific language governing permissions and
|
17
|
+
limitations under the License.
|
18
|
+
|
data/README.md
ADDED
@@ -0,0 +1,276 @@
|
|
1
|
+
# Hiera
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/puppetlabs/hiera.png?branch=master)](https://travis-ci.org/puppetlabs/hiera)
|
4
|
+
|
5
|
+
A simple pluggable Hierarchical Database.
|
6
|
+
|
7
|
+
-
|
8
|
+
**Tutorials:** Check the docs directory for tutorials.
|
9
|
+
|
10
|
+
## Why?
|
11
|
+
|
12
|
+
Hierarchical data is a good fit for the representation of infrastructure information.
|
13
|
+
Consider the example of a typical company with 2 datacenters and on-site development,
|
14
|
+
staging etc.
|
15
|
+
|
16
|
+
All machines need:
|
17
|
+
|
18
|
+
- ntp servers
|
19
|
+
- sysadmin contacts
|
20
|
+
|
21
|
+
By thinking about the data in a hierarchical manner you can resolve these to the most
|
22
|
+
correct answer easily:
|
23
|
+
|
24
|
+
<pre>
|
25
|
+
/------------- DC1 -------------\ /------------- DC2 -------------\
|
26
|
+
| ntpserver: ntp1.dc1.example.com | | ntpserver: ntp1.dc2.example.com |
|
27
|
+
| sysadmin: dc1noc@example.com | | |
|
28
|
+
| classes: users::dc1 | | classes: users::dc2 |
|
29
|
+
\-------------------------------/ \-------------------------------/
|
30
|
+
\ /
|
31
|
+
\ /
|
32
|
+
/------------- COMMON -------------\
|
33
|
+
| ntpserver: 1.pool.ntp.org |
|
34
|
+
| sysadmin: "sysadmin@%{domain}" |
|
35
|
+
| classes: users::common |
|
36
|
+
\----------------------------------/
|
37
|
+
</pre>
|
38
|
+
|
39
|
+
In this simple example machines in DC1 and DC2 have their own NTP servers, additionaly
|
40
|
+
DC1 has its own sysadmin contact - perhaps because its a remote DR site - while DC2
|
41
|
+
and all the other environments would revert to the common contact that would have the
|
42
|
+
machines domain fact expanded into the result.
|
43
|
+
|
44
|
+
The _classes_ variable can be searched using the array method which would build up a
|
45
|
+
list of classes to include on a node based on the hierarchy. Machines in DC1 would have
|
46
|
+
the classes _users::common_ and _users::dc1_.
|
47
|
+
|
48
|
+
The other environment like development and staging would all use the public NTP infrastructure.
|
49
|
+
|
50
|
+
This is the data model that extlookup() have promoted in Puppet, Hiera has taken this
|
51
|
+
data model and extracted it into a standalone project that is pluggable and have a few
|
52
|
+
refinements over extlookup.
|
53
|
+
|
54
|
+
## Enhancements over Extlookup
|
55
|
+
|
56
|
+
Extlookup had just one backend, Hiera can be extended with your own backends and represent
|
57
|
+
a few enhancements over the base Extlookup approach thanks to this.
|
58
|
+
|
59
|
+
### Multiple backends are queried
|
60
|
+
|
61
|
+
If you have a YAML and Puppet backend loaded and your users provide module defaults in the
|
62
|
+
Puppet backend you can use your YAML data to override the Puppet data. If the YAML doesnt
|
63
|
+
provide an answer the Puppet backend will get an opportunity to provide an answer.
|
64
|
+
|
65
|
+
### More scope based variable expansion
|
66
|
+
|
67
|
+
Extlookup could parse data like %{foo} into a scope lookup for the variable foo. Hiera
|
68
|
+
retains this ability and any Arrays or Hashes will be recursively searched for all strings
|
69
|
+
that will then be parsed.
|
70
|
+
|
71
|
+
The datadir and defaults are now also subject to variable parsing based on scope.
|
72
|
+
|
73
|
+
### No CSV support by default
|
74
|
+
|
75
|
+
We have not at present provided a backward compatible CSV backend. A converter to
|
76
|
+
YAML or JSON should be written. When the CSV backend was first chosen for Puppet the
|
77
|
+
Puppet language only supports strings and arrays of strings which mapped well to CSV.
|
78
|
+
Puppet has become (a bit) better wrt data and can now handle hashes and arrays of hashes
|
79
|
+
so it's a good time to retire the old data format.
|
80
|
+
|
81
|
+
### Array Searches
|
82
|
+
|
83
|
+
Hiera can search through all the tiers in a hierarchy and merge the result into a single
|
84
|
+
array. This is used in the hiera-puppet project to replace External Node Classifiers by
|
85
|
+
creating a Hiera compatible include function.
|
86
|
+
|
87
|
+
### Qualified Key Lookup
|
88
|
+
You can use a qualified key to lookup a value that is contained inside a hash or array:
|
89
|
+
|
90
|
+
<pre>
|
91
|
+
$ hiera user
|
92
|
+
{"name"=>"kim", "home"=>"/home/kim"}
|
93
|
+
$ hiera user.name
|
94
|
+
kim
|
95
|
+
</pre>
|
96
|
+
|
97
|
+
<pre>
|
98
|
+
$ hiera ssh_users
|
99
|
+
["root", "jeff", "gary", "hunter"]
|
100
|
+
$ hiera ssh_users.0
|
101
|
+
root
|
102
|
+
</pre>
|
103
|
+
|
104
|
+
## Future Enhancements
|
105
|
+
|
106
|
+
* More backends should be created
|
107
|
+
* A webservice that exposes the data
|
108
|
+
* Tools to help maintain the data files. Ideally this would be Foreman and Dashboard
|
109
|
+
with their own backends
|
110
|
+
|
111
|
+
## Installation
|
112
|
+
|
113
|
+
Hiera is available as a Gem called _hiera_ and out of the box it comes with just a single
|
114
|
+
YAML backend.
|
115
|
+
|
116
|
+
Hiera is also available as a native package via apt (http://apt.puppetlabs.com) and yum (http://yum.puppetlabs.com). Instructions for adding these repositories can be found at http://docs.puppetlabs.com/guides/installation.html#debian-and-ubuntu and http://docs.puppetlabs.com/guides/installation.html#enterprise-linux respectively.
|
117
|
+
|
118
|
+
At present JSON (github/ripienaar/hiera-json) and Puppet (hiera-puppet) backends are availble.
|
119
|
+
|
120
|
+
## Configuration
|
121
|
+
|
122
|
+
You can configure Hiera using a YAML file or by providing it Hash data in your code. There
|
123
|
+
isn't a default config path - the CLI script will probably assume _/etc/hiera.yaml_ though.
|
124
|
+
The default data directory for file based storage is _/var/lib/hiera_.
|
125
|
+
|
126
|
+
A sample configuration file can be seen here:
|
127
|
+
|
128
|
+
<pre>
|
129
|
+
---
|
130
|
+
:backends:
|
131
|
+
- yaml
|
132
|
+
- puppet
|
133
|
+
|
134
|
+
:logger: console
|
135
|
+
|
136
|
+
:hierarchy:
|
137
|
+
- "sites/%{location}"
|
138
|
+
- common
|
139
|
+
|
140
|
+
:yaml:
|
141
|
+
:datadir: /etc/puppetlabs/code/hieradata
|
142
|
+
|
143
|
+
:puppet:
|
144
|
+
:datasource: data
|
145
|
+
</pre>
|
146
|
+
|
147
|
+
This configuration will require YAML files in _/etc/puppetlabs/code/hieradata_ these need to contain
|
148
|
+
Hash data, sample files matching the hierarchy described in the _Why?_ section are below:
|
149
|
+
|
150
|
+
_/etc/puppetlabs/code/hieradata/sites/dc1.yaml_:
|
151
|
+
<pre>
|
152
|
+
---
|
153
|
+
ntpserver: ntp1.dc1.example.com
|
154
|
+
sysadmin: dc1noc@example.com
|
155
|
+
</pre>
|
156
|
+
|
157
|
+
_/etc/puppetlabs/code/hieradata/sites/dc2.yaml_:
|
158
|
+
<pre>
|
159
|
+
---
|
160
|
+
ntpserver: ntp1.dc2.example.com
|
161
|
+
</pre>
|
162
|
+
|
163
|
+
_/etc/puppetlabs/code/hieradata/common.yaml_:
|
164
|
+
<pre>
|
165
|
+
---
|
166
|
+
sysadmin: "sysadmin@%{domain}"
|
167
|
+
ntpserver: 1.pool.ntp.org
|
168
|
+
</pre>
|
169
|
+
|
170
|
+
## Querying from CLI
|
171
|
+
|
172
|
+
You can query your data from the CLI. By default the CLI expects a config file in _/etc/hiera.yaml_
|
173
|
+
but you can pass _--config_ to override that.
|
174
|
+
|
175
|
+
This example searches Hiera for node data. Scope is loaded from a Puppet created YAML facts
|
176
|
+
store as found on your Puppet Masters.
|
177
|
+
|
178
|
+
If no data is found and the facts had a location=dc1 fact the default would be _sites/dc1_
|
179
|
+
|
180
|
+
<pre>
|
181
|
+
$ hiera acme_version 'sites/%{location}' --yaml /opt/puppetlabs/puppet/cache/yaml/facts/example.com.yaml
|
182
|
+
</pre>
|
183
|
+
|
184
|
+
You can also supply extra facts on the CLI, assuming Puppet facts did not have a location fact:
|
185
|
+
|
186
|
+
<pre>
|
187
|
+
$ hiera acme_version 'sites/%{location}' location=dc1 --yaml /opt/puppetlabs/puppet/cache/yaml/facts/example.com.yaml
|
188
|
+
</pre>
|
189
|
+
|
190
|
+
Or if you use MCollective you can fetch the scope from a remote node's facts:
|
191
|
+
|
192
|
+
<pre>
|
193
|
+
$ hiera acme_version 'sites/%{location}' -m box.example.com
|
194
|
+
</pre>
|
195
|
+
|
196
|
+
You can also do array merge searches on the CLI:
|
197
|
+
|
198
|
+
<pre>
|
199
|
+
$ hiera -a classes location=dc1
|
200
|
+
["users::common", "users::dc1"]
|
201
|
+
</pre>
|
202
|
+
|
203
|
+
## Querying from code
|
204
|
+
|
205
|
+
This is the same query programatically as in the above CLI example:
|
206
|
+
|
207
|
+
<pre>
|
208
|
+
require 'rubygems'
|
209
|
+
require 'hiera'
|
210
|
+
require 'puppet'
|
211
|
+
|
212
|
+
# load the facts for example.com
|
213
|
+
scope = YAML.load_file("/opt/puppetlabs/puppet/cache/yaml/facts/example.com.yaml").values
|
214
|
+
|
215
|
+
# create a new instance based on config file
|
216
|
+
hiera = Hiera.new(:config => "/etc/puppetlabs/code/hiera.yaml")
|
217
|
+
|
218
|
+
# resolve the 'acme_version' variable based on scope
|
219
|
+
#
|
220
|
+
# given a fact location=dc1 in the facts file this will default to a branch sites/dc1
|
221
|
+
# and allow hierarchical overrides based on the hierarchy defined in the config file
|
222
|
+
puts "ACME Software Version: %s" % [ hiera.lookup("acme_version", "sites/%{location}", scope) ]
|
223
|
+
</pre>
|
224
|
+
|
225
|
+
## Extending
|
226
|
+
|
227
|
+
There exist 2 backends at present in addition to the bundled YAML one.
|
228
|
+
|
229
|
+
### JSON
|
230
|
+
|
231
|
+
This can be found on github under _ripienaar/hiera-json_. This is a good example
|
232
|
+
of file based backends as Hiera provides a number of helpers to make writing these
|
233
|
+
trivial.
|
234
|
+
|
235
|
+
### Puppet
|
236
|
+
|
237
|
+
This is much more complex and queries the data from the running Puppet state, it's found
|
238
|
+
on GitHub under _ripienaar/hiera-puppet_.
|
239
|
+
|
240
|
+
This is a good example to learn how to map your internal program state into what Hiera
|
241
|
+
wants as I needed to do with the Puppet Scope.
|
242
|
+
|
243
|
+
It includes a Puppet Parser Function to query the data from within Puppet.
|
244
|
+
|
245
|
+
When used in Puppet you'd expect Hiera to log using the Puppet infrastructure, this
|
246
|
+
plugin includes a Puppet Logger plugin for Hiera that uses the normal Puppet logging
|
247
|
+
methods for all logging.
|
248
|
+
|
249
|
+
## License
|
250
|
+
|
251
|
+
See LICENSE file.
|
252
|
+
|
253
|
+
## Support
|
254
|
+
|
255
|
+
Please log tickets and issues at our [JIRA tracker](http://tickets.puppetlabs.com). A [mailing
|
256
|
+
list](https://groups.google.com/forum/?fromgroups#!forum/puppet-users) is
|
257
|
+
available for asking questions and getting help from others. In addition there
|
258
|
+
is an active #puppet channel on Freenode.
|
259
|
+
|
260
|
+
We use semantic version numbers for our releases, and recommend that users stay
|
261
|
+
as up-to-date as possible by upgrading to patch releases and minor releases as
|
262
|
+
they become available.
|
263
|
+
|
264
|
+
Bugfixes and ongoing development will occur in minor releases for the current
|
265
|
+
major version. Security fixes will be backported to a previous major version on
|
266
|
+
a best-effort basis, until the previous major version is no longer maintained.
|
267
|
+
|
268
|
+
|
269
|
+
For example: If a security vulnerability is discovered in Hiera 1.3.0, we
|
270
|
+
would fix it in the 1 series, most likely as 1.3.1. Maintainers would then make
|
271
|
+
a best effort to backport that fix onto the latest Hiera release they carry.
|
272
|
+
|
273
|
+
Long-term support, including security patches and bug fixes, is available for
|
274
|
+
commercial customers. Please see the following page for more details:
|
275
|
+
|
276
|
+
[Puppet Enterprise Support Lifecycle](http://puppetlabs.com/misc/puppet-enterprise-lifecycle)
|