Sha256: 6d3fedd51a01c1e2dce8d585a40b9af58ddff6b69a39282e57910c19cc600b21

Contents?: true

Size: 922 Bytes

Versions: 6

Compression:

Stored size: 922 Bytes

Contents

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

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

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

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kafo-7.6.0 lib/kafo/hiera_configurer.rb
kafo-7.5.1 lib/kafo/hiera_configurer.rb
kafo-7.5.0 lib/kafo/hiera_configurer.rb
kafo-7.4.0 lib/kafo/hiera_configurer.rb
kafo-7.3.0 lib/kafo/hiera_configurer.rb
kafo-7.2.0 lib/kafo/hiera_configurer.rb