module Beaker::DSL::Helpers::Hiera
Methods that help you interact with your hiera installation. Hiera
must be installed for these methods to execute correctly.
Public Instance Methods
Copy hiera data files to the default host
@param [String] source
Directory containing the hiera data files.
@see copy_hiera_data_to
# File lib/beaker-hiera/helpers.rb, line 59 def copy_hiera_data(source) copy_hiera_data_to(default, source) end
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 [String] source
Directory containing the hiera data files.
# 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
Get file path to the hieradatadir for a given host. Handles whether or not a host is AIO-based & backwards compatibility
@param [Host] host
Host you want to use the hieradatadir from
@return [String] Path to the hiera data directory
# File lib/beaker-hiera/helpers.rb, line 70 def hiera_datadir(host) File.join(host.puppet['codedir'], 'hieradata') end
Write hiera config file for the default host
@param [Array] hierarchy
One or more hierarchy paths
# File lib/beaker-hiera/helpers.rb, line 36 def write_hiera_config(hierarchy) write_hiera_config_on(default, hierarchy) end
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 [Array[Hash[String, String]]] hierarchy
The hierachy as specified in Hiera config YAML version 5
@see www.puppet.com/docs/puppet/7/hiera_config_yaml_5.html
# 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