Class: Kafo::HieraConfigurer

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

Class Method Summary collapse

Class Method Details

.default_configObject



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/kafo/hiera_configurer.rb', line 3

def self.default_config
  {
    'version' => 5,
    'hierarchy' => [
      {
        'name' => 'Kafo Answers',
        'path' => '%{facts.kafo.scenario.answer_file}',
        'data_hash' => 'yaml_data',
      },
    ],
  }
end

.generate_data(modules, order = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/kafo/hiera_configurer.rb', line 21

def self.generate_data(modules, order = nil)
  classes = []
  data = modules.select(&:enabled?).inject({}) do |config, mod|
    classes << mod.class_name
    config.update(Hash[mod.params_hash.map { |k, v| ["#{mod.class_name}::#{k}", v] }])
  end
  data['classes'] = sort_modules(classes, order)
  data
end

.sort_modules(modules, order) ⇒ Object



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

def self.sort_modules(modules, order)
  return modules unless order

  (order & modules) + (modules - order)
end

.write_default_config(path) ⇒ Object



16
17
18
19
# File 'lib/kafo/hiera_configurer.rb', line 16

def self.write_default_config(path)
  File.open(path, 'w') { |f| f.write(YAML.dump(default_config)) }
  path
end