hiera-examiner 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. metadata +1 -2
  3. data/bin/hiera-examiner +0 -203
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31fc493b8ef4d1fedd0be37d594a9e7f69cc54d6
4
- data.tar.gz: 68dc85828fe5dec5b459a359b740078fbec75b12
3
+ metadata.gz: 8ed19f101430113f7c405990f3632f3879610069
4
+ data.tar.gz: ad06f630e6e97bc95ff3277d8828057db93d429f
5
5
  SHA512:
6
- metadata.gz: 2e7c1135812912ce7459c473e6793cfa7b7f0d663651d296df3195cf5ab51d6a76db12f5d5a15fd405331f828fea3aed799b89598442b97a3f870bf1837055dc
7
- data.tar.gz: 86264c9d528365ce784a258a25241d9c2085cd7be18aa4549bec36f8b9ebb2e30a5c33265157d2ff9b389ffeda9f02e55dbc1a1a192d30a84e18c711b2ac8574
6
+ metadata.gz: a83d14c196a84a81f0d80f34daef0c0664af05ffcedff31d3975bd6c2ccfda9d58aa55c138765377970495007c3c777d43e5a8e8b85d4466cd99bad88d785505
7
+ data.tar.gz: f160efb2be1e8326f3783f2a71ec7799bc6f7fdf0e0a36da4fded10aa5e91fd959da1f7a68d059476c0b7e719b95be88e16748ad992a4d19191cf3833c800287
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.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Stortz
@@ -16,7 +16,6 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
- - bin/hiera-examiner
20
19
  - lib/hiera-examiner.rb
21
20
  homepage: http://www.redstonecontentsolutions.com
22
21
  licenses:
data/bin/hiera-examiner DELETED
@@ -1,203 +0,0 @@
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])