kafo 1.0.6 → 1.0.7
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/config/kafo.yaml.example +0 -3
- data/doc/kafo_run.png +0 -0
- data/doc/kafo_run.uml +109 -0
- data/lib/kafo/configuration.rb +36 -11
- data/lib/kafo/exit_handler.rb +2 -1
- data/lib/kafo/kafo_configure.rb +11 -3
- data/lib/kafo/param.rb +9 -3
- data/lib/kafo/version.rb +1 -1
- data/modules/kafo_configure/lib/puppet/functions/dump_lookups.rb +14 -0
- data/modules/kafo_configure/lib/puppet/parser/functions/dump_values.rb +3 -8
- data/modules/kafo_configure/lib/puppet/parser/functions/to_yaml.rb +13 -0
- data/modules/kafo_configure/manifests/dump_values.pp +21 -0
- metadata +7 -5
- data/LICENSE.txt +0 -11
- data/README.md +0 -1112
- data/Rakefile +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e997beadceb5307a50757065a9b0feb0fcd7d35
|
4
|
+
data.tar.gz: a2460963b6539e91acecf021935e94bb329dcbab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bed514715b9f2913a85cdbeee6713f1f1d74d38a311014ebf38b2a3d42c9fc0bc0797656ad063e6346b1e62c4500d14e29ccb5bd3a32082ae63d5218627a2851
|
7
|
+
data.tar.gz: da303a516a27fb37c9a339198ff0e62a1bc8b3ecfc1f4068d49ef7e93ba6a3c9a4907ad52da45d931b8bf1cda98195eba8fa36c7214fb2abeb119f47d1bb34f0
|
data/config/kafo.yaml.example
CHANGED
@@ -36,9 +36,6 @@
|
|
36
36
|
# :log_name: configure.log
|
37
37
|
# :log_level: :info
|
38
38
|
|
39
|
-
# Change if you want to debug default answers for you modules, this directory holds default answers
|
40
|
-
# :default_values_dir: /tmp
|
41
|
-
|
42
39
|
## Advanced configuration - if not set it's ignored
|
43
40
|
# :log_owner: root
|
44
41
|
# :log_group: root
|
data/doc/kafo_run.png
ADDED
Binary file
|
data/doc/kafo_run.uml
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
/'Use PlantUML (http://plantuml.com/starting) to render this file to other formats like PNG, SVG, EPS'/
|
2
|
+
@startuml
|
3
|
+
|initialize|
|
4
|
+
start
|
5
|
+
:scenario manager setup;
|
6
|
+
note right
|
7
|
+
* guess scenario dir
|
8
|
+
* detect last used scenario
|
9
|
+
end note
|
10
|
+
#LightGrey:--list-scenarios>
|
11
|
+
:get config file;
|
12
|
+
note right
|
13
|
+
One of the following in this order
|
14
|
+
# **CONFIG_FILE**
|
15
|
+
# **--scenario** or **-S** in installer arguments
|
16
|
+
# previous scenarios
|
17
|
+
# any available scenario if there is *just one*
|
18
|
+
# select scenario if installer is in interactive mode
|
19
|
+
end note
|
20
|
+
|
21
|
+
if (no config file?)
|
22
|
+
stop
|
23
|
+
endif
|
24
|
+
|
25
|
+
:load configuration;
|
26
|
+
note right
|
27
|
+
* load configuration
|
28
|
+
* merge defaults
|
29
|
+
* save configuration
|
30
|
+
* load answer file
|
31
|
+
* setup kafo dirs
|
32
|
+
* setup hooks
|
33
|
+
* setup key-value store
|
34
|
+
end note
|
35
|
+
|
36
|
+
#greenyellow:**pre_migrations**|
|
37
|
+
note right: here the 6.1 configs get turned into 6.2 scenarios
|
38
|
+
|
39
|
+
:load configuration;
|
40
|
+
note right: if migrations requested reload
|
41
|
+
|
42
|
+
:execute scenario migrations;
|
43
|
+
|
44
|
+
#LightGrey:--migrations-only>
|
45
|
+
:load configuration;
|
46
|
+
note right: if any migration was applied
|
47
|
+
|
48
|
+
if (previous scenario != current scenario) then (scenario\nchanged)
|
49
|
+
#LightGrey:--compare-scenarios>
|
50
|
+
:load previous scenario;
|
51
|
+
:run scenario migrations
|
52
|
+
on previous scenario;
|
53
|
+
:migrate data from previous scenario
|
54
|
+
configuration to the current one;
|
55
|
+
:load configuration;
|
56
|
+
endif
|
57
|
+
|
58
|
+
:clamp init;
|
59
|
+
|
60
|
+
#Greenyellow:**boot**|
|
61
|
+
|
62
|
+
:define installer options;
|
63
|
+
:pre-parse ARGV to finish installer configuration;
|
64
|
+
|
65
|
+
#Greenyellow:**init**|
|
66
|
+
|
67
|
+
:load defaults from puppet;
|
68
|
+
#Greenyellow:**pre_values**|
|
69
|
+
:load values from answer file;
|
70
|
+
:load values from previous answer file;
|
71
|
+
note right: if previous scenraio != current scenario
|
72
|
+
|
73
|
+
:update help with default values;
|
74
|
+
|execute|
|
75
|
+
:parse values from CLI arguments;
|
76
|
+
|
77
|
+
:init progress bar;
|
78
|
+
|
79
|
+
#LightBlue:**run system checks**>
|
80
|
+
#Greenyellow:**pre_validations**|
|
81
|
+
|
82
|
+
if (interactive?) then (yes)
|
83
|
+
:run wizard;
|
84
|
+
else
|
85
|
+
:run validations;
|
86
|
+
endif
|
87
|
+
|
88
|
+
#Greenyellow:**pre_commit**|
|
89
|
+
|
90
|
+
:save answers;
|
91
|
+
note right: unless noop or dont-save-answers
|
92
|
+
:save current scenario as the last used one;
|
93
|
+
note right: unless noop or dont-save-answers
|
94
|
+
|
95
|
+
#Greenyellow:**pre**|
|
96
|
+
|
97
|
+
:setup HieraConfigurer and save configs;
|
98
|
+
|
99
|
+
#Gold:run puppet;
|
100
|
+
repeat
|
101
|
+
:parse puppet output;
|
102
|
+
:update installer logs;
|
103
|
+
:update progress bar;
|
104
|
+
repeat while (puppet runs?)
|
105
|
+
|
106
|
+
#Greenyellow:**post**|
|
107
|
+
|
108
|
+
stop
|
109
|
+
@enduml
|
data/lib/kafo/configuration.rb
CHANGED
@@ -24,7 +24,6 @@ module Kafo
|
|
24
24
|
:answer_file => './config/answers.yaml',
|
25
25
|
:installer_dir => '.',
|
26
26
|
:module_dirs => ['./modules'],
|
27
|
-
:default_values_dir => '/tmp',
|
28
27
|
:colors => Kafo::ColorScheme.colors_possible?,
|
29
28
|
:color_of_background => :dark,
|
30
29
|
:hook_dirs => [],
|
@@ -52,9 +51,14 @@ module Kafo
|
|
52
51
|
|
53
52
|
def save_configuration(configuration)
|
54
53
|
return true unless @persist
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
begin
|
55
|
+
FileUtils.touch @config_file
|
56
|
+
File.chmod 0600, @config_file
|
57
|
+
File.open(@config_file, 'w') { |file| file.write(format(YAML.dump(configuration))) }
|
58
|
+
rescue Errno::EACCES
|
59
|
+
puts "Insufficient permissions to write to #{@config_file}, can not continue"
|
60
|
+
KafoConfigure.exit(:insufficient_permissions)
|
61
|
+
end
|
58
62
|
end
|
59
63
|
|
60
64
|
def configure_application
|
@@ -133,7 +137,7 @@ module Kafo
|
|
133
137
|
|
134
138
|
def migrate_configuration(from_config, options={})
|
135
139
|
keys_to_skip = options.fetch(:skip, [])
|
136
|
-
keys = [:log_dir, :log_name, :log_level, :no_prefix,
|
140
|
+
keys = [:log_dir, :log_name, :log_level, :no_prefix,
|
137
141
|
:colors, :color_of_background, :custom, :password, :verbose_log_level]
|
138
142
|
keys += options.fetch(:with, [])
|
139
143
|
keys.each do |key|
|
@@ -145,15 +149,19 @@ module Kafo
|
|
145
149
|
|
146
150
|
def params_default_values
|
147
151
|
@params_default_values ||= begin
|
148
|
-
@logger.debug "Creating tmp dir within #{app[:default_values_dir]}..."
|
149
|
-
temp_dir = Dir.mktmpdir(nil, app[:default_values_dir])
|
150
|
-
KafoConfigure.exit_handler.register_cleanup_path temp_dir
|
151
|
-
|
152
152
|
puppetconf = PuppetConfigurer.new('noop' => true)
|
153
153
|
KafoConfigure.exit_handler.register_cleanup_path puppetconf.config_path
|
154
154
|
|
155
|
+
dump_manifest = <<EOS
|
156
|
+
#{includes}
|
157
|
+
class { '::kafo_configure::dump_values':
|
158
|
+
lookups => [#{param_lookups_to_dump}],
|
159
|
+
variables => [#{params_to_dump}],
|
160
|
+
}
|
161
|
+
EOS
|
162
|
+
|
155
163
|
@logger.info 'Loading default values from puppet modules...'
|
156
|
-
command = PuppetCommand.new(
|
164
|
+
command = PuppetCommand.new(dump_manifest, [], puppetconf, self).append('2>&1').command
|
157
165
|
result = `#{command}`
|
158
166
|
@logger.debug result
|
159
167
|
unless $?.exitstatus == 0
|
@@ -165,7 +173,8 @@ module Kafo
|
|
165
173
|
KafoConfigure.exit(:defaults_error)
|
166
174
|
end
|
167
175
|
@logger.info "... finished"
|
168
|
-
|
176
|
+
|
177
|
+
load_yaml_from_output(result.split($/))
|
169
178
|
end
|
170
179
|
end
|
171
180
|
|
@@ -304,6 +313,10 @@ module Kafo
|
|
304
313
|
params.select(&:dump_default_needed?).map(&:dump_default).join(',')
|
305
314
|
end
|
306
315
|
|
316
|
+
def param_lookups_to_dump
|
317
|
+
params.select { |p| p.manifest_default.nil? }.map { |p| %{"#{p.identifier}"} }.join(',')
|
318
|
+
end
|
319
|
+
|
307
320
|
def format(data)
|
308
321
|
data.gsub('!ruby/sym ', ':')
|
309
322
|
end
|
@@ -312,6 +325,18 @@ module Kafo
|
|
312
325
|
YAML.load_file(filename)
|
313
326
|
end
|
314
327
|
|
328
|
+
# Loads YAML from mixed output, finding the "---" and "..." document start/end delimiters
|
329
|
+
def load_yaml_from_output(lines)
|
330
|
+
start = lines.find_index { |l| l.start_with?('---') }
|
331
|
+
last = lines[start..-1].find_index("...")
|
332
|
+
if start.nil? || last.nil?
|
333
|
+
puts "Could not find default values in output"
|
334
|
+
@logger.error 'Could not find default values in Puppet output, cannot continue'
|
335
|
+
KafoConfigure.exit(:defaults_error)
|
336
|
+
end
|
337
|
+
YAML.load(lines[start,last].join($/))
|
338
|
+
end
|
339
|
+
|
315
340
|
def register_data_types
|
316
341
|
module_dirs.each do |module_dir|
|
317
342
|
Dir[File.join(module_dir, '*', 'types', '**', '*.pp')].each do |type_file|
|
data/lib/kafo/exit_handler.rb
CHANGED
data/lib/kafo/kafo_configure.rb
CHANGED
@@ -113,6 +113,14 @@ module Kafo
|
|
113
113
|
self.class.logger
|
114
114
|
end
|
115
115
|
|
116
|
+
def run(*args)
|
117
|
+
started_at = Time.now
|
118
|
+
logger.info("Running installer with args #{args.inspect}")
|
119
|
+
super
|
120
|
+
ensure
|
121
|
+
logger.info("Installer finished in #{Time.now - started_at} seconds")
|
122
|
+
end
|
123
|
+
|
116
124
|
def execute
|
117
125
|
parse_cli_arguments
|
118
126
|
|
@@ -306,8 +314,8 @@ module Kafo
|
|
306
314
|
self.class.app_option ['-S', '--scenario'], 'SCENARIO', 'Use installation scenario'
|
307
315
|
self.class.app_option ['--disable-scenario'], 'SCENARIO', 'Disable installation scenario'
|
308
316
|
self.class.app_option ['--enable-scenario'], 'SCENARIO', 'Enable installation scenario'
|
309
|
-
self.class.app_option ['--list-scenarios'], :flag, 'List available installation
|
310
|
-
self.class.app_option ['--force'], :flag, 'Force change of installation
|
317
|
+
self.class.app_option ['--list-scenarios'], :flag, 'List available installation scenarios'
|
318
|
+
self.class.app_option ['--force'], :flag, 'Force change of installation scenario'
|
311
319
|
self.class.app_option ['--compare-scenarios'], :flag, 'Show changes between last used scenario and the scenario specified with -S or --scenario argument'
|
312
320
|
self.class.app_option ['--migrations-only'], :flag, 'Apply migrations to a selected scenario and exit'
|
313
321
|
self.class.app_option ['--[no-]parser-cache'], :flag, 'Force use or bypass of Puppet module parser cache'
|
@@ -425,7 +433,7 @@ module Kafo
|
|
425
433
|
'hiera_config' => hiera.config_path,
|
426
434
|
'noop' => !!noop?,
|
427
435
|
'profile' => !!profile?,
|
428
|
-
'show_diff' =>
|
436
|
+
'show_diff' => true
|
429
437
|
)
|
430
438
|
self.class.exit_handler.register_cleanup_path(puppetconf.config_path)
|
431
439
|
|
data/lib/kafo/param.rb
CHANGED
@@ -17,6 +17,10 @@ module Kafo
|
|
17
17
|
@type = DataType.new_from_string(type)
|
18
18
|
end
|
19
19
|
|
20
|
+
def identifier
|
21
|
+
@module ? "#{@module.identifier}::#{name}" : name
|
22
|
+
end
|
23
|
+
|
20
24
|
def groups
|
21
25
|
@groups || []
|
22
26
|
end
|
@@ -37,10 +41,10 @@ module Kafo
|
|
37
41
|
@value = nil
|
38
42
|
end
|
39
43
|
|
40
|
-
# For literal default values, only use 'manifest_default'. For variable values
|
41
|
-
# loaded back from the dump in 'default'.
|
44
|
+
# For literal default values, only use 'manifest_default'. For variable or values from a data
|
45
|
+
# lookup, use the value loaded back from the dump in 'default'.
|
42
46
|
def default
|
43
|
-
@type.typecast(dump_default_needed? ? @default : manifest_default)
|
47
|
+
@type.typecast(dump_default_needed? || !@default.nil? ? @default : manifest_default)
|
44
48
|
end
|
45
49
|
|
46
50
|
def default=(default)
|
@@ -89,6 +93,8 @@ module Kafo
|
|
89
93
|
# be used. On calling #value, the default will be returned if no overriding value is set.
|
90
94
|
if dump_default_needed? && defaults.has_key?(manifest_default_params_variable)
|
91
95
|
self.default = defaults[manifest_default_params_variable]
|
96
|
+
elsif defaults.has_key?(identifier)
|
97
|
+
self.default = defaults[identifier]
|
92
98
|
end
|
93
99
|
end
|
94
100
|
|
data/lib/kafo/version.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Find values via data lookups for class parameters
|
2
|
+
#
|
3
|
+
# Wraps the lookup() function for data lookups of class parameters without
|
4
|
+
# inline defaults.
|
5
|
+
#
|
6
|
+
Puppet::Functions.create_function(:dump_lookups) do
|
7
|
+
dispatch :dump_lookups do
|
8
|
+
param 'Array[String]', :parameters
|
9
|
+
end
|
10
|
+
|
11
|
+
def dump_lookups(parameters)
|
12
|
+
Hash[parameters.map { |param| [param, call_function('lookup', [param], 'default_value' => nil)] }]
|
13
|
+
end
|
14
|
+
end
|
@@ -1,18 +1,13 @@
|
|
1
1
|
# Find default values for variables specified as args
|
2
2
|
#
|
3
3
|
module Puppet::Parser::Functions
|
4
|
-
newfunction(:dump_values) do |args|
|
4
|
+
newfunction(:dump_values, :type => :rvalue) do |args|
|
5
5
|
options = []
|
6
6
|
options<< false if Puppet::PUPPETVERSION.start_with?('2.6')
|
7
|
-
data = args.map do |arg|
|
7
|
+
data = args.flatten.map do |arg|
|
8
8
|
found_value = lookupvar(arg, *options)
|
9
9
|
[arg, found_value]
|
10
10
|
end
|
11
|
-
|
12
|
-
|
13
|
-
dump_dir = lookupvar('temp_dir')
|
14
|
-
file_name = "#{dump_dir}/default_values.yaml"
|
15
|
-
|
16
|
-
File.open(file_name, File::WRONLY|File::CREAT|File::EXCL, 0600) { |file| file.write(YAML.dump(data)) }
|
11
|
+
Hash[data]
|
17
12
|
end
|
18
13
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Returns the given argument as a string containing YAML, with an end of
|
2
|
+
# document marker.
|
3
|
+
#
|
4
|
+
module Puppet::Parser::Functions
|
5
|
+
newfunction(:to_yaml, :type => :rvalue) do |args|
|
6
|
+
dump = if args.all? { |a| a.is_a?(Hash) }
|
7
|
+
args.inject({}) { |m,a| m.merge(a) }
|
8
|
+
else
|
9
|
+
args.first
|
10
|
+
end
|
11
|
+
YAML.dump(dump) + "\n...\n"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Outputs a YAML hash of variable to its value, for:
|
2
|
+
# - variables: a list of variables from params classes that have
|
3
|
+
# already been included
|
4
|
+
# - lookups: a list of variables to find through lookup()
|
5
|
+
#
|
6
|
+
# The result will be merged together into one hash.
|
7
|
+
class kafo_configure::dump_values($variables, $lookups) {
|
8
|
+
$dumped_vars = dump_values($variables)
|
9
|
+
|
10
|
+
# Data lookups are only supported on Puppet 4 or higher, however depend on
|
11
|
+
# 4.5.0 which fixes PUP-6230 where missing data correctly returns the
|
12
|
+
# default/undef instead of an empty hash.
|
13
|
+
if versioncmp($::puppetversion, '4.5') >= 0 {
|
14
|
+
$dumped_lookups = dump_lookups($lookups)
|
15
|
+
$dumped = to_yaml($dumped_vars, $dumped_lookups)
|
16
|
+
} else {
|
17
|
+
$dumped = to_yaml($dumped_vars)
|
18
|
+
}
|
19
|
+
|
20
|
+
notice("\n${dumped}")
|
21
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kafo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marek Hulan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -194,14 +194,13 @@ executables:
|
|
194
194
|
extensions: []
|
195
195
|
extra_rdoc_files: []
|
196
196
|
files:
|
197
|
-
- LICENSE.txt
|
198
|
-
- README.md
|
199
|
-
- Rakefile
|
200
197
|
- bin/kafo-configure
|
201
198
|
- bin/kafo-export-params
|
202
199
|
- bin/kafofy
|
203
200
|
- config/config_header.txt
|
204
201
|
- config/kafo.yaml.example
|
202
|
+
- doc/kafo_run.png
|
203
|
+
- doc/kafo_run.uml
|
205
204
|
- lib/kafo.rb
|
206
205
|
- lib/kafo/color_scheme.rb
|
207
206
|
- lib/kafo/condition.rb
|
@@ -262,10 +261,13 @@ files:
|
|
262
261
|
- lib/kafo/validator.rb
|
263
262
|
- lib/kafo/version.rb
|
264
263
|
- lib/kafo/wizard.rb
|
264
|
+
- modules/kafo_configure/lib/puppet/functions/dump_lookups.rb
|
265
265
|
- modules/kafo_configure/lib/puppet/parser/functions/add_progress.rb
|
266
266
|
- modules/kafo_configure/lib/puppet/parser/functions/decrypt.rb
|
267
267
|
- modules/kafo_configure/lib/puppet/parser/functions/dump_values.rb
|
268
268
|
- modules/kafo_configure/lib/puppet/parser/functions/load_kafo_password.rb
|
269
|
+
- modules/kafo_configure/lib/puppet/parser/functions/to_yaml.rb
|
270
|
+
- modules/kafo_configure/manifests/dump_values.pp
|
269
271
|
- modules/kafo_configure/manifests/init.pp
|
270
272
|
homepage: https://github.com/theforeman/kafo
|
271
273
|
licenses:
|
data/LICENSE.txt
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
This program and entire repository is free software: you can redistribute it
|
2
|
-
and/or modify it under the terms of the GNU General Public License as
|
3
|
-
published by the Free Software Foundation, either version 3 of the License,
|
4
|
-
or any later version.
|
5
|
-
|
6
|
-
This program is distributed in the hope that it will be useful, but WITHOUT
|
7
|
-
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
8
|
-
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
9
|
-
|
10
|
-
You should have received a copy of the GNU General Public License along with
|
11
|
-
this program. If not, see http://www.gnu.org/licenses/.
|