Module: BeakerPuppetHelpers::ModuleUtils

Defined in:
lib/beaker_puppet_helpers/module_utils.rb

Overview

Methods to help install puppet modules

Instance Method Summary collapse

Instance Method Details

#install_local_module_on(hosts, source = '.') ⇒ Object

Install local module for acceptance testing

This uses puppet-modulebuilder to build the module located at source and then copies it to the hosts. There it runs puppet module install.

Parameters:

  • hosts (Beaker::Host, Array<Beaker::Host>, String, Symbol)

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

  • source (String) (defaults to: '.')

    The directory where the module sits



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/beaker_puppet_helpers/module_utils.rb', line 42

def install_local_module_on(hosts, source = '.')
  builder = Puppet::Modulebuilder::Builder.new(File.realpath(source))
  source_path = builder.build
  begin
    block_on hosts do |host|
      target_file = host.tmpfile('puppet_module')
      begin
        host.do_scp_to(source_path, target_file, {})
        install_puppet_module_via_pmt_on(host, target_file)
      ensure
        host.rm_rf(target_file)
      end
    end
  ensure
    File.unlink(source_path) if source_path
  end
end

#install_puppet_module_via_pmt_on(hosts, module_name, version = nil, module_repository = nil) ⇒ Object

Install the desired module with the Puppet Module Tool (PMT) on a given host

Parameters:

  • hosts (Beaker::Host, Array<Beaker::Host>, String, Symbol)

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

  • module_name (String)

    The short name of the module to be installed

  • version (String) (defaults to: nil)

    The version of the module to be installed

  • module_repository (String) (defaults to: nil)

    An optional module repository to install from



21
22
23
24
25
26
27
28
29
30
# File 'lib/beaker_puppet_helpers/module_utils.rb', line 21

def install_puppet_module_via_pmt_on(hosts, module_name, version = nil, module_repository = nil)
  block_on hosts do |host|
    puppet_opts = {}
    puppet_opts.merge!(host[:default_module_install_opts]) if host[:default_module_install_opts]
    puppet_opts[:version] = Shellwords.escape(version) if version
    puppet_opts[:module_repository] = Shellwords.escape(module_repository) if module_repository

    on host, Beaker::PuppetCommand.new('module', ['install', module_name], puppet_opts)
  end
end