kafo 6.1.1 → 6.4.0
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/README.md +26 -0
- data/Rakefile +8 -1
- data/lib/kafo/app_option/declaration.rb +0 -2
- data/lib/kafo/app_option/definition.rb +0 -2
- data/lib/kafo/color_scheme.rb +2 -2
- data/lib/kafo/configuration.rb +37 -36
- data/lib/kafo/data_types/integer.rb +3 -1
- data/lib/kafo/data_types/numeric.rb +3 -1
- data/lib/kafo/exceptions.rb +0 -3
- data/lib/kafo/hook_context.rb +2 -2
- data/lib/kafo/hooking.rb +18 -3
- data/lib/kafo/kafo_configure.rb +39 -15
- data/lib/kafo/multi_stage_hook.rb +13 -0
- data/lib/kafo/param.rb +3 -3
- data/lib/kafo/progress_bar.rb +13 -1
- data/lib/kafo/puppet_module.rb +8 -7
- data/lib/kafo/scenario_manager.rb +5 -4
- data/lib/kafo/scenario_option.rb +92 -0
- data/lib/kafo/store.rb +1 -1
- data/lib/kafo/string_helper.rb +1 -1
- data/lib/kafo/version.rb +1 -1
- data/lib/kafo/wizard.rb +25 -15
- data/modules/kafo_configure/metadata.json +1 -1
- metadata +7 -6
- data/modules/kafo_configure/spec/fixtures/manifests/site.pp +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4298932fae581df1967c430be034c621ed435954ac95acf7cf7b23c9b7692d40
|
|
4
|
+
data.tar.gz: 8ce698b286d5ec94c19adfcfc23e541c8b0599cb1399e689ee00b4413668552c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 769146a010f1007993961a0075a03b1cbf9c4055a59bd8259940379662eaa36003ad5a83b746452e8dd0b35ea47640eb1a3064516a7a776d6e8030c6403321a1
|
|
7
|
+
data.tar.gz: dd05194e14a17c54a205b5eacc35677b78fe4f036b8ab851972a8301c59b1e327555dd065772d82476a190d878d50226ed0253afe1c5dc129496ee316555bac3
|
data/README.md
CHANGED
|
@@ -816,6 +816,32 @@ if app_value(:reset_foreman_db) && !app_value(:noop)
|
|
|
816
816
|
end
|
|
817
817
|
```
|
|
818
818
|
|
|
819
|
+
Hooks can additionally be defined by combining all related stages into a single file
|
|
820
|
+
known as a Multi-stage hook. Multi-stage hooks live in a special directory inside
|
|
821
|
+
the hooks directory: ```$installer_dir/hooks/multi```. Taking the previous example:
|
|
822
|
+
|
|
823
|
+
```ruby
|
|
824
|
+
# hooks/multi/10-reset_option_feature.rb
|
|
825
|
+
boot do
|
|
826
|
+
app_option '--reset-foreman-db', :flag, 'Drop foreman database first? You will lose all data!', :default => false
|
|
827
|
+
end
|
|
828
|
+
|
|
829
|
+
pre do
|
|
830
|
+
if app_value(:reset_foreman_db) && !app_value(:noop)
|
|
831
|
+
`which foreman-rake > /dev/null 2>&1`
|
|
832
|
+
if $?.success?
|
|
833
|
+
logger.info 'Dropping database!'
|
|
834
|
+
output = `foreman-rake db:drop 2>&1`
|
|
835
|
+
logger.debug output.to_s
|
|
836
|
+
unless $?.success?
|
|
837
|
+
logger.warn "Unable to drop DB, ignoring since it's not fatal, output was: '#{output}''"
|
|
838
|
+
end
|
|
839
|
+
else
|
|
840
|
+
logger.warn 'Foreman not installed yet, can not drop database!'
|
|
841
|
+
end
|
|
842
|
+
end
|
|
843
|
+
end
|
|
844
|
+
```
|
|
819
845
|
|
|
820
846
|
If you want to add more directories to be search you can use the "hook_dirs" option
|
|
821
847
|
in the installer configuration file.
|
data/Rakefile
CHANGED
|
@@ -4,7 +4,7 @@ load 'tasks/jenkins.rake'
|
|
|
4
4
|
|
|
5
5
|
Rake::TestTask.new('test:ruby') do |t|
|
|
6
6
|
t.libs << 'lib' << 'test'
|
|
7
|
-
t.test_files = FileList['test/**/*_test.rb']
|
|
7
|
+
t.test_files = FileList['test/**/*_test.rb'] - FileList['test/tmp/**/*_test.rb']
|
|
8
8
|
t.verbose = true
|
|
9
9
|
end
|
|
10
10
|
|
|
@@ -31,6 +31,13 @@ namespace 'test' do
|
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
begin
|
|
35
|
+
require 'rubocop/rake_task'
|
|
36
|
+
RuboCop::RakeTask.new
|
|
37
|
+
rescue LoadError
|
|
38
|
+
puts 'Rubocop not loaded'
|
|
39
|
+
end
|
|
40
|
+
|
|
34
41
|
CLEAN.include 'test/tmp'
|
|
35
42
|
|
|
36
43
|
task :test => ['test:ruby', 'test:puppet_modules']
|
|
@@ -3,7 +3,6 @@ require_relative 'definition'
|
|
|
3
3
|
module Kafo
|
|
4
4
|
module AppOption
|
|
5
5
|
module Declaration
|
|
6
|
-
|
|
7
6
|
include Clamp::Option::Declaration
|
|
8
7
|
|
|
9
8
|
def app_option(switches, type, description, opts = {}, &block)
|
|
@@ -13,7 +12,6 @@ module Kafo
|
|
|
13
12
|
declared_options << option
|
|
14
13
|
end
|
|
15
14
|
end
|
|
16
|
-
|
|
17
15
|
end
|
|
18
16
|
end
|
|
19
17
|
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
module Kafo
|
|
2
2
|
module AppOption
|
|
3
3
|
class Definition < Clamp::Option::Definition
|
|
4
|
-
|
|
5
4
|
def initialize(switches, type, description, options = {})
|
|
6
5
|
@advanced = options.fetch(:advanced, false)
|
|
7
6
|
super(switches, type, description, options)
|
|
@@ -10,7 +9,6 @@ module Kafo
|
|
|
10
9
|
def advanced?
|
|
11
10
|
@advanced
|
|
12
11
|
end
|
|
13
|
-
|
|
14
12
|
end
|
|
15
13
|
end
|
|
16
14
|
end
|
data/lib/kafo/color_scheme.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require 'highline
|
|
1
|
+
require 'highline'
|
|
2
2
|
|
|
3
3
|
module Kafo
|
|
4
4
|
class ColorScheme
|
|
@@ -7,7 +7,7 @@ module Kafo
|
|
|
7
7
|
::ENV['TERM'] && !`which tput 2> /dev/null`.empty? && `tput colors`.to_i > 0
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def initialize(options={})
|
|
10
|
+
def initialize(options = {})
|
|
11
11
|
@background = options[:background].nil? ? :dark : options[:background]
|
|
12
12
|
@colors = options[:colors].nil? ? self.class.colors_possible? : options[:colors]
|
|
13
13
|
end
|
data/lib/kafo/configuration.rb
CHANGED
|
@@ -5,43 +5,44 @@ require 'kafo/puppet_module'
|
|
|
5
5
|
require 'kafo/color_scheme'
|
|
6
6
|
require 'kafo/data_type_parser'
|
|
7
7
|
require 'kafo/execution_environment'
|
|
8
|
+
require 'kafo/scenario_option'
|
|
8
9
|
|
|
9
10
|
module Kafo
|
|
10
11
|
class Configuration
|
|
11
12
|
attr_reader :config_file, :answer_file, :scenario_id
|
|
12
13
|
|
|
13
14
|
DEFAULT = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
15
|
+
ScenarioOption::NAME => '',
|
|
16
|
+
ScenarioOption::DESCRIPTION => '',
|
|
17
|
+
ScenarioOption::ENABLED => true,
|
|
18
|
+
ScenarioOption::LOG_DIR => '/var/log/kafo',
|
|
19
|
+
ScenarioOption::LOG_OWNER => nil,
|
|
20
|
+
ScenarioOption::LOG_GROUP => nil,
|
|
21
|
+
ScenarioOption::STORE_DIR => '',
|
|
22
|
+
ScenarioOption::LOG_NAME => 'configuration.log',
|
|
23
|
+
ScenarioOption::LOG_LEVEL => 'notice',
|
|
24
|
+
ScenarioOption::NO_PREFIX => false,
|
|
25
|
+
ScenarioOption::MAPPING => {},
|
|
26
|
+
ScenarioOption::ANSWER_FILE => './config/answers.yaml',
|
|
27
|
+
ScenarioOption::INSTALLER_DIR => '.',
|
|
28
|
+
ScenarioOption::MODULE_DIRS => ['./modules'],
|
|
29
|
+
ScenarioOption::COLORS => Kafo::ColorScheme.colors_possible?,
|
|
30
|
+
ScenarioOption::COLOR_OF_BACKGROUND => :dark,
|
|
31
|
+
ScenarioOption::HOOK_DIRS => [],
|
|
32
|
+
ScenarioOption::CHECK_DIRS => nil,
|
|
33
|
+
ScenarioOption::CUSTOM => {},
|
|
34
|
+
ScenarioOption::FACTS => {},
|
|
35
|
+
ScenarioOption::LOW_PRIORITY_MODULES => [],
|
|
36
|
+
ScenarioOption::VERBOSE => false,
|
|
37
|
+
ScenarioOption::VERBOSE_LOG_LEVEL => 'notice',
|
|
38
|
+
ScenarioOption::SKIP_PUPPET_VERSION_CHECK => false,
|
|
39
|
+
ScenarioOption::PARSER_CACHE_PATH => nil,
|
|
40
|
+
ScenarioOption::IGNORE_UNDOCUMENTED => nil,
|
|
41
|
+
ScenarioOption::ORDER => nil,
|
|
42
|
+
ScenarioOption::HIERA_CONFIG => nil,
|
|
43
|
+
ScenarioOption::KAFO_MODULES_DIR => nil,
|
|
44
|
+
ScenarioOption::CONFIG_HEADER_FILE => nil,
|
|
45
|
+
ScenarioOption::DONT_SAVE_ANSWERS => nil,
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
def self.get_scenario_id(filename)
|
|
@@ -129,7 +130,7 @@ module Kafo
|
|
|
129
130
|
def modules
|
|
130
131
|
@modules ||= begin
|
|
131
132
|
register_data_types
|
|
132
|
-
@data.keys.map { |mod| PuppetModule.new(mod,
|
|
133
|
+
@data.keys.map { |mod| PuppetModule.new(mod, configuration: self).parse }.sort
|
|
133
134
|
end
|
|
134
135
|
end
|
|
135
136
|
|
|
@@ -158,7 +159,7 @@ module Kafo
|
|
|
158
159
|
end
|
|
159
160
|
|
|
160
161
|
def add_module(name)
|
|
161
|
-
mod = PuppetModule.new(name,
|
|
162
|
+
mod = PuppetModule.new(name, configuration: self).parse
|
|
162
163
|
unless modules.map(&:name).include?(mod.name)
|
|
163
164
|
mod.enable
|
|
164
165
|
@modules << mod
|
|
@@ -170,7 +171,7 @@ module Kafo
|
|
|
170
171
|
save_configuration(app)
|
|
171
172
|
end
|
|
172
173
|
|
|
173
|
-
def migrate_configuration(from_config, options={})
|
|
174
|
+
def migrate_configuration(from_config, options = {})
|
|
174
175
|
keys_to_skip = options.fetch(:skip, [])
|
|
175
176
|
keys = [:log_dir, :log_name, :log_level, :no_prefix,
|
|
176
177
|
:colors, :color_of_background, :custom, :verbose_log_level]
|
|
@@ -197,7 +198,7 @@ module Kafo
|
|
|
197
198
|
}
|
|
198
199
|
EOS
|
|
199
200
|
|
|
200
|
-
@logger.
|
|
201
|
+
@logger.info "Loading default values from puppet modules..."
|
|
201
202
|
command = PuppetCommand.new(dump_manifest, [], puppetconf, self).command
|
|
202
203
|
stdout, stderr, status = Open3.capture3(*PuppetCommand.format_command(command))
|
|
203
204
|
|
|
@@ -222,7 +223,7 @@ EOS
|
|
|
222
223
|
end
|
|
223
224
|
end
|
|
224
225
|
|
|
225
|
-
@logger.
|
|
226
|
+
@logger.info "... finished loading default values from puppet modules."
|
|
226
227
|
|
|
227
228
|
load_yaml_from_output(stdout.split($/))
|
|
228
229
|
end
|
data/lib/kafo/exceptions.rb
CHANGED
data/lib/kafo/hook_context.rb
CHANGED
|
@@ -34,8 +34,8 @@ module Kafo
|
|
|
34
34
|
#
|
|
35
35
|
# @example
|
|
36
36
|
# app_option ['-n', '--noop'], :flag, 'Run puppet in noop mode?', :default => false
|
|
37
|
-
def app_option(*args)
|
|
38
|
-
self.kafo.class.app_option(*args)
|
|
37
|
+
def app_option(*args, &block)
|
|
38
|
+
self.kafo.class.app_option(*args, &block)
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
# Returns whether the given app option exists. This is useful when there's a conditional option that is
|
data/lib/kafo/hooking.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'kafo/hook_context'
|
|
2
|
+
require 'kafo/multi_stage_hook'
|
|
2
3
|
|
|
3
4
|
module Kafo
|
|
4
5
|
class Hooking
|
|
@@ -36,6 +37,14 @@ module Kafo
|
|
|
36
37
|
register(hook_type, file, &hook_block)
|
|
37
38
|
end
|
|
38
39
|
end
|
|
40
|
+
|
|
41
|
+
# Multi stage hooks are special
|
|
42
|
+
Dir.glob(File.join(base_dir, 'multi', '*.rb')).sort.each do |file|
|
|
43
|
+
logger.debug "Loading multi stage hook #{file}"
|
|
44
|
+
hook = File.read(file)
|
|
45
|
+
MultiStageHook.new(file, self, TYPES).instance_eval(hook, file, 1)
|
|
46
|
+
end
|
|
47
|
+
|
|
39
48
|
@loaded = true
|
|
40
49
|
end
|
|
41
50
|
self
|
|
@@ -47,13 +56,19 @@ module Kafo
|
|
|
47
56
|
|
|
48
57
|
def execute(group, log_stage: true)
|
|
49
58
|
logger = Logger.new(group)
|
|
50
|
-
logger.
|
|
51
|
-
|
|
59
|
+
logger.info "Executing hooks in group #{group}" if log_stage
|
|
60
|
+
|
|
61
|
+
sorted_hooks = self.hooks[group].keys.sort do |a, b|
|
|
62
|
+
File.basename(a.to_s) <=> File.basename(b.to_s)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
sorted_hooks.each do |name|
|
|
52
66
|
hook = self.hooks[group][name]
|
|
53
67
|
result = HookContext.execute(self.kafo, logger, &hook)
|
|
54
68
|
logger.debug "Hook #{name} returned #{result.inspect}"
|
|
55
69
|
end
|
|
56
|
-
|
|
70
|
+
|
|
71
|
+
logger.info "All hooks in group #{group} finished" if log_stage
|
|
57
72
|
@group = nil
|
|
58
73
|
end
|
|
59
74
|
|
data/lib/kafo/kafo_configure.rb
CHANGED
|
@@ -143,7 +143,14 @@ module Kafo
|
|
|
143
143
|
# so we limit parsing only to app config options (because of --help and later defined params)
|
|
144
144
|
parse clamp_app_arguments
|
|
145
145
|
parse_app_arguments # set values from ARGS to config.app
|
|
146
|
-
|
|
146
|
+
|
|
147
|
+
if ARGV.any? { |option| ['--help', '--full-help'].include? option }
|
|
148
|
+
Logging.setup_verbose(level: :error)
|
|
149
|
+
else
|
|
150
|
+
Logging.setup(verbose: config.app[:verbose])
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
logger.notice("Loading installer configuration. This will take some time.")
|
|
147
154
|
self.class.set_color_scheme
|
|
148
155
|
|
|
149
156
|
self.class.hooking.execute(:init)
|
|
@@ -166,6 +173,10 @@ module Kafo
|
|
|
166
173
|
def run(*args)
|
|
167
174
|
started_at = Time.now
|
|
168
175
|
logger.debug("Running installer with args #{args.inspect}")
|
|
176
|
+
if config.app[:verbose]
|
|
177
|
+
logger.notice("Running installer with log based terminal output at level #{config.app[:verbose_log_level].upcase}.")
|
|
178
|
+
logger.notice("Use -l to set the terminal output log level to ERROR, WARN, NOTICE, INFO, or DEBUG. See --full-help for definitions.")
|
|
179
|
+
end
|
|
169
180
|
super
|
|
170
181
|
ensure
|
|
171
182
|
logger.debug("Installer finished in #{Time.now - started_at} seconds")
|
|
@@ -311,6 +322,25 @@ module Kafo
|
|
|
311
322
|
self.class.app_option(*args, &block)
|
|
312
323
|
end
|
|
313
324
|
|
|
325
|
+
def terminal_log_levels_message
|
|
326
|
+
if ARGV.include?('--full-help')
|
|
327
|
+
<<~HEREDOC.chomp
|
|
328
|
+
Log level for log based terminal output.
|
|
329
|
+
The available levels are
|
|
330
|
+
ERROR - Only show errors which prevented the installer from completing successfully.
|
|
331
|
+
WARN - Deprecation warnings and other information users may want to be aware of.
|
|
332
|
+
NOTICE - High level information about installer execution and progress.
|
|
333
|
+
INFO - More detailed information about execution and progress. Also shows when the installer makes a change to system configuration.
|
|
334
|
+
DEBUG - Show all information about execution, including configuration items where no change was needed.
|
|
335
|
+
HEREDOC
|
|
336
|
+
else
|
|
337
|
+
<<~HEREDOC.chomp
|
|
338
|
+
Log level for log based terminal output.
|
|
339
|
+
The available levels are ERROR, WARN, NOTICE, INFO, DEBUG. See --full-help for definitions.
|
|
340
|
+
HEREDOC
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
|
|
314
344
|
def set_app_options
|
|
315
345
|
app_option ['--[no-]colors'], :flag, 'Use color output on STDOUT',
|
|
316
346
|
:default => config.app[:colors], :advanced => true
|
|
@@ -333,7 +363,7 @@ module Kafo
|
|
|
333
363
|
:default => false, :advanced => true
|
|
334
364
|
app_option ['-v', '--[no-]verbose'], :flag, 'Display log on STDOUT instead of progressbar',
|
|
335
365
|
:default => config.app[:verbose]
|
|
336
|
-
app_option ['-l', '--verbose-log-level'], 'LEVEL',
|
|
366
|
+
app_option ['-l', '--verbose-log-level'], 'LEVEL', terminal_log_levels_message,
|
|
337
367
|
:default => 'notice'
|
|
338
368
|
app_option ['-S', '--scenario'], 'SCENARIO', 'Use installation scenario'
|
|
339
369
|
app_option ['--disable-scenario'], 'SCENARIO', 'Disable installation scenario',
|
|
@@ -365,9 +395,9 @@ module Kafo
|
|
|
365
395
|
params.sort.each do |param|
|
|
366
396
|
doc = param.doc.nil? ? 'UNDOCUMENTED' : param.doc.join("\n")
|
|
367
397
|
app_option parametrize(param), '', doc + " (current: #{param.value_to_s})",
|
|
368
|
-
|
|
398
|
+
:multivalued => param.multivalued?
|
|
369
399
|
app_option parametrize(param, 'reset-'), :flag,
|
|
370
|
-
|
|
400
|
+
"Reset #{param.name} to the default value (#{param.default_to_s})"
|
|
371
401
|
end
|
|
372
402
|
end
|
|
373
403
|
|
|
@@ -440,7 +470,7 @@ module Kafo
|
|
|
440
470
|
end
|
|
441
471
|
|
|
442
472
|
def validate_all(logging = true)
|
|
443
|
-
logger.
|
|
473
|
+
logger.info "Running validation checks."
|
|
444
474
|
results = enabled_params.map do |param|
|
|
445
475
|
result = param.valid?
|
|
446
476
|
errors = param.validation_errors.join(', ')
|
|
@@ -477,13 +507,7 @@ module Kafo
|
|
|
477
507
|
log_parser = PuppetLogParser.new
|
|
478
508
|
logger = Logger.new('configure')
|
|
479
509
|
|
|
480
|
-
|
|
481
|
-
Starting system configuration.
|
|
482
|
-
The total number of configuration tasks may increase during the run.
|
|
483
|
-
Observe logs or specify --verbose-log-level to see individual configuration tasks.
|
|
484
|
-
HEREDOC
|
|
485
|
-
|
|
486
|
-
logger.notice(start_message.chomp)
|
|
510
|
+
logger.notice("Starting system configuration.")
|
|
487
511
|
|
|
488
512
|
PTY.spawn(*PuppetCommand.format_command(command)) do |stdin, stdout, pid|
|
|
489
513
|
begin
|
|
@@ -492,9 +516,9 @@ HEREDOC
|
|
|
492
516
|
method, message = log_parser.parse(line)
|
|
493
517
|
progress_log(method, message, logger)
|
|
494
518
|
|
|
495
|
-
if (output = line.match(
|
|
496
|
-
if (output[:count].to_i %
|
|
497
|
-
logger.notice("#{output[:count].to_i - 1} out of #{output[:total]}
|
|
519
|
+
if (output = line.match(/(.+\]): Starting to evaluate the resource( \((?<count>\d+) of (?<total>\d+)\))?/))
|
|
520
|
+
if (output[:count].to_i % 250) == 1 && output[:count].to_i != 1
|
|
521
|
+
logger.notice("#{output[:count].to_i - 1} configuration steps out of #{output[:total]} steps complete.")
|
|
498
522
|
end
|
|
499
523
|
end
|
|
500
524
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Kafo
|
|
2
|
+
class MultiStageHook
|
|
3
|
+
def initialize(name, registry, types)
|
|
4
|
+
default_name = name
|
|
5
|
+
|
|
6
|
+
types.each do |hook_type|
|
|
7
|
+
self.class.send(:define_method, hook_type) do |name=nil, &block|
|
|
8
|
+
registry.send(:register, hook_type, name || default_name, &block)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
data/lib/kafo/param.rb
CHANGED
|
@@ -123,12 +123,12 @@ module Kafo
|
|
|
123
123
|
@type.multivalued?
|
|
124
124
|
end
|
|
125
125
|
|
|
126
|
-
def <=>
|
|
126
|
+
def <=>(other)
|
|
127
127
|
unless @module.configuration.app[:no_prefix]
|
|
128
|
-
r = self.module_name <=>
|
|
128
|
+
r = self.module_name <=> other.module_name
|
|
129
129
|
return r unless r == 0
|
|
130
130
|
end
|
|
131
|
-
self.name <=>
|
|
131
|
+
self.name <=> other.name
|
|
132
132
|
end
|
|
133
133
|
|
|
134
134
|
def visible?(context = [])
|
data/lib/kafo/progress_bar.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
|
+
require 'highline'
|
|
2
3
|
require 'powerbar'
|
|
3
4
|
require 'ansi/code'
|
|
4
5
|
require 'set'
|
|
@@ -20,7 +21,7 @@ module Kafo
|
|
|
20
21
|
@all_lines = 0
|
|
21
22
|
@total = :unknown
|
|
22
23
|
@resources = Set.new
|
|
23
|
-
@term_width =
|
|
24
|
+
@term_width = terminal_width
|
|
24
25
|
@bar = PowerBar.new
|
|
25
26
|
@bar.settings.tty.infinite.template.main = infinite_template
|
|
26
27
|
@bar.settings.tty.finite.template.main = finite_template
|
|
@@ -85,6 +86,17 @@ module Kafo
|
|
|
85
86
|
|
|
86
87
|
private
|
|
87
88
|
|
|
89
|
+
def terminal_width
|
|
90
|
+
# HighLine 2 has Terminal, 1 has SystemExtensions
|
|
91
|
+
terminal_size = if HighLine.respond_to?(:default_instance)
|
|
92
|
+
HighLine.default_instance.terminal.terminal_size
|
|
93
|
+
else
|
|
94
|
+
HighLine::SystemExtensions.terminal_size
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
terminal_size ? (terminal_size[0] || 0) : 0
|
|
98
|
+
end
|
|
99
|
+
|
|
88
100
|
def done_message
|
|
89
101
|
text = 'Done'
|
|
90
102
|
text + (' ' * (50 - text.length))
|
data/lib/kafo/puppet_module.rb
CHANGED
|
@@ -25,7 +25,7 @@ module Kafo
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
def initialize(identifier, parser
|
|
28
|
+
def initialize(identifier, parser: nil, configuration: KafoConfigure.config)
|
|
29
29
|
@identifier = identifier
|
|
30
30
|
@configuration = configuration
|
|
31
31
|
@name = get_name
|
|
@@ -65,6 +65,7 @@ module Kafo
|
|
|
65
65
|
def parse(builder_klass = ParamBuilder)
|
|
66
66
|
@raw_data = @parser_cache.get(identifier, manifest_path) if @parser_cache
|
|
67
67
|
if @raw_data.nil?
|
|
68
|
+
@parser = self.class.find_parser if @parser.nil?
|
|
68
69
|
if @parser.nil? || @parser == :none
|
|
69
70
|
raise ParserError.new("No Puppet module parser is installed and no cache of the file #{manifest_path} is available. Please check debug logs and install optional dependencies for the parser.")
|
|
70
71
|
else
|
|
@@ -96,16 +97,16 @@ module Kafo
|
|
|
96
97
|
Hash[params.map { |param| [param.name, param.value] }]
|
|
97
98
|
end
|
|
98
99
|
|
|
99
|
-
def <=>
|
|
100
|
+
def <=>(other)
|
|
100
101
|
@configuration.app[:low_priority_modules].each do |module_name|
|
|
101
|
-
return 1 if self.name.include?(module_name) && !
|
|
102
|
-
return -1 if !self.name.include?(module_name) &&
|
|
103
|
-
if self.name.include?(module_name) &&
|
|
104
|
-
return self.name.sub(/.*#{module_name}/, '') <=>
|
|
102
|
+
return 1 if self.name.include?(module_name) && !other.name.include?(module_name)
|
|
103
|
+
return -1 if !self.name.include?(module_name) && other.name.include?(module_name)
|
|
104
|
+
if self.name.include?(module_name) && other.name.include?(module_name)
|
|
105
|
+
return self.name.sub(/.*#{module_name}/, '') <=> other.name.sub(/.*#{module_name}/, '')
|
|
105
106
|
end
|
|
106
107
|
end
|
|
107
108
|
|
|
108
|
-
self.name <=>
|
|
109
|
+
self.name <=> other.name
|
|
109
110
|
end
|
|
110
111
|
|
|
111
112
|
private
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
|
+
require 'highline/import'
|
|
2
3
|
require 'kafo_wizards'
|
|
3
4
|
require 'pathname'
|
|
4
5
|
|
|
@@ -6,7 +7,7 @@ module Kafo
|
|
|
6
7
|
class ScenarioManager
|
|
7
8
|
attr_reader :config_dir, :last_scenario_link, :previous_scenario
|
|
8
9
|
|
|
9
|
-
def initialize(config, last_scenario_link_name='last_scenario.yaml')
|
|
10
|
+
def initialize(config, last_scenario_link_name = 'last_scenario.yaml')
|
|
10
11
|
@logger = Logger.new('scenario_manager')
|
|
11
12
|
@config_dir = File.file?(config) ? File.dirname(config) : config
|
|
12
13
|
@last_scenario_link = File.join(config_dir, last_scenario_link_name)
|
|
@@ -31,7 +32,7 @@ module Kafo
|
|
|
31
32
|
end
|
|
32
33
|
|
|
33
34
|
def list_available_scenarios
|
|
34
|
-
say ::HighLine.color("Available scenarios", :
|
|
35
|
+
say ::HighLine.color("Available scenarios", :info)
|
|
35
36
|
available_scenarios.each do |config_file, content|
|
|
36
37
|
scenario = File.basename(config_file, '.yaml')
|
|
37
38
|
use = (File.expand_path(config_file) == @previous_scenario ? 'INSTALLED' : "use: --scenario #{scenario}")
|
|
@@ -77,7 +78,7 @@ module Kafo
|
|
|
77
78
|
!!(defined?(CONFIG_DIR) && CONFIG_DIR)
|
|
78
79
|
end
|
|
79
80
|
|
|
80
|
-
def scenario_from_args(arg_name='--scenario|-S')
|
|
81
|
+
def scenario_from_args(arg_name = '--scenario|-S')
|
|
81
82
|
# try scenario provided in the args via -S or --scenario
|
|
82
83
|
ARGV.each_with_index do |arg, index|
|
|
83
84
|
parsed = arg.match(/^(#{arg_name})($|=(?<scenario>\S+))/)
|
|
@@ -111,7 +112,7 @@ module Kafo
|
|
|
111
112
|
end
|
|
112
113
|
|
|
113
114
|
def show_scenario_diff(prev_scenario, new_scenario)
|
|
114
|
-
say ::HighLine.color("Scenarios are being compared, that may take a while...", :
|
|
115
|
+
say ::HighLine.color("Scenarios are being compared, that may take a while...", :info)
|
|
115
116
|
prev_conf = load_and_setup_configuration(prev_scenario)
|
|
116
117
|
new_conf = load_and_setup_configuration(new_scenario)
|
|
117
118
|
print_scenario_diff(prev_conf, new_conf)
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
module Kafo
|
|
2
|
+
# A class containing constants for all scenario options
|
|
3
|
+
class ScenarioOption
|
|
4
|
+
# @group Basic
|
|
5
|
+
|
|
6
|
+
# Human readable scenario name
|
|
7
|
+
NAME = :name
|
|
8
|
+
|
|
9
|
+
# Description of the installer scenario and its purpose
|
|
10
|
+
DESCRIPTION = :description
|
|
11
|
+
|
|
12
|
+
# Path to answer file, if the file does not exist a $pwd/config/answers.yaml is used as a fallback
|
|
13
|
+
ANSWER_FILE = :answer_file
|
|
14
|
+
|
|
15
|
+
# Enable colors? If you don't touch this, we'll autodetect terminal capabilities
|
|
16
|
+
COLORS = :colors
|
|
17
|
+
# Color scheme, we support :bright and :dark (first is better for white background, dark for black background)
|
|
18
|
+
COLOR_OF_BACKGROUND = :color_of_background
|
|
19
|
+
|
|
20
|
+
# @group Logging
|
|
21
|
+
|
|
22
|
+
# Destination for the log files
|
|
23
|
+
LOG_DIR = :log_dir
|
|
24
|
+
LOG_NAME = :log_name
|
|
25
|
+
LOG_LEVEL = :log_level
|
|
26
|
+
LOG_OWNER = :log_owner
|
|
27
|
+
LOG_GROUP = :log_group
|
|
28
|
+
|
|
29
|
+
# Whether verbose logging is enabled
|
|
30
|
+
VERBOSE = :verbose
|
|
31
|
+
|
|
32
|
+
# When verbose logging is enabled, which level (and up) is shown.
|
|
33
|
+
VERBOSE_LOG_LEVEL = :verbose_log_level
|
|
34
|
+
|
|
35
|
+
# @group State
|
|
36
|
+
|
|
37
|
+
# Custom storage is handy if you use hooks and you must store some
|
|
38
|
+
# configuration which should persist among installer runs. It can be also
|
|
39
|
+
# used for passing value from one hook to another.
|
|
40
|
+
CUSTOM = :custom
|
|
41
|
+
|
|
42
|
+
FACTS = :facts
|
|
43
|
+
|
|
44
|
+
# @group Advanced
|
|
45
|
+
|
|
46
|
+
# Checks, implemented as executable files, are loaded from the listed
|
|
47
|
+
# directories.
|
|
48
|
+
CHECK_DIRS = :check_dirs
|
|
49
|
+
|
|
50
|
+
# Hooks in these extra directories will be loaded, by default they are
|
|
51
|
+
# loaded from $installer_dir/hooks/$type when you specify your directory,
|
|
52
|
+
# it will be search for $yourdir/$type/*.rb
|
|
53
|
+
HOOK_DIRS = :hook_dirs
|
|
54
|
+
|
|
55
|
+
# Option to load puppet modules from a specific path. Optional and
|
|
56
|
+
# $pwd/modules is used by default, multiple dirs are allowed
|
|
57
|
+
MODULE_DIRS = :module_dirs
|
|
58
|
+
|
|
59
|
+
# Kafo has a cache for information parsed from Puppet modules. This
|
|
60
|
+
# determines the location where that information is stored.
|
|
61
|
+
PARSER_CACHE_PATH = :parser_cache_path
|
|
62
|
+
|
|
63
|
+
# By default all module parameters must be documented or an error is
|
|
64
|
+
# raised. This can be used to not raise an error when undocumented
|
|
65
|
+
# parameters are found.
|
|
66
|
+
IGNORE_UNDOCUMENTED = :ignore_undocumented
|
|
67
|
+
|
|
68
|
+
# Kafo tuning, customization of core functionality
|
|
69
|
+
|
|
70
|
+
# An optional mapping of classes
|
|
71
|
+
MAPPING = :mapping
|
|
72
|
+
NO_PREFIX = :no_prefix
|
|
73
|
+
ORDER = :order
|
|
74
|
+
LOW_PRIORITY_MODULES = :low_priority_modules
|
|
75
|
+
HIERA_CONFIG = :hiera_config
|
|
76
|
+
KAFO_MODULES_DIR = :kafo_modules_dir
|
|
77
|
+
CONFIG_HEADER_FILE = :config_header_file
|
|
78
|
+
DONT_SAVE_ANSWERS = :dont_save_answers
|
|
79
|
+
|
|
80
|
+
# These options are in DEFAULT but not in kafo.yaml.example
|
|
81
|
+
|
|
82
|
+
# Whether the scenario is enabled or not
|
|
83
|
+
ENABLED = :enabled
|
|
84
|
+
STORE_DIR = :store_dir
|
|
85
|
+
INSTALLER_DIR = :installer_dir
|
|
86
|
+
|
|
87
|
+
# Puppet modules declare the Puppet version they're compatible with. Kafo
|
|
88
|
+
# implements checks to verify this is correct with the Puppet version
|
|
89
|
+
# that's running. This can be used to bypass the checks
|
|
90
|
+
SKIP_PUPPET_VERSION_CHECK = :skip_puppet_version_check
|
|
91
|
+
end
|
|
92
|
+
end
|
data/lib/kafo/store.rb
CHANGED
data/lib/kafo/string_helper.rb
CHANGED
data/lib/kafo/version.rb
CHANGED
data/lib/kafo/wizard.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
|
-
require '
|
|
2
|
+
require 'forwardable'
|
|
3
|
+
require 'highline'
|
|
3
4
|
require 'yaml'
|
|
4
5
|
|
|
5
6
|
module Kafo
|
|
@@ -8,14 +9,17 @@ module Kafo
|
|
|
8
9
|
Kafo::ENV::LANG =~ /UTF-8\z/
|
|
9
10
|
end
|
|
10
11
|
|
|
12
|
+
extend Forwardable
|
|
13
|
+
def_delegators :@highline, :agree, :ask, :choose, :say
|
|
14
|
+
|
|
11
15
|
OK = utf_support? ? '✓' : 'y'
|
|
12
16
|
NO = utf_support? ? '✗' : 'n'
|
|
13
17
|
|
|
14
|
-
def initialize(kafo)
|
|
18
|
+
def initialize(kafo, input = $stdin, output = $stdout)
|
|
15
19
|
@kafo = kafo
|
|
16
20
|
@config = kafo.config
|
|
17
21
|
@name = @config.app[:name] || 'Kafo'
|
|
18
|
-
setup_terminal
|
|
22
|
+
@highline = setup_terminal(input, output)
|
|
19
23
|
end
|
|
20
24
|
|
|
21
25
|
def run
|
|
@@ -68,7 +72,7 @@ END
|
|
|
68
72
|
|
|
69
73
|
def display_hash
|
|
70
74
|
data = Hash[@config.modules.map { |mod| [mod.name, mod.enabled? ? mod.params_hash : false] }]
|
|
71
|
-
say HighLine.color(YAML.dump(data), :
|
|
75
|
+
say HighLine.color(YAML.dump(data), :info)
|
|
72
76
|
end
|
|
73
77
|
|
|
74
78
|
def configure_module(mod)
|
|
@@ -79,7 +83,7 @@ END
|
|
|
79
83
|
menu.prompt = 'Choose an option from the menu... '
|
|
80
84
|
menu.select_by = :index
|
|
81
85
|
|
|
82
|
-
menu.choice("Enable/disable #{mod.name} module, current value: #{HighLine.color(mod.enabled?.to_s, :
|
|
86
|
+
menu.choice("Enable/disable #{mod.name} module, current value: #{HighLine.color(mod.enabled?.to_s, :info)}") { turn_module(mod) }
|
|
83
87
|
if mod.enabled?
|
|
84
88
|
render_params(mod.primary_parameter_group.params, menu)
|
|
85
89
|
|
|
@@ -114,7 +118,7 @@ END
|
|
|
114
118
|
def render_params(params, menu)
|
|
115
119
|
params.each do |param|
|
|
116
120
|
if param.visible?(@kafo.params)
|
|
117
|
-
menu.choice "Set #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :
|
|
121
|
+
menu.choice "Set #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :info)}" do
|
|
118
122
|
configure(param)
|
|
119
123
|
end
|
|
120
124
|
end
|
|
@@ -141,13 +145,13 @@ END
|
|
|
141
145
|
end
|
|
142
146
|
|
|
143
147
|
def configure_single(param)
|
|
144
|
-
say "\ncurrent value: #{HighLine.color(param.value_to_s, :
|
|
148
|
+
say "\ncurrent value: #{HighLine.color(param.value_to_s, :info)}"
|
|
145
149
|
ask("new value:")
|
|
146
150
|
end
|
|
147
151
|
|
|
148
152
|
def configure_multi(param)
|
|
149
|
-
say HighLine.color('every line is a separate value, blank line to quit, for hash use key:value syntax', :
|
|
150
|
-
say "\ncurrent value: #{HighLine.color(param.value_to_s, :
|
|
153
|
+
say HighLine.color('every line is a separate value, blank line to quit, for hash use key:value syntax', :info)
|
|
154
|
+
say "\ncurrent value: #{HighLine.color(param.value_to_s, :info)} %>"
|
|
151
155
|
ask("new value:") do |q|
|
|
152
156
|
q.gather = ""
|
|
153
157
|
end
|
|
@@ -164,7 +168,7 @@ END
|
|
|
164
168
|
say "\n" + HighLine.color("Resetting parameters of module #{mod.name}", :headline)
|
|
165
169
|
choose do |menu|
|
|
166
170
|
mod.params.each do |param|
|
|
167
|
-
menu.choice "Reset #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :
|
|
171
|
+
menu.choice "Reset #{HighLine.color(param.name, :important)}, current value: #{HighLine.color(param.value_to_s, :info)}, default value: #{HighLine.color(param.default_to_s, :info)}" do
|
|
168
172
|
reset(param)
|
|
169
173
|
end if param.visible?(@kafo.params)
|
|
170
174
|
end
|
|
@@ -178,11 +182,17 @@ END
|
|
|
178
182
|
say "\n" + HighLine.color("Value for #{param.name} reset to default", :important)
|
|
179
183
|
end
|
|
180
184
|
|
|
181
|
-
def setup_terminal
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
185
|
+
def setup_terminal(input, output)
|
|
186
|
+
highline = HighLine.new(input, output)
|
|
187
|
+
# HighLine 2 vs 1
|
|
188
|
+
data = if highline.respond_to?(:terminal)
|
|
189
|
+
highline.terminal.terminal_size
|
|
190
|
+
else
|
|
191
|
+
HighLine::SystemExtensions.terminal_size
|
|
192
|
+
end
|
|
193
|
+
highline.wrap_at = data.first > 80 ? 80 : data.first if data.first
|
|
194
|
+
highline.page_at = data.last if data.last
|
|
195
|
+
highline
|
|
186
196
|
end
|
|
187
197
|
end
|
|
188
198
|
end
|
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: 6.
|
|
4
|
+
version: 6.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marek Hulan
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-05-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -171,7 +171,7 @@ dependencies:
|
|
|
171
171
|
version: 1.6.21
|
|
172
172
|
- - "<"
|
|
173
173
|
- !ruby/object:Gem::Version
|
|
174
|
-
version: '
|
|
174
|
+
version: '3.0'
|
|
175
175
|
type: :runtime
|
|
176
176
|
prerelease: false
|
|
177
177
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -181,7 +181,7 @@ dependencies:
|
|
|
181
181
|
version: 1.6.21
|
|
182
182
|
- - "<"
|
|
183
183
|
- !ruby/object:Gem::Version
|
|
184
|
-
version: '
|
|
184
|
+
version: '3.0'
|
|
185
185
|
- !ruby/object:Gem::Dependency
|
|
186
186
|
name: powerbar
|
|
187
187
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -262,6 +262,7 @@ files:
|
|
|
262
262
|
- lib/kafo/logging.rb
|
|
263
263
|
- lib/kafo/migration_context.rb
|
|
264
264
|
- lib/kafo/migrations.rb
|
|
265
|
+
- lib/kafo/multi_stage_hook.rb
|
|
265
266
|
- lib/kafo/param.rb
|
|
266
267
|
- lib/kafo/param_builder.rb
|
|
267
268
|
- lib/kafo/param_group.rb
|
|
@@ -275,6 +276,7 @@ files:
|
|
|
275
276
|
- lib/kafo/puppet_log_parser.rb
|
|
276
277
|
- lib/kafo/puppet_module.rb
|
|
277
278
|
- lib/kafo/scenario_manager.rb
|
|
279
|
+
- lib/kafo/scenario_option.rb
|
|
278
280
|
- lib/kafo/store.rb
|
|
279
281
|
- lib/kafo/string_helper.rb
|
|
280
282
|
- lib/kafo/system_checker.rb
|
|
@@ -293,7 +295,6 @@ files:
|
|
|
293
295
|
- modules/kafo_configure/spec/classes/init_spec.rb
|
|
294
296
|
- modules/kafo_configure/spec/fixtures/hiera/hiera.yaml
|
|
295
297
|
- modules/kafo_configure/spec/fixtures/hiera/test.yaml
|
|
296
|
-
- modules/kafo_configure/spec/fixtures/manifests/site.pp
|
|
297
298
|
- modules/kafo_configure/spec/fixtures/modules/dummy/manifests/init.pp
|
|
298
299
|
- modules/kafo_configure/spec/fixtures/modules/dummy/manifests/params.pp
|
|
299
300
|
- modules/kafo_configure/spec/functions/dump_lookups_spec.rb
|
|
@@ -319,7 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
319
320
|
- !ruby/object:Gem::Version
|
|
320
321
|
version: '0'
|
|
321
322
|
requirements: []
|
|
322
|
-
rubygems_version: 3.1.
|
|
323
|
+
rubygems_version: 3.1.6
|
|
323
324
|
signing_key:
|
|
324
325
|
specification_version: 4
|
|
325
326
|
summary: A gem for making installations based on puppet user friendly
|
|
File without changes
|