Class: PuppetSetting

Inherits:
Object
  • Object
show all
Includes:
Foreman::Util
Defined in:
lib/puppet_setting.rb

Instance Method Summary collapse

Methods included from Foreman::Util

#secure_token, #which

Instance Method Details

#get(*name) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppet_setting.rb', line 8

def get(*name)
  cmd = "#{puppetmaster} --configprint #{name.join(",")} 2>&1"

  values = if !SETTINGS[:puppetgem] && defined? Bundler && Bundler.responds_to(:with_clean_env)
    # execute in a clean env to prevent bundler interfering with loading Ruby for Puppet
    Bundler.with_clean_env do
      `#{cmd}`
    end
  else
    # if puppetgem is set, the user intends to rely on bundler
    `#{cmd}`
  end
  raise "unable to get #{name.inspect} Puppet setting, `#{cmd}` returned #{$?}: #{values}" unless $?.success?

  if name.size > 1
    # Parse key = value lines into hash
    HashWithIndifferentAccess[values.lines.map {|kv| kv.chomp.split(' = ', 2) }]
  else
    HashWithIndifferentAccess[name.first.to_s, values.chomp]
  end
end