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

Defined in:
lib/beaker-hiera/helpers.rb,
lib/beaker-hiera.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


43
44
45
# File 'lib/beaker-hiera/helpers.rb', line 43

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

@param[Host, Array<Host>, String, Symbol] host One or more hosts to act upon,

or a role (String or Symbol) that identifies one or more hosts.

@param Directory containing the hiera data files.


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

def copy_hiera_data_to(host, source)
  scp_to host, File.expand_path(source), hiera_datadir(host)
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

@param host Host you want to use the hieradatadir from

Returns:

  • (String)

    Path to the hiera data directory


53
54
55
# File 'lib/beaker-hiera/helpers.rb', line 53

def hiera_datadir(host)
  host[:type] =~ /aio/ ? File.join(host.puppet['codedir'], 'hieradata') : host[:hieradatadir]
end

#write_hiera_config(hierarchy) ⇒ Object

Write hiera config file for the default host


28
29
30
# File 'lib/beaker-hiera/helpers.rb', line 28

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

@param[Host, Array<Host>, String, Symbol] host One or more hosts to act upon,

or a role (String or Symbol) that identifies one or more hosts.

@param One or more hierarchy paths


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

def write_hiera_config_on(host, hierarchy)

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