hiera-examiner 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/hiera-examiner +203 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee63dcfc46795a65576d331158f699c7ef4fb75d
|
4
|
+
data.tar.gz: d5f0d43c214878f9decf5e37c8e66f3faf61c982
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c643b76cd29ed29f01548331400748c7bc1fd7cd5ed454c3d5cb2f9670aae63eee354b2e45c2e1fb0c01048fce82ec5f635eeb9c08aa51862f1418e18f5af1a
|
7
|
+
data.tar.gz: 78d79db87842162d9f5bb86e30eddeda279c3f3db04032ee2902aad202b59c4b1d5df0f5ed3b486a53e2fda1580d45f80e4c80c86cdac8037affc426bd526d33
|
data/bin/hiera-examiner
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.delete '.'
|
4
|
+
|
5
|
+
# CLI client for Hiera Examiner.
|
6
|
+
require 'hiera-examiner'
|
7
|
+
require 'hiera/util'
|
8
|
+
require 'optparse'
|
9
|
+
require 'pp'
|
10
|
+
|
11
|
+
options = {
|
12
|
+
:default => nil,
|
13
|
+
:config => '/vagrant/puppet/hiera/hiera.yaml',
|
14
|
+
:scope => {},
|
15
|
+
:key => nil,
|
16
|
+
:verbose => false,
|
17
|
+
:resolution_type => :priority
|
18
|
+
}
|
19
|
+
|
20
|
+
# Loads the scope from YAML or JSON files
|
21
|
+
def load_scope(source, type=:yaml)
|
22
|
+
case type
|
23
|
+
when :mcollective
|
24
|
+
begin
|
25
|
+
require 'mcollective'
|
26
|
+
|
27
|
+
include MCollective::RPC
|
28
|
+
|
29
|
+
util = rpcclient("rpcutil")
|
30
|
+
util.progress = false
|
31
|
+
nodestats = util.custom_request("inventory", {}, source, {"identity" => source}).first
|
32
|
+
|
33
|
+
raise "Failed to retrieve facts for node #{source}: #{nodestats[:statusmsg]}" unless nodestats[:statuscode] == 0
|
34
|
+
|
35
|
+
scope = nodestats[:data][:facts]
|
36
|
+
rescue Exception => e
|
37
|
+
STDERR.puts "MCollective lookup failed: #{e.class}: #{e}"
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
|
41
|
+
when :yaml
|
42
|
+
raise "Cannot find scope #{type} file #{source}" unless File.exist?(source)
|
43
|
+
|
44
|
+
require 'yaml'
|
45
|
+
|
46
|
+
# Attempt to load puppet in case we're going to be fed
|
47
|
+
# Puppet yaml files
|
48
|
+
begin
|
49
|
+
require 'puppet'
|
50
|
+
rescue
|
51
|
+
end
|
52
|
+
|
53
|
+
scope = YAML.load_file(source)
|
54
|
+
|
55
|
+
# Puppet makes dumb yaml files that do not promote data reuse.
|
56
|
+
scope = scope.values if scope.is_a?(Puppet::Node::Facts)
|
57
|
+
|
58
|
+
when :json
|
59
|
+
raise "Cannot find scope #{type} file #{source}" unless File.exist?(source)
|
60
|
+
|
61
|
+
require 'json'
|
62
|
+
|
63
|
+
scope = JSON.load(File.read(source))
|
64
|
+
|
65
|
+
when :inventory_service
|
66
|
+
# For this to work the machine running the hiera command needs access to
|
67
|
+
# /facts REST endpoint on your inventory server. This access is
|
68
|
+
# controlled in auth.conf and identification is by the certname of the
|
69
|
+
# machine running hiera commands.
|
70
|
+
#
|
71
|
+
# Another caveat is that if your inventory server isn't at the short dns
|
72
|
+
# name of 'puppet' you will need to set the inventory_sever option in
|
73
|
+
# your puppet.conf. Set it in either the master or main sections. It
|
74
|
+
# is fine to have the inventory_server option set even if the config
|
75
|
+
# doesn't have the fact_terminus set to rest.
|
76
|
+
begin
|
77
|
+
require 'puppet/util/run_mode'
|
78
|
+
$puppet_application_mode = Puppet::Util::RunMode[:master]
|
79
|
+
require 'puppet'
|
80
|
+
Puppet.settings.parse
|
81
|
+
Puppet::Node::Facts.indirection.terminus_class = :rest
|
82
|
+
scope = YAML.load(Puppet::Node::Facts.indirection.find(source).to_yaml)
|
83
|
+
# Puppet makes dumb yaml files that do not promote data reuse.
|
84
|
+
scope = scope.values if scope.is_a?(Puppet::Node::Facts)
|
85
|
+
rescue Exception => e
|
86
|
+
STDERR.puts "Puppet inventory service lookup failed: #{e.class}: #{e}"
|
87
|
+
exit 1
|
88
|
+
end
|
89
|
+
else
|
90
|
+
raise "Don't know how to load data type #{type}"
|
91
|
+
end
|
92
|
+
|
93
|
+
raise "Scope from #{type} file #{source} should be a Hash" unless scope.is_a?(Hash)
|
94
|
+
|
95
|
+
scope
|
96
|
+
end
|
97
|
+
|
98
|
+
OptionParser.new do |opts|
|
99
|
+
opts.banner = "Usage: hiera [options] key [default value] [variable='text'...]\n\nThe default value will be used if no value is found for the key. Scope variables\nwill be interpolated into %{variable} placeholders in the hierarchy and in\nreturned values.\n\n"
|
100
|
+
|
101
|
+
#opts.on("--version", "-V", "Version information") do
|
102
|
+
# puts Hiera.version
|
103
|
+
# exit
|
104
|
+
#end
|
105
|
+
|
106
|
+
opts.on("--debug", "-d", "Show debugging information") do
|
107
|
+
options[:verbose] = true
|
108
|
+
end
|
109
|
+
|
110
|
+
opts.on("--array", "-a", "Return all values as an array") do
|
111
|
+
options[:resolution_type] = :array
|
112
|
+
end
|
113
|
+
|
114
|
+
opts.on("--hash", "-h", "Return all values as a hash") do
|
115
|
+
options[:resolution_type] = :hash
|
116
|
+
end
|
117
|
+
|
118
|
+
opts.on("--config CONFIG", "-c", "Configuration file") do |v|
|
119
|
+
if File.exist?(v)
|
120
|
+
options[:config] = v
|
121
|
+
else
|
122
|
+
STDERR.puts "Cannot find config file: #{v}"
|
123
|
+
exit 1
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
opts.on("--json SCOPE", "-j", "JSON format file to load scope from") do |v|
|
128
|
+
begin
|
129
|
+
options[:scope] = load_scope(v, :json)
|
130
|
+
rescue Exception => e
|
131
|
+
STDERR.puts "Could not load JSON scope: #{e.class}: #{e}"
|
132
|
+
exit 1
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
opts.on("--yaml SCOPE", "-y", "YAML format file to load scope from") do |v|
|
137
|
+
begin
|
138
|
+
options[:scope] = load_scope(v)
|
139
|
+
rescue Exception => e
|
140
|
+
STDERR.puts "Could not load YAML scope: #{e.class}: #{e}"
|
141
|
+
exit 1
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
opts.on("--mcollective IDENTITY", "-m", "Use facts from a node (via mcollective) as scope") do |v|
|
146
|
+
begin
|
147
|
+
options[:scope] = load_scope(v, :mcollective)
|
148
|
+
rescue Exception => e
|
149
|
+
STDERR.puts "Could not load MCollective scope: #{e.class}: #{e}"
|
150
|
+
exit 1
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
opts.on("--inventory_service IDENTITY", "-i", "Use facts from a node (via Puppet's inventory service) as scope") do |v|
|
155
|
+
begin
|
156
|
+
options[:scope] = load_scope(v, :inventory_service)
|
157
|
+
rescue Exception => e
|
158
|
+
STDERR.puts "Could not load Puppet inventory service scope: #{e.class}: #{e}"
|
159
|
+
exit 1
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end.parse!
|
163
|
+
|
164
|
+
# arguments can be:
|
165
|
+
#
|
166
|
+
# key default var=val another=val
|
167
|
+
#
|
168
|
+
# The var=val's assign scope
|
169
|
+
unless ARGV.empty?
|
170
|
+
options[:key] = ARGV.delete_at(0)
|
171
|
+
|
172
|
+
ARGV.each do |arg|
|
173
|
+
if arg =~ /^(.+?)=(.+?)$/
|
174
|
+
options[:scope][$1] = $2
|
175
|
+
else
|
176
|
+
unless options[:default]
|
177
|
+
options[:default] = arg.dup
|
178
|
+
else
|
179
|
+
STDERR.puts "Don't know how to parse scope argument: #{arg}"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
else
|
184
|
+
STDERR.puts "Please supply a data item to look up"
|
185
|
+
exit 1
|
186
|
+
end
|
187
|
+
|
188
|
+
begin
|
189
|
+
hieraExaminer = HieraExaminer.new(options[:config])
|
190
|
+
rescue Exception => e
|
191
|
+
if options[:verbose]
|
192
|
+
raise
|
193
|
+
else
|
194
|
+
STDERR.puts "Failed to start HieraExaminer: #{e.class}: #{e}"
|
195
|
+
exit 1
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
unless options[:verbose]
|
200
|
+
#HieraExaminer.logger = "noop"
|
201
|
+
end
|
202
|
+
|
203
|
+
hieraExaminer.explain(options[:key], options[:scope])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hiera-examiner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Stortz
|
@@ -12,10 +12,12 @@ date: 2015-12-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
13
13
|
description: A simple hiera gem
|
14
14
|
email: astortz@redstonecontentsolutions.com
|
15
|
-
executables:
|
15
|
+
executables:
|
16
|
+
- hiera-examiner
|
16
17
|
extensions: []
|
17
18
|
extra_rdoc_files: []
|
18
19
|
files:
|
20
|
+
- bin/hiera-examiner
|
19
21
|
- lib/hiera-examiner.rb
|
20
22
|
homepage: http://www.redstonecontentsolutions.com
|
21
23
|
licenses:
|