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

Parameters:

  • source (String)

    Directory containing the hiera data files.

See Also:



59
60
61
# File 'lib/beaker-hiera/helpers.rb', line 59

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

Parameters:

  • host (Host, Array<Host>, String, Symbol)

    One or more hosts to act upon, or a role (String or Symbol) that identifies one or more hosts.

  • source (String)

    Directory containing the hiera data files.



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

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

Parameters:

  • host (Host)

    Host you want to use the hieradatadir from

Returns:

  • (String)

    Path to the hiera data directory



70
71
72
# File 'lib/beaker-hiera/helpers.rb', line 70

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

#write_hiera_config(hierarchy) ⇒ Object

Write hiera config file for the default host

Parameters:

  • hierarchy (Array)

    One or more hierarchy paths

See Also:



36
37
38
# File 'lib/beaker-hiera/helpers.rb', line 36

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

Parameters:

  • host (Host, Array<Host>, String, Symbol)

    One or more hosts to act upon, or a role (String or Symbol) that identifies one or more hosts.

  • hierarchy (Array[Hash[String, String]])

    The hierachy as specified in Hiera config YAML version 5

See Also:



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

def write_hiera_config_on(host, hierarchy)
  block_on host do |hst|
    hiera_config = {
      'version' => 5,
      'defaults' => {
        'datadir' => hiera_datadir(hst),
        'data_hash' => 'yaml_data',
      },
      'hierarchy' => hierarchy,
    }
    create_remote_file hst, hst.puppet['hiera_config'], hiera_config.to_yaml
  end
end