kafo 4.0.1 → 4.1.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/lib/kafo/base_context.rb +9 -1
- data/lib/kafo/configuration.rb +12 -7
- data/lib/kafo/kafo_configure.rb +1 -1
- data/lib/kafo/puppet_command.rb +21 -1
- data/lib/kafo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ea658aadb5a4ad0c3e096e073d1d810b6deefa829a5105456ba30df27338f1a
|
4
|
+
data.tar.gz: '0812a0ddc530cc1e98aa6eabe4bdb2498834c24d4d5f6f3dd72d5057bfe338a9'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16a1fada15bfd5a7301339e161b1a2bb88f30a15f428d58067e5ef9e5cc05d5e69d667063b6cb8846cc144ddfa1b46f4c584cbf2b1e7ea47b43554f521efc620
|
7
|
+
data.tar.gz: 2c4a224ad2a3dde11c370d456a8ea1668bdba7878f0a1ca80774e066e6b86158d57b915fd15350388794724932c7a8d9aabaca312b96749108665f03830c707a
|
data/lib/kafo/base_context.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
1
3
|
module Kafo
|
2
4
|
class BaseContext
|
3
5
|
def facts
|
@@ -24,12 +26,18 @@ module Kafo
|
|
24
26
|
|
25
27
|
def self.facts
|
26
28
|
@facts ||= begin
|
27
|
-
|
29
|
+
result = run_command("#{facter_path} --json")
|
30
|
+
symbolize(JSON.load(result) || {})
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
31
34
|
def self.facter_path
|
32
35
|
@facter_path ||= PuppetCommand.search_puppet_path('facter')
|
33
36
|
end
|
37
|
+
|
38
|
+
def self.run_command(command)
|
39
|
+
stdout, _stderr, _status = Open3.capture3(*PuppetCommand.format_command(command))
|
40
|
+
stdout
|
41
|
+
end
|
34
42
|
end
|
35
43
|
end
|
data/lib/kafo/configuration.rb
CHANGED
@@ -176,12 +176,16 @@ module Kafo
|
|
176
176
|
EOS
|
177
177
|
|
178
178
|
@logger.info 'Loading default values from puppet modules...'
|
179
|
-
command = PuppetCommand.new(dump_manifest, [], puppetconf, self).
|
180
|
-
|
181
|
-
|
182
|
-
|
179
|
+
command = PuppetCommand.new(dump_manifest, [], puppetconf, self).command
|
180
|
+
stdout, stderr, status = Open3.capture3(*PuppetCommand.format_command(command))
|
181
|
+
|
182
|
+
@logger.debug stdout
|
183
|
+
@logger.debug stderr
|
184
|
+
|
185
|
+
unless status.success?
|
183
186
|
log = app[:log_dir] + '/' + app[:log_name]
|
184
|
-
|
187
|
+
|
188
|
+
if (version_mismatch = /kafo_configure::puppet_version_failure: (.+?\))/.match(stderr))
|
185
189
|
puts version_mismatch[1]
|
186
190
|
puts "Cannot continue due to incompatible version of Puppet. Use --skip-puppet-version-check to disable this check."
|
187
191
|
@logger.error version_mismatch[1]
|
@@ -190,14 +194,15 @@ EOS
|
|
190
194
|
else
|
191
195
|
puts "Could not get default values, check log file at #{log} for more information"
|
192
196
|
@logger.error command
|
193
|
-
@logger.error
|
197
|
+
@logger.error stderr
|
194
198
|
@logger.error 'Could not get default values, cannot continue'
|
195
199
|
KafoConfigure.exit(:defaults_error)
|
196
200
|
end
|
197
201
|
end
|
202
|
+
|
198
203
|
@logger.info "... finished"
|
199
204
|
|
200
|
-
load_yaml_from_output(
|
205
|
+
load_yaml_from_output(stdout.split($/))
|
201
206
|
end
|
202
207
|
end
|
203
208
|
|
data/lib/kafo/kafo_configure.rb
CHANGED
@@ -446,7 +446,7 @@ module Kafo
|
|
446
446
|
begin
|
447
447
|
command = PuppetCommand.new('include kafo_configure', options, puppetconf).command
|
448
448
|
log_parser = PuppetLogParser.new
|
449
|
-
PTY.spawn(command) do |stdin, stdout, pid|
|
449
|
+
PTY.spawn(*PuppetCommand.format_command(command)) do |stdin, stdout, pid|
|
450
450
|
begin
|
451
451
|
stdin.each do |line|
|
452
452
|
line = normalize_encoding(line)
|
data/lib/kafo/puppet_command.rb
CHANGED
@@ -35,12 +35,32 @@ module Kafo
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def self.search_puppet_path(bin_name)
|
38
|
+
# Find the location of the puppet executable and use that to
|
39
|
+
# determine the path of all executables
|
38
40
|
bin_path = (::ENV['PATH'].split(File::PATH_SEPARATOR) + ['/opt/puppetlabs/bin']).find do |path|
|
39
|
-
File.executable?(File.join(path, bin_name))
|
41
|
+
File.executable?(File.join(path, 'puppet')) && File.executable?(File.join(path, bin_name))
|
40
42
|
end
|
41
43
|
File.join([bin_path, bin_name].compact)
|
42
44
|
end
|
43
45
|
|
46
|
+
def self.format_command(command)
|
47
|
+
if search_puppet_path('puppet').start_with?('/opt/puppetlabs')
|
48
|
+
[clean_env_vars, command, :unsetenv_others => true]
|
49
|
+
else
|
50
|
+
[::ENV, command, :unsetenv_others => false]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.clean_env_vars
|
55
|
+
# Cleaning ENV vars and keeping required vars only because,
|
56
|
+
# When using SCL it adds GEM_HOME and GEM_PATH ENV vars.
|
57
|
+
whitelisted_vars = %w[HOME USER LANG]
|
58
|
+
|
59
|
+
cleaned_env = ::ENV.select { |var| whitelisted_vars.include?(var) || var.start_with?('LC_') }
|
60
|
+
cleaned_env['PATH'] = '/sbin:/bin:/usr/sbin:/usr/bin:/opt/puppetlabs/bin'
|
61
|
+
cleaned_env
|
62
|
+
end
|
63
|
+
|
44
64
|
private
|
45
65
|
|
46
66
|
def manifest
|
data/lib/kafo/version.rb
CHANGED
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: 4.0
|
4
|
+
version: 4.1.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: 2020-
|
11
|
+
date: 2020-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|