Module: Beaker::DSL::Helpers::Hiera

Defined in:
lib/beaker-hiera/helpers.rb,
lib/beaker-hiera/version.rb

Overview

Methods that help you interact with your hiera installation. Hiera must be installed for these methods to execute correctly.

Defined Under Namespace

Modules: Version

Instance Method Summary collapse

Instance Method Details

#copy_hiera_data(source) ⇒ Object

Copy hiera data files to the default host



57
58
59
# File 'lib/beaker-hiera/helpers.rb', line 57

def copy_hiera_data(source)
  copy_hiera_data_to(default, source)
end

#copy_hiera_data_to(host, source) ⇒ Object

Copy hiera data files to one or more provided hosts



45
46
47
48
49
# File 'lib/beaker-hiera/helpers.rb', line 45

def copy_hiera_data_to(host, source)
  block_on host do |hst|
    scp_to hst, File.expand_path(source), hiera_datadir(hst)
  end
end

#hiera_datadir(host) ⇒ String

Get file path to the hieradatadir for a given host. Handles whether or not a host is AIO-based & backwards compatibility



68
69
70
# File 'lib/beaker-hiera/helpers.rb', line 68

def hiera_datadir(host)
  File.join(host.puppet['codedir'], 'hieradata')
end

#write_hiera_config(hierarchy) ⇒ Object

Write hiera config file for the default host



34
35
36
# File 'lib/beaker-hiera/helpers.rb', line 34

def write_hiera_config(hierarchy)
  write_hiera_config_on(default, hierarchy)
end

#write_hiera_config_on(host, hierarchy) ⇒ Object

Write hiera config file on one or more provided hosts



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/beaker-hiera/helpers.rb', line 14

def write_hiera_config_on(host, hierarchy)
  block_on host do |hst|
    hiera_config = {
      backends: 'yaml',
      yaml: {
        datadir: hiera_datadir(hst)
      },
      hierarchy: hierarchy,
      logger: 'console'
    }
    create_remote_file hst, hst.puppet['hiera_config'], hiera_config.to_yaml
  end
end