Module: ErbHiera

Defined in:
lib/erb-hiera.rb,
lib/erb-hiera/cli.rb,
lib/erb-hiera/hiera.rb,
lib/erb-hiera/version.rb,
lib/erb-hiera/manifest.rb,
lib/erb-hiera/directory.rb

Defined Under Namespace

Modules: CLI, Directory, Hiera, Manifest

Constant Summary collapse

VERSION =
"0.4.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.optionsObject

Returns the value of attribute options.



15
16
17
# File 'lib/erb-hiera.rb', line 15

def options
  @options
end

.scopeObject

Returns the value of attribute scope.



15
16
17
# File 'lib/erb-hiera.rb', line 15

def scope
  @scope
end

Class Method Details

.runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/erb-hiera.rb', line 18

def self.run
  @options = CLI.parse

  mappings.each do |config|
    ErbHiera.scope  = config["scope"]
    in_dir          = config["dir"]["input"]
    out_dir         = config["dir"]["output"]

    [:in_dir, :out_dir].each do |dir|
      raise StandardError, "error: undefined #{dir.to_s.split('_')[0]}put directory" unless binding.local_variable_get(dir)
    end

    manifests(in_dir).each do |manifest|
      out_file = File.join(out_dir, manifest.gsub(in_dir, ""))

      Manifest.info(manifest, out_file) if options[:verbose]

      erb = ERB.new(File.read(manifest), nil, "-").result(Hiera.get_binding)

      puts erb if options[:verbose]

      unless options[:dry_run]
        FileUtils.mkdir_p File.dirname(out_file) unless Dir.exists?(File.dirname(out_file))
        File.write(out_file, erb)
      end
    end
  end
rescue => error
  handle_error(error)
  exit 1
end