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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dfbb4a616b18c65acd9ec41a140d96ecb4fbec247cb408416d4ce69c41c693b8
4
- data.tar.gz: 5c77881bebac08faa217e5eff4ce173d43c7ef1cbb13ea40fc736b35b4786565
3
+ metadata.gz: 3ea658aadb5a4ad0c3e096e073d1d810b6deefa829a5105456ba30df27338f1a
4
+ data.tar.gz: '0812a0ddc530cc1e98aa6eabe4bdb2498834c24d4d5f6f3dd72d5057bfe338a9'
5
5
  SHA512:
6
- metadata.gz: 6863e239a103139ceb283835fb1d30baffcd8756893ae0627ee97396f8acad8de9fe93124868ce4d5a724f0906587ec37517cd7179ce8c36d5252385afcbee2c
7
- data.tar.gz: 9cd2571288e2847d66f781142e9d75b28c0dd7e7fb3b2e377e741128586bf79337032db98c524fd530b800154487f3a5f399ab037738f44394e1319fd967f932
6
+ metadata.gz: 16a1fada15bfd5a7301339e161b1a2bb88f30a15f428d58067e5ef9e5cc05d5e69d667063b6cb8846cc144ddfa1b46f4c584cbf2b1e7ea47b43554f521efc620
7
+ data.tar.gz: 2c4a224ad2a3dde11c370d456a8ea1668bdba7878f0a1ca80774e066e6b86158d57b915fd15350388794724932c7a8d9aabaca312b96749108665f03830c707a
@@ -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
- symbolize(JSON.load(`#{facter_path} --json`) || {})
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
@@ -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).append('2>&1').command
180
- result = `#{command}`
181
- @logger.debug result
182
- unless $?.exitstatus == 0
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
- if (version_mismatch = /kafo_configure::puppet_version_failure: (.+?\))/.match(result))
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 result
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(result.split($/))
205
+ load_yaml_from_output(stdout.split($/))
201
206
  end
202
207
  end
203
208
 
@@ -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)
@@ -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
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
  module Kafo
3
3
  PARSER_CACHE_VERSION = 1
4
- VERSION = "4.0.1"
4
+ VERSION = "4.1.0"
5
5
  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: 4.0.1
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-01-22 00:00:00.000000000 Z
11
+ date: 2020-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler