hiera_explain 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +89 -14
- data/bin/hiera_explain +62 -11
- data/lib/hiera_explain.rb +12 -5
- data/lib/hiera_explain/datasource/{marshall.rb → marshal.rb} +0 -0
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 62b43e9bbbd325c266ea3353f8117437d9e28aa9
|
|
4
|
+
data.tar.gz: f1265853cac0fe2d6c164edf2d8a2f3572937eb0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea1959e7315819eaefd3f77aef057a9da2b1d3e423cebf859a93c7e37e152fc2849f535d49c050d1b805b34bad499945ce203dcddfb4d79ce65d4c7ada8add06
|
|
7
|
+
data.tar.gz: 5c75677b4298ae512b46008c9b2c81ce3e28e92806ce28378fd550501118d6ad4f9a1cb19060ea77bcc26b6ac41b3cbb34c2585e79be142c379c32a25065ff66
|
data/README.md
CHANGED
|
@@ -9,6 +9,17 @@ it will use whatever scope you provide to evaluate the `hiera.yaml` file and
|
|
|
9
9
|
print it out exactly as Hiera will interpret it. What is scope? That's merely
|
|
10
10
|
the collection of facts or other variables provided for Hiera to use.
|
|
11
11
|
|
|
12
|
+
* [Usage](#usage)
|
|
13
|
+
* [Options](#options)
|
|
14
|
+
* [Overriding facts](#overriding-facts)
|
|
15
|
+
* [Filtering output](#filtering-output)
|
|
16
|
+
* [Displaying sources for results](#displaying-sources-for-results)
|
|
17
|
+
* [Adding supported backends](#adding-supported-backends)
|
|
18
|
+
* [Disclaimer](#disclaimer)
|
|
19
|
+
* [Contact](#contact)
|
|
20
|
+
|
|
21
|
+

|
|
22
|
+
|
|
12
23
|
## Usage
|
|
13
24
|
|
|
14
25
|
The examples here will use this sample `hiera.yaml` configuration file:
|
|
@@ -107,16 +118,14 @@ Array lookup results:
|
|
|
107
118
|
* hiera_array('hashies') => [{"key"=>"value"}]
|
|
108
119
|
|
|
109
120
|
Hash lookup results:
|
|
110
|
-
* hiera_hash('pe_repo::base_path') =>
|
|
111
|
-
* hiera_hash('puppet_enterprise::profile::console::rbac_session_timeout') =>
|
|
112
|
-
* hiera_hash('puppet_enterprise::profile::puppetdb::listen_address') =>
|
|
113
|
-
* hiera_hash('message') =>
|
|
114
|
-
* hiera_hash('foo') =>
|
|
121
|
+
* hiera_hash('pe_repo::base_path') => Not a hash datatype in ["master.puppetlabs.vm.yaml", "classroom.yaml"]
|
|
122
|
+
* hiera_hash('puppet_enterprise::profile::console::rbac_session_timeout') => Not a hash datatype in ["classroom.yaml"]
|
|
123
|
+
* hiera_hash('puppet_enterprise::profile::puppetdb::listen_address') => Not a hash datatype in ["classroom.yaml"]
|
|
124
|
+
* hiera_hash('message') => Not a hash datatype in ["defaults.yaml", "overrides.json"]
|
|
125
|
+
* hiera_hash('foo') => Not a hash datatype in ["overrides.json"]
|
|
115
126
|
* hiera_hash('hashies') => {"key"=>"value"}
|
|
116
127
|
```
|
|
117
128
|
|
|
118
|
-

|
|
119
|
-
|
|
120
129
|
### Options
|
|
121
130
|
|
|
122
131
|
`hiera_explain` can use scope from a variety of sources. You can pass a JSON or
|
|
@@ -128,6 +137,9 @@ root@master:~ # hiera_explain -h
|
|
|
128
137
|
|
|
129
138
|
Usage : hiera_explain [--json PATH] [--yaml PATH] [--mcollective IDENTITY] [--puppetdb IDENTITY].
|
|
130
139
|
|
|
140
|
+
-c, --config CONFIG Load Hiera settings from an alternate hiera.yaml.
|
|
141
|
+
-f, --filter FILTER Only keys matching this string or regex will be displayed.
|
|
142
|
+
-v, --verbose Show verbose datasource details.
|
|
131
143
|
-j, --json PATH Load scope from a JSON file.
|
|
132
144
|
-y, --yaml PATH Load scope from a YAML file.
|
|
133
145
|
-m, --mcollective IDENTITY Use MCollective to retrieve scope for an identity.
|
|
@@ -139,6 +151,8 @@ Usage : hiera_explain [--json PATH] [--yaml PATH] [--mcollective IDENTITY] [--pu
|
|
|
139
151
|
-h, --help Displays this help
|
|
140
152
|
```
|
|
141
153
|
|
|
154
|
+
#### Overriding facts
|
|
155
|
+
|
|
142
156
|
You can even override facts one at a time on the command line.
|
|
143
157
|
|
|
144
158
|
```
|
|
@@ -159,6 +173,66 @@ Expanded hierarchy:
|
|
|
159
173
|
* defaults
|
|
160
174
|
```
|
|
161
175
|
|
|
176
|
+
#### Filtering output
|
|
177
|
+
|
|
178
|
+
If you have many keys set and the output is too long, you can pass in a filter
|
|
179
|
+
using either a full string or a regular expression. For example:
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
root@master:~ # hiera_explain -f message
|
|
183
|
+
[...]
|
|
184
|
+
Priority lookup results:
|
|
185
|
+
* hiera('message') => This message is customized for the master.
|
|
186
|
+
|
|
187
|
+
Array lookup results:
|
|
188
|
+
* hiera_array('message') => ["This message is customized for the master.", "This is a sample variable that came from a Hiera datasource"]
|
|
189
|
+
|
|
190
|
+
Hash lookup results:
|
|
191
|
+
* hiera_hash('message') => Not a hash datatype in ["master.puppetlabs.vm.yaml", "defaults.yaml"]
|
|
192
|
+
|
|
193
|
+
root@master:~ # hiera_explain -f /^puppet_enterprise/
|
|
194
|
+
[...]
|
|
195
|
+
Priority lookup results:
|
|
196
|
+
* hiera('puppet_enterprise::profile::console::rbac_session_timeout') => 4320
|
|
197
|
+
* hiera('puppet_enterprise::profile::puppetdb::listen_address') => 0.0.0.0
|
|
198
|
+
|
|
199
|
+
Array lookup results:
|
|
200
|
+
* hiera_array('puppet_enterprise::profile::console::rbac_session_timeout') => [4320]
|
|
201
|
+
* hiera_array('puppet_enterprise::profile::puppetdb::listen_address') => ["0.0.0.0"]
|
|
202
|
+
|
|
203
|
+
Hash lookup results:
|
|
204
|
+
* hiera_hash('puppet_enterprise::profile::console::rbac_session_timeout') => Not a hash datatype in ["classroom.yaml"]
|
|
205
|
+
* hiera_hash('puppet_enterprise::profile::puppetdb::listen_address') => Not a hash datatype in ["classroom.yaml"]
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### Displaying sources for results
|
|
209
|
+
|
|
210
|
+
To see which datasource(s) resolved any given variable returned, you can pass the
|
|
211
|
+
`--verbose` flag. This might generate a very long printout, so you might want to
|
|
212
|
+
couple it with the `--filter` flag as well.
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
root@master:~ # hiera_explain -v -f /message/
|
|
216
|
+
[...]
|
|
217
|
+
Priority lookup results:
|
|
218
|
+
* hiera('message') => This message is customized for the master.
|
|
219
|
+
- /etc/puppetlabs/code/hieradata/master.puppetlabs.vm.yaml
|
|
220
|
+
* hiera('hashmessage') => {"key"=>"A message embedded in a hash"}
|
|
221
|
+
- /etc/puppetlabs/code/hieradata/defaults.yaml
|
|
222
|
+
|
|
223
|
+
Array lookup results:
|
|
224
|
+
* hiera_array('message') => ["This message is customized for the master.", "This is a sample variable t4hat came from a Hiera datasource"]
|
|
225
|
+
- /etc/puppetlabs/code/hieradata/master.puppetlabs.vm.yaml
|
|
226
|
+
- /etc/puppetlabs/code/hieradata/defaults.yaml
|
|
227
|
+
* hiera_array('hashmessage') => [{"key"=>"A message embedded in a hash"}]
|
|
228
|
+
- /etc/puppetlabs/code/hieradata/defaults.yaml
|
|
229
|
+
|
|
230
|
+
Hash lookup results:
|
|
231
|
+
* hiera_hash('message') => Not a hash datatype in ["master.puppetlabs.vm.yaml", "defaults.yaml"]
|
|
232
|
+
* hiera_hash('hashmessage') => {"key"=>"A message embedded in a hash"}
|
|
233
|
+
- /etc/puppetlabs/code/hieradata/defaults.yaml
|
|
234
|
+
```
|
|
235
|
+
|
|
162
236
|
### Adding supported backends.
|
|
163
237
|
|
|
164
238
|
A standard Hiera backend won't provide the data we need to look up all available
|
|
@@ -171,10 +245,10 @@ hash of Hiera data, given a path.
|
|
|
171
245
|
```ruby
|
|
172
246
|
class HieraExplain::Datasource
|
|
173
247
|
|
|
174
|
-
#
|
|
248
|
+
# marshal is a data serialization format for Ruby. There does not exist
|
|
175
249
|
# a Hiera backend for using it, nor should there be as it's a binary format.
|
|
176
250
|
# But if there were, this would make hiera_explain understand it.
|
|
177
|
-
def self.
|
|
251
|
+
def self.marshal(path)
|
|
178
252
|
Marshal::load(File.read(path))
|
|
179
253
|
end
|
|
180
254
|
|
|
@@ -185,21 +259,22 @@ The filename and the method it provides *must* be the same as the name for your
|
|
|
185
259
|
backend.
|
|
186
260
|
|
|
187
261
|
```
|
|
188
|
-
root@master:modules # $ tree
|
|
189
|
-
|
|
262
|
+
root@master:modules # $ tree marshal
|
|
263
|
+
marshal
|
|
190
264
|
└── lib
|
|
191
265
|
├── hiera
|
|
192
266
|
│ └── backends
|
|
193
|
-
│ └──
|
|
267
|
+
│ └── marshal_backend.rb
|
|
194
268
|
└── hiera_explain
|
|
195
269
|
└── datasource
|
|
196
|
-
└──
|
|
270
|
+
└── marshal.rb
|
|
197
271
|
```
|
|
198
272
|
|
|
199
273
|
## Disclaimer
|
|
200
274
|
|
|
201
275
|
This is early in development, although the script this is based on has been used
|
|
202
|
-
in the classroom for quite a while now.
|
|
276
|
+
in the classroom for quite a while now. This currently only supports Hiera
|
|
277
|
+
version 1.x.
|
|
203
278
|
|
|
204
279
|
Contact
|
|
205
280
|
-------
|
data/bin/hiera_explain
CHANGED
|
@@ -14,13 +14,32 @@ rescue => e
|
|
|
14
14
|
Puppet.settings.parse
|
|
15
15
|
end
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
scope
|
|
17
|
+
config = Puppet.settings[:hiera_config]
|
|
18
|
+
scope = HieraExplain::Scope.new()
|
|
19
|
+
filter = nil
|
|
20
|
+
verbose = false
|
|
21
|
+
|
|
19
22
|
optparse = OptionParser.new { |opts|
|
|
20
23
|
opts.banner = "Usage : hiera_explain [--json PATH] [--yaml PATH] [--mcollective IDENTITY] [--puppetdb IDENTITY].
|
|
21
24
|
|
|
22
25
|
"
|
|
23
26
|
|
|
27
|
+
opts.on("-c CONFIG", "--config CONFIG", "Load Hiera settings from an alternate hiera.yaml.") do |arg|
|
|
28
|
+
config = File.expand_path(arg)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
opts.on("-f FILTER", "--filter FILTER", "Only keys matching this string or regex will be displayed.") do |arg|
|
|
32
|
+
if arg[0] == '/' and arg[-1] == '/'
|
|
33
|
+
filter = Regexp.new(arg[1...-1])
|
|
34
|
+
else
|
|
35
|
+
filter = arg
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
opts.on("-v", "--verbose", "Show verbose datasource details.") do
|
|
40
|
+
verbose = true
|
|
41
|
+
end
|
|
42
|
+
|
|
24
43
|
opts.on("-j PATH", "--json PATH", "Load scope from a JSON file.") do |arg|
|
|
25
44
|
scope.load_scope(arg, :json)
|
|
26
45
|
end
|
|
@@ -64,15 +83,20 @@ optparse = OptionParser.new { |opts|
|
|
|
64
83
|
}
|
|
65
84
|
optparse.parse!
|
|
66
85
|
|
|
67
|
-
# Default to the
|
|
86
|
+
# Default to the current node's MCO's fact cache
|
|
68
87
|
scope.load_scope("/etc/puppetlabs/mcollective/facts.yaml", :yaml) if scope.empty?
|
|
69
88
|
scope['environment'] ||= 'production'
|
|
70
89
|
|
|
71
90
|
# data buckets
|
|
72
|
-
priority_lookup
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
priority_lookup = {}
|
|
92
|
+
priority_sources = {}
|
|
93
|
+
|
|
94
|
+
array_lookup = {}
|
|
95
|
+
array_sources = {}
|
|
96
|
+
|
|
97
|
+
hash_lookup = {}
|
|
98
|
+
hash_sources = {}
|
|
99
|
+
hash_errors = {}
|
|
76
100
|
|
|
77
101
|
# Cribbed from Hiera source to ensure we're parsing the same way.
|
|
78
102
|
unless ARGV.empty?
|
|
@@ -85,8 +109,17 @@ unless ARGV.empty?
|
|
|
85
109
|
end
|
|
86
110
|
end
|
|
87
111
|
|
|
112
|
+
# now that we've got scope, start evaluating it.
|
|
113
|
+
hiera = Hiera.new(:config => config)
|
|
114
|
+
|
|
88
115
|
puts 'Backend data directories:'
|
|
89
116
|
Hiera::Config[:backends].each do |backend|
|
|
117
|
+
# make sure we've got any third-party datasources loaded up
|
|
118
|
+
begin
|
|
119
|
+
require "hiera_explain/datasource/#{backend}"
|
|
120
|
+
rescue LoadError => e
|
|
121
|
+
end
|
|
122
|
+
|
|
90
123
|
puts " * #{backend}: #{Hiera::Backend.datadir(backend, scope)}"
|
|
91
124
|
end
|
|
92
125
|
puts
|
|
@@ -115,12 +148,19 @@ Hiera::Config[:backends].each do |backend|
|
|
|
115
148
|
priority_lookup = data.merge(priority_lookup)
|
|
116
149
|
|
|
117
150
|
data.each do |key, value|
|
|
151
|
+
priority_sources[key] ||= path
|
|
152
|
+
array_sources[key] ||= Array.new
|
|
153
|
+
hash_sources[key] ||= Array.new
|
|
154
|
+
|
|
155
|
+
|
|
118
156
|
array_lookup[key] ||= Array.new
|
|
119
|
-
array_lookup[key]
|
|
157
|
+
array_lookup[key] << value
|
|
158
|
+
array_sources[key] << path
|
|
120
159
|
|
|
121
160
|
hash_lookup[key] ||= Hash.new
|
|
122
161
|
if (value.class == Hash)
|
|
123
162
|
hash_lookup[key].merge!(value)
|
|
163
|
+
hash_sources[key] << path
|
|
124
164
|
else
|
|
125
165
|
hash_errors[key] ||= Array.new
|
|
126
166
|
hash_errors[key] << "#{source}.#{backend}"
|
|
@@ -134,20 +174,31 @@ end
|
|
|
134
174
|
puts
|
|
135
175
|
|
|
136
176
|
puts 'Priority lookup results:'
|
|
137
|
-
priority_lookup.each
|
|
177
|
+
priority_lookup.each do |key, value|
|
|
178
|
+
next unless HieraExplain.match(key, filter)
|
|
179
|
+
puts " * hiera('#{key}') => #{value.to_s.green}"
|
|
180
|
+
puts " - #{priority_sources[key].cyan}" if verbose
|
|
181
|
+
end
|
|
138
182
|
puts
|
|
139
183
|
|
|
140
184
|
puts 'Array lookup results:'
|
|
141
|
-
array_lookup.each
|
|
185
|
+
array_lookup.each do |key, value|
|
|
186
|
+
next unless HieraExplain.match(key, filter)
|
|
187
|
+
puts " * hiera_array('#{key}') => #{value.inspect.green}"
|
|
188
|
+
array_sources[key].each { |source| puts " - #{source.cyan}"} if verbose
|
|
189
|
+
end
|
|
142
190
|
puts
|
|
143
191
|
|
|
144
192
|
puts 'Hash lookup results:'
|
|
145
193
|
hash_lookup.each do |key, value|
|
|
194
|
+
next unless HieraExplain.match(key, filter)
|
|
195
|
+
|
|
146
196
|
print " * hiera_hash('#{key}') => "
|
|
147
197
|
if(hash_errors.has_key? key)
|
|
148
|
-
puts "
|
|
198
|
+
puts "Not a hash datatype in #{hash_errors[key].inspect}".red
|
|
149
199
|
else
|
|
150
200
|
puts value.inspect.green
|
|
151
201
|
end
|
|
202
|
+
hash_sources[key].each { |source| puts " - #{source.cyan}"} if verbose
|
|
152
203
|
end
|
|
153
204
|
puts
|
data/lib/hiera_explain.rb
CHANGED
|
@@ -3,11 +3,6 @@ class HieraExplain
|
|
|
3
3
|
def self.load_datasource(backend, path)
|
|
4
4
|
return {} unless File.exists? path
|
|
5
5
|
|
|
6
|
-
begin
|
|
7
|
-
require "hiera_explain/datasource/#{backend}"
|
|
8
|
-
rescue LoadError => e
|
|
9
|
-
end
|
|
10
|
-
|
|
11
6
|
begin
|
|
12
7
|
return HieraExplain::Datasource.send(backend.to_s, path)
|
|
13
8
|
rescue => e
|
|
@@ -17,4 +12,16 @@ class HieraExplain
|
|
|
17
12
|
|
|
18
13
|
data
|
|
19
14
|
end
|
|
15
|
+
|
|
16
|
+
def self.match(key, filter)
|
|
17
|
+
return true if filter.nil?
|
|
18
|
+
|
|
19
|
+
case filter
|
|
20
|
+
when String
|
|
21
|
+
key == filter
|
|
22
|
+
when Regexp
|
|
23
|
+
key =~ filter
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
20
27
|
end
|
|
File without changes
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hiera_explain
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ben Ford
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-04-
|
|
11
|
+
date: 2016-04-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: puppet
|
|
@@ -68,7 +68,7 @@ files:
|
|
|
68
68
|
- README.md
|
|
69
69
|
- LICENSE
|
|
70
70
|
- bin/hiera_explain
|
|
71
|
-
- lib/hiera_explain/datasource/
|
|
71
|
+
- lib/hiera_explain/datasource/marshal.rb
|
|
72
72
|
- lib/hiera_explain/datasource.rb
|
|
73
73
|
- lib/hiera_explain/scope.rb
|
|
74
74
|
- lib/hiera_explain.rb
|