hieracles 0.2.0 → 0.2.1
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/CHANGELOG.md +10 -0
- data/Gemfile +2 -0
- data/README.md +54 -8
- data/bin/hc +12 -6
- data/bin/ppdb +42 -0
- data/hc.1 +50 -8
- data/lib/hieracles.rb +2 -2
- data/lib/hieracles/config.rb +31 -19
- data/lib/hieracles/format.rb +4 -0
- data/lib/hieracles/formats/console.rb +49 -16
- data/lib/hieracles/formats/csv.rb +12 -8
- data/lib/hieracles/formats/json.rb +19 -6
- data/lib/hieracles/formats/plain.rb +24 -3
- data/lib/hieracles/formats/rawyaml.rb +4 -0
- data/lib/hieracles/formats/yaml.rb +4 -0
- data/lib/hieracles/node.rb +55 -10
- data/lib/hieracles/notification.rb +31 -0
- data/lib/hieracles/options/hc.rb +109 -0
- data/lib/hieracles/options/ppdb.rb +32 -0
- data/lib/hieracles/optparse.rb +4 -43
- data/lib/hieracles/puppetdb.rb +12 -0
- data/lib/hieracles/puppetdb/apierror.rb +10 -0
- data/lib/hieracles/puppetdb/client.rb +63 -0
- data/lib/hieracles/puppetdb/filter.rb +15 -0
- data/lib/hieracles/puppetdb/fixsslconnectionadapter.rb +25 -0
- data/lib/hieracles/puppetdb/query.rb +79 -0
- data/lib/hieracles/puppetdb/request.rb +44 -0
- data/lib/hieracles/puppetdb/response.rb +14 -0
- data/ppdb.1 +158 -0
- data/spec/files/config.yml +2 -0
- data/spec/files/config_withdb.yml +9 -0
- data/spec/files/facts.json +110 -0
- data/spec/files/facts.yaml +103 -0
- data/spec/files/hiera_columns.yaml +16 -0
- data/spec/files/hiera_deep.yaml +17 -0
- data/spec/files/hiera_deeper.yaml +17 -0
- data/spec/files/ssl/bad-ca.crt +1 -0
- data/spec/files/ssl/bad-cert.crt +1 -0
- data/spec/files/ssl/bad-key.pem +1 -0
- data/spec/files/ssl/ca.crt +16 -0
- data/spec/files/ssl/cert.crt +16 -0
- data/spec/files/ssl/key-pass.pem +18 -0
- data/spec/files/ssl/key.pem +15 -0
- data/spec/lib/config_spec.rb +51 -11
- data/spec/lib/format_spec.rb +5 -0
- data/spec/lib/formats/console_spec.rb +24 -3
- data/spec/lib/formats/csv_spec.rb +15 -0
- data/spec/lib/formats/json_spec.rb +22 -2
- data/spec/lib/formats/plain_spec.rb +23 -3
- data/spec/lib/formats/rawyaml_spec.rb +13 -0
- data/spec/lib/formats/yaml_spec.rb +138 -48
- data/spec/lib/hiera_spec.rb +0 -1
- data/spec/lib/hieracles_spec.rb +8 -0
- data/spec/lib/interpolate_spec.rb +49 -0
- data/spec/lib/node_spec.rb +50 -9
- data/spec/lib/notification_spec.rb +29 -0
- data/spec/lib/options/hc_spec.rb +82 -0
- data/spec/lib/optparse_spec.rb +7 -7
- data/spec/lib/puppetdb/apierror_spec.rb +11 -0
- data/spec/lib/puppetdb/client_spec.rb +64 -0
- data/spec/lib/puppetdb/fixsslconnectionadapter_spec.rb +107 -0
- data/spec/lib/puppetdb/query_spec.rb +39 -0
- data/spec/lib/puppetdb/request_spec.rb +61 -0
- data/spec/lib/puppetdb/response_spec.rb +13 -0
- data/spec/spec_helper.rb +4 -4
- metadata +133 -30
- data/Rakefile +0 -14
- data/hieracles.gemspec +0 -90
- data/lib/hieracles/help.rb +0 -38
- data/spec/lib/help_spec.rb +0 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c52c2ee117ba60358faf78e464d6530786ebeb79
|
|
4
|
+
data.tar.gz: 9a1c3bd0fc147a75d1d0e399d75acd84c480dfa5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f1039911f488752aeb1324c5a24c1ba0679fd1c64705766532d0fe364c6a7de311cf3de4cce0e069f08bde3c75ee553d5c26684ad4c0ea2d5ba72f7a1c5a10fa
|
|
7
|
+
data.tar.gz: 91b8db1bbc0dfa06899a21542c6e172facff41a4a5fbf157870d9c6981afe17c90993d706be53129bdde5e5bb3db17179bfc7ac9a56cf87d52904e579d7cb3db
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
Hieracles Changelog
|
|
2
2
|
=======================
|
|
3
3
|
|
|
4
|
+
### 0.2.1 - 2015-12-11
|
|
5
|
+
- add configuration variables for connection to PuppetDB
|
|
6
|
+
- make PuppetDB calls fill up the facts for the node queried
|
|
7
|
+
- add a `facts` command to display the facts, provided locally
|
|
8
|
+
or from PuppetDB directly
|
|
9
|
+
- make a new CLI tool named ppdb for direct calls to PuppetDB
|
|
10
|
+
- add optional filtering on ppdb commands
|
|
11
|
+
- add a man page for ppdb
|
|
12
|
+
- add zsh completion for ppdb
|
|
13
|
+
|
|
4
14
|
### 0.2.0 - 2015-11-24
|
|
5
15
|
- fix merging for unsorted arrays
|
|
6
16
|
- translate all paths to absolute paths,
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -4,8 +4,8 @@ Hieracles
|
|
|
4
4
|
[](http://rubygems.org/gems/hieracles)
|
|
5
5
|
[](https://rubygems.org/gems/hieracles)
|
|
6
6
|
[](https://travis-ci.org/Gandi/hieracles)
|
|
7
|
-
[](https://coveralls.io/github/Gandi/hieracles?branch=master)
|
|
8
|
+
[](https://gemnasium.com/Gandi/hieracles)
|
|
9
9
|
[](https://codeclimate.com/github/Gandi/hieracles)
|
|
10
10
|
|
|
11
11
|
Hieracles is a command-line tool for analysis and deep examination of [Hiera][hiera] parameters in a [Puppet][puppet] setup. It can be used to quickly visualize, from a local puppet (typically on a developers environment), all the Hiera params related to a specific node.
|
|
@@ -55,7 +55,7 @@ Configuration variables are:
|
|
|
55
55
|
- encpath
|
|
56
56
|
where to read information about each nodes
|
|
57
57
|
- hierafile
|
|
58
|
-
where to find a hierafile
|
|
58
|
+
where to find a hierafile customized for your local puppet installation
|
|
59
59
|
- format
|
|
60
60
|
can be plain, console, csv, yaml, rawyaml, json
|
|
61
61
|
- defaultscope
|
|
@@ -73,6 +73,14 @@ Usage
|
|
|
73
73
|
Available commands:
|
|
74
74
|
info provides the farm, datacenter, country
|
|
75
75
|
associated to the given fqdn
|
|
76
|
+
An extra param can be added for filtering
|
|
77
|
+
eg. hc <fqdn> info timestamp
|
|
78
|
+
eg. hc <fqdn> info farm
|
|
79
|
+
facts lists facts, either provided as a fact file
|
|
80
|
+
or grabbed from puppetdb.
|
|
81
|
+
An extra param can be added for filtering
|
|
82
|
+
eg. hc <fqdn> facts architecture
|
|
83
|
+
eg. hc <fqdn> facts 'memory.*mb'
|
|
76
84
|
files list all files containing params affecting this fqdn
|
|
77
85
|
(in more than commons)
|
|
78
86
|
paths list all file paths for files with params
|
|
@@ -97,13 +105,13 @@ Usage
|
|
|
97
105
|
-y <fact_file> - facts in yaml format
|
|
98
106
|
-j <fact_file> - facts in json format
|
|
99
107
|
-i - interactive mode
|
|
108
|
+
-db - query puppetdb
|
|
109
|
+
-nodb - do not query puppetdb
|
|
100
110
|
|
|
101
111
|
|
|
102
112
|
About facts aka. scope
|
|
103
113
|
------------------------
|
|
104
114
|
|
|
105
|
-
_(work in progress)_
|
|
106
|
-
|
|
107
115
|
Like with Hiera CLI you can use hieracles with defined top-scope variables. Those top-scope vars can be defined with:
|
|
108
116
|
|
|
109
117
|
- `-p extraparam=what;anotherparam=this`
|
|
@@ -131,24 +139,62 @@ Note that if the scope var is not defined or if the file declared in hiera confi
|
|
|
131
139
|
An option, `-i` enables the `interactive mode` in which you are prompted to fill up for undefined scope variables encountered in the hiera config file. This behavior can be made systematic by enabling `interactive: true` in hieracles configuration file.
|
|
132
140
|
|
|
133
141
|
|
|
142
|
+
Optionnaly connecting to a puppetDB
|
|
143
|
+
--------------------------------------
|
|
144
|
+
|
|
145
|
+
#### Configuration
|
|
146
|
+
|
|
147
|
+
When adding to the configuration file:
|
|
148
|
+
|
|
149
|
+
usedb: false
|
|
150
|
+
puppetdb:
|
|
151
|
+
usessl: false
|
|
152
|
+
host: puppetdb.example.com
|
|
153
|
+
port: 8080
|
|
154
|
+
|
|
155
|
+
or for a ssl setup:
|
|
156
|
+
|
|
157
|
+
usedb: false
|
|
158
|
+
puppetdb:
|
|
159
|
+
usessl: true
|
|
160
|
+
host: puppetdb.example.com
|
|
161
|
+
port: 8081
|
|
162
|
+
key: path/to/key
|
|
163
|
+
key_password: somepassword
|
|
164
|
+
cert: path/to/cert
|
|
165
|
+
ca_file: path/to/ca_file
|
|
166
|
+
verify_peer: false
|
|
167
|
+
|
|
168
|
+
#### Usage
|
|
169
|
+
|
|
170
|
+
If you set `usedb: false` the `hc` commands will not query the puppetdb unless you pass the `-db` options.
|
|
171
|
+
|
|
172
|
+
If you set `usedb: true` the `hc` command will query the puppetdb by default and display extra informations for the queried node. This default behavior can be changed by passing the `-nodb` option on the commandline.
|
|
173
|
+
|
|
174
|
+
#### Impact
|
|
175
|
+
|
|
176
|
+
When usedb is true, a call to puppetdb will be made for all commands to retrieve facts if they are present for the queried node.
|
|
177
|
+
|
|
178
|
+
|
|
134
179
|
Completion
|
|
135
180
|
-------------
|
|
136
181
|
There is a simple zsh completion file in `tools/completion`.
|
|
137
182
|
|
|
138
183
|
If you use [oh-my-zsh][omz] put it in `~/.oh-my-zsh/completions`
|
|
139
184
|
|
|
140
|
-
wget -O ~/.oh-my-zsh/completions/_hc https://raw.githubusercontent.com/Gandi/hieracles/master/tools/completion/_hc
|
|
185
|
+
wget -O ~/.oh-my-zsh/completions/_hc https://raw.githubusercontent.com/Gandi/hieracles/master/tools/completion/zsh/_hc
|
|
141
186
|
echo 'compdef _hc hc "bundle exec hc"' >> ~/.zshrc
|
|
142
187
|
echo 'autoload -U _hc' >> ~/.zshrc
|
|
143
188
|
|
|
144
189
|
Otherwise
|
|
145
190
|
|
|
146
191
|
mkdir ~/.zsh-completions
|
|
147
|
-
wget -O ~/.zsh-completions/_hc https://raw.githubusercontent.com/Gandi/hieracles/master/tools/completion/_hc
|
|
192
|
+
wget -O ~/.zsh-completions/_hc https://raw.githubusercontent.com/Gandi/hieracles/master/tools/completion/zsh/_hc
|
|
148
193
|
echo 'fpath=(~/.zsh-completions $fpath)' >> ~/.zshrc
|
|
149
194
|
echo 'compdef _hc hc "bundle exec hc"' >> ~/.zshrc
|
|
150
195
|
echo 'autoload -U _hc' >> ~/.zshrc
|
|
151
196
|
|
|
197
|
+
Note: `ppdb` also has a completion file https://raw.githubusercontent.com/Gandi/hieracles/master/tools/completion/zsh/_ppdb
|
|
152
198
|
|
|
153
199
|
Debian packaging
|
|
154
200
|
--------------------
|
|
@@ -195,7 +241,7 @@ Todo
|
|
|
195
241
|
- detect unused params
|
|
196
242
|
- create a repl, which at launch reads all data so the queries are blazing fast
|
|
197
243
|
- adapt to other ENCs
|
|
198
|
-
- adapt to
|
|
244
|
+
- adapt to PuppetDB storage
|
|
199
245
|
|
|
200
246
|
|
|
201
247
|
Authors
|
data/bin/hc
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
$LOAD_PATH << File.expand_path("../../lib", __FILE__)
|
|
4
4
|
|
|
5
5
|
require 'hieracles'
|
|
6
|
+
require 'hieracles/options/hc'
|
|
6
7
|
|
|
7
|
-
opt = Hieracles::
|
|
8
|
+
opt = Hieracles::Options::Hc.new(ARGV)
|
|
8
9
|
|
|
9
10
|
if opt.options.has_key? :version
|
|
10
11
|
puts Hieracles.version
|
|
@@ -16,22 +17,27 @@ command = opt.payload[1]
|
|
|
16
17
|
args = opt.payload[2..-1]
|
|
17
18
|
|
|
18
19
|
unless fqdn && command
|
|
19
|
-
puts Hieracles::
|
|
20
|
+
puts Hieracles::Options::Hc.usage
|
|
20
21
|
exit(1)
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
if Hieracles::Format.method_defined? command
|
|
24
|
-
|
|
25
|
+
begin
|
|
26
|
+
node = Hieracles::Node.new fqdn, opt.options
|
|
27
|
+
rescue Exception => e
|
|
28
|
+
puts "*** Error: #{e.message}"
|
|
29
|
+
exit(1)
|
|
30
|
+
end
|
|
25
31
|
begin
|
|
26
32
|
formatter = Object.const_get("Hieracles::Formats::#{Hieracles::Config.format}")
|
|
27
33
|
rescue
|
|
28
|
-
puts "
|
|
34
|
+
puts "*** Unknown format #{Hieracles::Config.format}"
|
|
29
35
|
exit(1)
|
|
30
36
|
end
|
|
31
37
|
dispatch = formatter.new node
|
|
32
38
|
puts dispatch.send(command.to_sym, args)
|
|
33
39
|
else
|
|
34
|
-
puts "
|
|
35
|
-
Hieracles::
|
|
40
|
+
puts "*** Unknown command: #{command}"
|
|
41
|
+
Hieracles::Options::Hc.usage
|
|
36
42
|
exit(1)
|
|
37
43
|
end
|
data/bin/ppdb
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH << File.expand_path("../../lib", __FILE__)
|
|
4
|
+
|
|
5
|
+
require 'hieracles'
|
|
6
|
+
require 'hieracles/options/ppdb'
|
|
7
|
+
|
|
8
|
+
opt = Hieracles::Options::Ppdb.new(ARGV)
|
|
9
|
+
|
|
10
|
+
if opt.options.has_key? :version
|
|
11
|
+
puts Hieracles.version
|
|
12
|
+
exit(0)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
unless opt.payload[1]
|
|
16
|
+
puts Hieracles::Options::Ppdb.usage
|
|
17
|
+
exit(1)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
command = "#{opt.payload[0]}_#{opt.payload[1]}"
|
|
21
|
+
args = opt.payload[2..-1] || []
|
|
22
|
+
|
|
23
|
+
Hieracles::Config.load opt.options
|
|
24
|
+
|
|
25
|
+
if Hieracles::Puppetdb::Request.method_defined? command
|
|
26
|
+
request = Hieracles::Puppetdb::Request.new Hieracles::Config.puppetdb
|
|
27
|
+
meth = request.method(command.to_sym)
|
|
28
|
+
required = request.method(command.to_sym).parameters.select { |arg| arg[0] == :req }.map { |arg| arg[1] }
|
|
29
|
+
if args.length < required.length
|
|
30
|
+
args = required.join(', ')
|
|
31
|
+
puts "*** The #{command} method requires arguments: #{args}"
|
|
32
|
+
exit(1)
|
|
33
|
+
else
|
|
34
|
+
format = Hieracles::Formats::Console.new(nil)
|
|
35
|
+
resp = meth.call(*args)
|
|
36
|
+
puts format.build_list(resp.data, resp.notifications, [])
|
|
37
|
+
end
|
|
38
|
+
else
|
|
39
|
+
puts "*** Unknown command: #{command}"
|
|
40
|
+
puts Hieracles::Options::Ppdb.usage
|
|
41
|
+
exit(1)
|
|
42
|
+
end
|
data/hc.1
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
.TH hc 1 "2015-
|
|
1
|
+
.TH hc 1 "2015-12-05" "version 0.2.1" "Hieracles command manual"
|
|
2
2
|
|
|
3
3
|
.SH NAME
|
|
4
|
-
hc \- Command tool for Hieracles
|
|
4
|
+
hc \- Command line tool for Hieracles
|
|
5
5
|
.SH SYNOPSIS
|
|
6
6
|
.B hc
|
|
7
7
|
.I fqdn
|
|
@@ -23,24 +23,47 @@ time, a generic Hiera overlay visualization tool.
|
|
|
23
23
|
.PP
|
|
24
24
|
hc command takes at minimum 2 arguments:
|
|
25
25
|
.RS 4
|
|
26
|
+
|
|
26
27
|
.IP fqdn 10
|
|
27
28
|
the fqdn under which the node is known in the ENC dir
|
|
29
|
+
|
|
28
30
|
.IP action
|
|
29
31
|
the action needs to be one of the following
|
|
30
32
|
.RS
|
|
33
|
+
|
|
31
34
|
.IP info 10
|
|
32
35
|
provides the farm, datacenter, country associated to the given fqdn.
|
|
36
|
+
An extra filter can be added to limit the list.
|
|
37
|
+
Use ruby regexp without the enclosing slashes.
|
|
38
|
+
.RS
|
|
39
|
+
eg. hc <fqdn> info timestamps
|
|
40
|
+
.RE
|
|
41
|
+
|
|
42
|
+
.IP facts 10
|
|
43
|
+
lists facts for a given fqdn, from puppetdb or local facts (see configuration).
|
|
44
|
+
An extra filter can be added to limit the list.
|
|
45
|
+
use ruby regexp without the enclosing slashes.
|
|
46
|
+
.RS
|
|
47
|
+
eg. hc <fqdn> facts architecture
|
|
48
|
+
.RE
|
|
49
|
+
.RS
|
|
50
|
+
eg. hc <fqdn> facts 'memory.*mb'
|
|
51
|
+
.RE
|
|
52
|
+
|
|
33
53
|
.IP files
|
|
34
54
|
list all files containing params affecting this fqdn
|
|
35
55
|
(in more than commons).
|
|
56
|
+
|
|
36
57
|
.IP paths
|
|
37
58
|
list all file paths for files with params.
|
|
59
|
+
|
|
38
60
|
.IP modules
|
|
39
61
|
list modules included in the farm where the node is.
|
|
62
|
+
|
|
40
63
|
.IP params
|
|
41
64
|
list params for the node matching the fqdn.
|
|
42
|
-
An extra filter
|
|
43
|
-
|
|
65
|
+
An extra filter can be added to limit the list.
|
|
66
|
+
Use ruby regexp without the enclosing slashes.
|
|
44
67
|
.RS
|
|
45
68
|
eg. hc <fqdn> params postfix.*version
|
|
46
69
|
.RE
|
|
@@ -50,7 +73,8 @@ eg. hc <fqdn> params '^postfix'
|
|
|
50
73
|
.RS
|
|
51
74
|
eg. hc <fqdn> params 'version$'
|
|
52
75
|
.RE
|
|
53
|
-
|
|
76
|
+
|
|
77
|
+
.IP allparams
|
|
54
78
|
same as params but including the common.yaml params (huge)
|
|
55
79
|
Also accepts a search string
|
|
56
80
|
.RE
|
|
@@ -122,7 +146,6 @@ the basepath is prepended to the paths found in the configfile and the hierafile
|
|
|
122
146
|
.B \-\-encdir \fRpath
|
|
123
147
|
encdir is where we can find the ENC definitions. It's stated in the configfile but can be overridden by the -e option.
|
|
124
148
|
|
|
125
|
-
|
|
126
149
|
.TP
|
|
127
150
|
.PD 0
|
|
128
151
|
.B \-y \fRfile
|
|
@@ -136,7 +159,6 @@ and test locally what would be the consequences of switching from
|
|
|
136
159
|
one environment to another. It's also good for anticipation
|
|
137
160
|
of how new node, that don't have facts yet, will behave.
|
|
138
161
|
|
|
139
|
-
|
|
140
162
|
.TP
|
|
141
163
|
.PD 0
|
|
142
164
|
.B \-j \fRfile
|
|
@@ -150,7 +172,6 @@ flag but in json format, which can be obtained on the node with
|
|
|
150
172
|
and this behave the same way. Note that the \-y has precedence on
|
|
151
173
|
the \-j in this context.
|
|
152
174
|
|
|
153
|
-
|
|
154
175
|
.TP
|
|
155
176
|
.PD 0
|
|
156
177
|
.B \-i
|
|
@@ -166,6 +187,24 @@ in which you are prompted to fill up for undefined scope variables encountered i
|
|
|
166
187
|
in hieracles configuration file.
|
|
167
188
|
.RE
|
|
168
189
|
|
|
190
|
+
.TP
|
|
191
|
+
.PD 0
|
|
192
|
+
.B \-db
|
|
193
|
+
if
|
|
194
|
+
.I "usedb: false"
|
|
195
|
+
is specified in the hieracles configuration file, it cancels the calls to puppetdb
|
|
196
|
+
and only display information according to local data.
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
.TP
|
|
200
|
+
.PD 0
|
|
201
|
+
.B \-nodb
|
|
202
|
+
if
|
|
203
|
+
.I "usedb: true"
|
|
204
|
+
is specified in the hieracles configuration file, it forces the calls to puppetdb
|
|
205
|
+
for gathering facts and node information.
|
|
206
|
+
|
|
207
|
+
|
|
169
208
|
.SH FILES
|
|
170
209
|
.I ~/.config/hieracles/config.yaml
|
|
171
210
|
.RS
|
|
@@ -178,6 +217,9 @@ A typical config file would look like:
|
|
|
178
217
|
---
|
|
179
218
|
.RE
|
|
180
219
|
.RS
|
|
220
|
+
basepath: /home/mose/git/puppet
|
|
221
|
+
.RE
|
|
222
|
+
.RS
|
|
181
223
|
classpath: farm_modules/%s/manifests/init.pp
|
|
182
224
|
.RE
|
|
183
225
|
.RS
|
data/lib/hieracles.rb
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
require 'hieracles/notification'
|
|
1
2
|
require 'hieracles/interpolate'
|
|
2
|
-
require 'hieracles/optparse'
|
|
3
3
|
require 'hieracles/config'
|
|
4
4
|
require 'hieracles/hiera'
|
|
5
5
|
require 'hieracles/utils'
|
|
6
|
-
require 'hieracles/help'
|
|
7
6
|
require 'hieracles/node'
|
|
8
7
|
require 'hieracles/format'
|
|
9
8
|
require 'hieracles/registry'
|
|
@@ -13,6 +12,7 @@ require 'hieracles/formats/yaml'
|
|
|
13
12
|
require 'hieracles/formats/plain'
|
|
14
13
|
require 'hieracles/formats/console'
|
|
15
14
|
require 'hieracles/formats/rawyaml'
|
|
15
|
+
require 'hieracles/puppetdb'
|
|
16
16
|
|
|
17
17
|
# https://github.com/Gandi/hieracles
|
|
18
18
|
module Hieracles
|
data/lib/hieracles/config.rb
CHANGED
|
@@ -9,37 +9,47 @@ module Hieracles
|
|
|
9
9
|
include Hieracles::Utils
|
|
10
10
|
extend self
|
|
11
11
|
|
|
12
|
-
attr_reader :extraparams, :server, :classpath, :scope,
|
|
12
|
+
attr_reader :extraparams, :server, :classpath, :scope, :puppetdb, :usedb,
|
|
13
13
|
:modulepath, :hierafile, :basepath, :encpath, :format, :interactive
|
|
14
14
|
|
|
15
15
|
def load(options)
|
|
16
|
-
@
|
|
16
|
+
@options = options
|
|
17
|
+
@optionfile = @options[:config] || defaultconfig
|
|
17
18
|
@extraparams = extract_params(options[:params])
|
|
18
|
-
values = get_config(@optionfile)
|
|
19
|
-
@server = values['server']
|
|
20
|
-
@
|
|
21
|
-
|
|
22
|
-
@
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
@
|
|
29
|
-
@
|
|
19
|
+
@values = get_config(@optionfile)
|
|
20
|
+
@server = @values['server']
|
|
21
|
+
@usedb = if @options[:db]
|
|
22
|
+
true
|
|
23
|
+
elsif @options[:nodb]
|
|
24
|
+
false
|
|
25
|
+
else
|
|
26
|
+
@values['usedb']
|
|
27
|
+
end
|
|
28
|
+
@puppetdb = @values['puppetdb']
|
|
29
|
+
@values['basepath'] ||= @values['localpath']
|
|
30
|
+
@basepath = File.expand_path(pick_first(:basepath, '.'))
|
|
31
|
+
@classpath = build_path(@values['classpath'])
|
|
32
|
+
@modulepath = resolve_path(pick_first(:modulepath, 'modules'))
|
|
33
|
+
@encpath = resolve_path(pick_first(:encpath, 'enc'))
|
|
34
|
+
@hierafile = resolve_path(pick_first(:hierafile, 'hiera.yaml'))
|
|
35
|
+
@format = pick_first(:format, 'console').capitalize
|
|
36
|
+
@scope = load_scope(@values)
|
|
37
|
+
@interactive = pick_first(:interactive, false)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def pick_first(label, default)
|
|
41
|
+
@options[label] || @values[label.to_s] || default
|
|
30
42
|
end
|
|
31
43
|
|
|
32
44
|
def get_config(file)
|
|
33
45
|
initconfig(file) unless File.exist? file
|
|
34
|
-
|
|
46
|
+
YAML.load_file(file)
|
|
35
47
|
end
|
|
36
48
|
|
|
37
49
|
def initconfig(file)
|
|
38
50
|
FileUtils.mkdir_p(File.dirname(file))
|
|
39
51
|
File.open(file, 'w') do |f|
|
|
40
52
|
f.puts '---'
|
|
41
|
-
f.puts '# uncomment if you use the CGI method for discovery'
|
|
42
|
-
f.puts '# server: puppetserver.example.com'
|
|
43
53
|
f.puts 'classpath: manifests/classes/%s.pp'
|
|
44
54
|
f.puts 'modulepath: modules'
|
|
45
55
|
f.puts 'encpath: enc'
|
|
@@ -60,8 +70,10 @@ module Hieracles
|
|
|
60
70
|
end
|
|
61
71
|
end
|
|
62
72
|
|
|
63
|
-
def
|
|
64
|
-
|
|
73
|
+
def load_scope(values)
|
|
74
|
+
facts_file = @options[:yaml_facts] || @options[:json_facts]
|
|
75
|
+
facts_format = @options[:json_facts] ? :json : :yaml
|
|
76
|
+
sym_keys((facts_file && load_facts(facts_file, facts_format)) || values['defaultscope'] || {})
|
|
65
77
|
end
|
|
66
78
|
|
|
67
79
|
def load_facts(file, format)
|