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.1.0"

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
# File 'lib/erb-hiera.rb', line 18

def self.run
  @options = CLI.parse

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

    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
end