puppet-runner 0.0.18 → 0.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/puppet-runner +67 -4
- data/lib/avst/string_ext.rb +7 -0
- data/puppet-runner.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4f086089d8c2affa036b2a13590f65ddb9e6c2f8e4fd8bed75e889db6ad2dba1
|
4
|
+
data.tar.gz: 6407eb197c0bb1378a06fbc2c488c095a37cb9e172cc862a74dc8502883ad5be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60c425bb861d0de9d71cd706be3494eacce00197c2a5dddc2b9446fc03479f835ca1b3cb374df78729dec855a8c020979760ecf38d8b9cc3c1da8a02fb9a53de
|
7
|
+
data.tar.gz: 732de9de032ab030d56871cb02c04b4c9eeaa72560696dcb7e70d5d62a206cb1adc99dabd5ac63738900c6655aa126ec77b5615831baf989337b1218b93c7afb
|
data/bin/puppet-runner
CHANGED
@@ -21,6 +21,7 @@ require 'deep_merge'
|
|
21
21
|
require 'docopt'
|
22
22
|
require 'colorize'
|
23
23
|
require 'facter'
|
24
|
+
require 'avst/string_ext'
|
24
25
|
|
25
26
|
doc = <<DOCOPT
|
26
27
|
Adaptavist puppet runner
|
@@ -95,6 +96,22 @@ def extract_comment_from_hash(input)
|
|
95
96
|
res
|
96
97
|
end
|
97
98
|
|
99
|
+
def extract_type_from_hash(input)
|
100
|
+
res = {}
|
101
|
+
if input
|
102
|
+
res = input.map{|key, val|
|
103
|
+
if val != nil
|
104
|
+
type = 'string'
|
105
|
+
if val.is_a?(Hash) and val["type"] != nil
|
106
|
+
type = val["type"]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
{key => type }
|
110
|
+
}
|
111
|
+
end
|
112
|
+
res
|
113
|
+
end
|
114
|
+
|
98
115
|
begin
|
99
116
|
options = Docopt::docopt(doc)
|
100
117
|
rescue Docopt::Exit => e
|
@@ -150,6 +167,7 @@ if options['all'] || options['prepare']
|
|
150
167
|
prefixed_facts_comments = {}
|
151
168
|
puppetfile_config = YAML.load_file(puppetfile_config_path) || {}
|
152
169
|
puppetfile_dependencies = []
|
170
|
+
global_transform_data = []
|
153
171
|
# functionalities:
|
154
172
|
# # In honor of Henry...
|
155
173
|
# 1_app:
|
@@ -189,6 +207,19 @@ if options['all'] || options['prepare']
|
|
189
207
|
|
190
208
|
fact_comments_as_string = extract_comment_from_hash(default_facts).to_s
|
191
209
|
|
210
|
+
# get a list of each fields type if set (if not they will report as strings)
|
211
|
+
data_type = extract_type_from_hash(default_facts)
|
212
|
+
|
213
|
+
# Check to see if any of the fields are booleans, if so add an entry to the transform_data array
|
214
|
+
transform_data = []
|
215
|
+
data_type.each do | field|
|
216
|
+
field.each do | field_name, field_type |
|
217
|
+
if field_type == 'boolean'
|
218
|
+
transform_data << field_name
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
192
223
|
if to_add.is_a?(Hash)
|
193
224
|
# if prefixes are not defined skip replacing
|
194
225
|
if prefixes
|
@@ -205,6 +236,7 @@ if options['all'] || options['prepare']
|
|
205
236
|
facts_as_string = facts_as_string.gsub(/#{prefix}/, "#{replace_prefixes_with}")
|
206
237
|
fact_comments_as_string = fact_comments_as_string.gsub(/#{prefix}/, "#{replace_prefixes_with}")
|
207
238
|
prefixed_required_facts = prefixed_required_facts.merge(required_facts.map! { |item| item.gsub(/#{prefix}/, "#{replace_prefixes_with}") })
|
239
|
+
transform_data = transform_data.map {|s| s.gsub(/#{prefix}/, "#{replace_prefixes_with}")} if !transform_data.empty?
|
208
240
|
end
|
209
241
|
end
|
210
242
|
end
|
@@ -217,6 +249,7 @@ if options['all'] || options['prepare']
|
|
217
249
|
facts_as_string = facts_as_string.gsub(/#{prefix}/, "#{replace_prefixes_with}")
|
218
250
|
fact_comments_as_string = fact_comments_as_string.gsub(/#{prefix}/, "#{replace_prefixes_with}")
|
219
251
|
prefixed_required_facts = prefixed_required_facts.merge(required_facts.map! { |item| item.gsub(/#{prefix}/, "#{replace_prefixes_with}") })
|
252
|
+
transform_data = transform_data.map {|s| s.gsub(/#{prefix}/, "#{replace_prefixes_with}")} if !transform_data.empty?
|
220
253
|
end
|
221
254
|
end
|
222
255
|
end
|
@@ -231,6 +264,9 @@ if options['all'] || options['prepare']
|
|
231
264
|
default_fact_comments = extract_comment_from_hash(plain_facts)
|
232
265
|
prefixed_required_facts = prefixed_required_facts.merge(required_facts)
|
233
266
|
end
|
267
|
+
# add the "local" transformation list to the global one
|
268
|
+
global_transform_data.push(*transform_data)
|
269
|
+
|
234
270
|
result_template.deep_merge!(template)
|
235
271
|
# default_facts_prefixed is Array of hashes as the result of map, this will create hash from it
|
236
272
|
result_default_facts.merge!(default_facts_prefixed.reduce Hash.new, :merge)
|
@@ -240,10 +276,6 @@ if options['all'] || options['prepare']
|
|
240
276
|
end
|
241
277
|
end
|
242
278
|
end
|
243
|
-
# Write results
|
244
|
-
File.open(output_file_path, 'w+') do |output_file|
|
245
|
-
YAML.dump(result_template, output_file)
|
246
|
-
end
|
247
279
|
custom_facts_path = path_join_glob(input_dir, "#{hostname}_facts.yaml")
|
248
280
|
custom_facts = YAML.load_file(custom_facts_path) || {}
|
249
281
|
File.open(output_encrypted_facts_file_path, 'w+') do |output_file|
|
@@ -254,6 +286,29 @@ if options['all'] || options['prepare']
|
|
254
286
|
end
|
255
287
|
end
|
256
288
|
output_file.write(output_result_default_facts)
|
289
|
+
|
290
|
+
# now that the merged final facts are present look for any global transformations to apply
|
291
|
+
# global transformations are currently just booleans that need to be expressed directly in output file
|
292
|
+
if !global_transform_data.empty?
|
293
|
+
result_template = result_template.to_s
|
294
|
+
all_facts = YAML.load(output_result_default_facts)
|
295
|
+
global_transform_data.each do | transform_value |
|
296
|
+
debug "Attempting to replace boolean value for fact #{transform_value}"
|
297
|
+
begin
|
298
|
+
# convert the final template to a string, replace any facts that are booleans with their actual value and then convert the result bacl to YAML
|
299
|
+
# convert the fact to boolean and then back to string during the replace, this allows validation that the fact is actually a boolean
|
300
|
+
result_template = result_template.gsub(/\"\%{::#{transform_value}}\"/, all_facts[transform_value].to_bool.to_s)
|
301
|
+
rescue
|
302
|
+
warning "Unable to convert fact #{transform_value} with value #{all_facts[transform_value]} into boolean, conversion will be skipped"
|
303
|
+
end
|
304
|
+
end
|
305
|
+
result_template = eval(result_template)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
# Write results
|
310
|
+
File.open(output_file_path, 'w+') do |output_file|
|
311
|
+
YAML.dump(result_template, output_file)
|
257
312
|
end
|
258
313
|
|
259
314
|
# decrypt facts file because Puppet doesn't appear to be able to read encrypted facts
|
@@ -298,7 +353,14 @@ if options['all'] || options['prepare']
|
|
298
353
|
end
|
299
354
|
output_file.write(decrypted.join)
|
300
355
|
end
|
356
|
+
|
357
|
+
begin
|
358
|
+
FileUtils.rm output_encrypted_facts_file_path
|
359
|
+
rescue
|
360
|
+
warning "Unable to remove tmp encrypted facts file #{output_encrypted_facts_file_path}"
|
361
|
+
end
|
301
362
|
|
363
|
+
# create puppetfile from the dictionary
|
302
364
|
File.open(puppetfile_output_path, 'w+') do |output_file|
|
303
365
|
header = "#!/usr/bin/env ruby\n\n"
|
304
366
|
output_file.write(header)
|
@@ -348,3 +410,4 @@ if (options['start'] || options['all']) && !stop_apply
|
|
348
410
|
end
|
349
411
|
end
|
350
412
|
|
413
|
+
|
data/puppet-runner.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "puppet-runner"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.19"
|
8
8
|
spec.authors = ["Martin Brehovsky", "Matthew Hope"]
|
9
9
|
spec.email = ["mbrehovsky@adaptavist.com"]
|
10
10
|
spec.summary = %q{Preprocessor for hiera config}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-runner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Brehovsky
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-03-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- README.md
|
141
141
|
- Rakefile
|
142
142
|
- bin/puppet-runner
|
143
|
+
- lib/avst/string_ext.rb
|
143
144
|
- puppet-runner.gemspec
|
144
145
|
- test/configs/defaults/confluence.yaml
|
145
146
|
- test/configs/defaults/connector_proxy.yaml
|
@@ -172,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
173
|
version: '0'
|
173
174
|
requirements: []
|
174
175
|
rubyforge_project:
|
175
|
-
rubygems_version: 2.
|
176
|
+
rubygems_version: 2.7.6
|
176
177
|
signing_key:
|
177
178
|
specification_version: 4
|
178
179
|
summary: Preprocessor for hiera config
|