Class: Kafo::ExecutionEnvironment

Inherits:
Object
  • Object
show all
Defined in:
lib/kafo/execution_environment.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, logger = KafoConfigure.logger) ⇒ ExecutionEnvironment

Returns a new instance of ExecutionEnvironment.



9
10
11
12
# File 'lib/kafo/execution_environment.rb', line 9

def initialize(config, logger = KafoConfigure.logger)
  @config = config
  @logger = logger
end

Instance Method Details

#configure_puppet(settings = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/kafo/execution_environment.rb', line 37

def configure_puppet(settings = {})
  @logger.debug("Configuring Puppet in #{directory}")

  @logger.debug("Writing facts to #{factpath}")
  FactWriter.write_facts(facts, factpath)

  hiera_config = configure_hiera

  settings = {
    'environmentpath' => environmentpath,
    'factpath'        => factpath,
    'hiera_config'    => hiera_config,
    'reports'         => 'store',
    'reportdir'       => reportdir,
  }.merge(settings)

  PuppetConfigurer.new(puppet_conf, settings)
end

#directoryObject



14
15
16
17
18
19
20
# File 'lib/kafo/execution_environment.rb', line 14

def directory
  @directory ||= begin
    directory = Dir.mktmpdir('kafo_installation')
    @logger.debug("Creating execution environment in #{directory}")
    directory
  end
end

#reportdirObject



22
23
24
# File 'lib/kafo/execution_environment.rb', line 22

def reportdir
  @reportdir ||= File.join(directory, 'reports')
end

#reportsObject



26
27
28
29
# File 'lib/kafo/execution_environment.rb', line 26

def reports
  # Reports are stored in $reportdir/$certname/$report
  Dir.glob(File.join(reportdir, '*', '*.*')).sort_by { |path| File.mtime(path) }
end

#store_answersObject



31
32
33
34
35
# File 'lib/kafo/execution_environment.rb', line 31

def store_answers
  answer_data = HieraConfigurer.generate_data(@config.modules, @config.app[:order])
  @logger.debug("Writing temporary answers to #{answer_file}")
  File.open(answer_file, 'w') { |f| f.write(YAML.dump(answer_data)) }
end