Class: BeakerPuppetHelpers::InstallUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/beaker_puppet_helpers/install_utils.rb

Overview

Methods to install Puppet

Constant Summary collapse

REPOS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  openvox: {
    release: {
      apt: 'https://apt.voxpupuli.org/',
      yum: 'https://yum.voxpupuli.org/',
    },
  },
  puppet: {
    release: {
      apt: 'https://apt.puppet.com',
      yum: 'https://yum.puppet.com',
    },
  },
}.freeze

Class Method Summary collapse

Class Method Details

.collection2packagename(host, collection, prefer_aio: true) ⇒ String

Determine if we need the Perforce or OpenVox Package, based on the collection

Parameters:

  • host (Beaker::Host)

    The host to act on

  • collection

    The used collection (puppet7, openvox8…)

  • prefer_aio (Boolean) (defaults to: true)

    Whether to prefer AIO packages or OS packages

Returns:

  • (String)

    the package name



118
119
120
121
# File 'lib/beaker_puppet_helpers/install_utils.rb', line 118

def self.collection2packagename(host, collection, prefer_aio: true)
  implementation = implementation_from_collection(collection)
  package_name(host, prefer_aio: prefer_aio, implementation: implementation)
end

.implementation_from_collection(collection) ⇒ String

returns the used implementation (puppet or openvox)

Parameters:

  • collection (String)

    The used collection (puppet7, openvox8…)

Returns:

  • (String)

    the implementation



29
30
31
# File 'lib/beaker_puppet_helpers/install_utils.rb', line 29

def self.implementation_from_collection(collection)
  collection.gsub(/\d+/, '')
end

.install_puppet_release_repo_on(host, collection = 'puppet') ⇒ Object

Note:

This method only works on redhat-like and debian-like hosts. There are no official Puppet releases for other platforms.

Install official Puppet release repository configuration on host(s).

Examples:

Install Puppet 7

install_puppet_release_repo_on(hosts, 'puppet7')

Parameters:

  • host (Beaker::Host)

    A host to act upon.

  • collection (String) (defaults to: 'puppet')

    The collection to install. The default (puppet) is the latest available version. Can also be openvox7, puppet8 and others. Method is called from beaker_install_helpers



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/beaker_puppet_helpers/install_utils.rb', line 49

def self.install_puppet_release_repo_on(host, collection = 'puppet')
  implementation = implementation_from_collection(collection)
  repos = REPOS[implementation.to_sym][:release]

  variant, version, _arch = host['packaging_platform'].split('-', 3)

  case variant
  when 'el', 'fedora', 'sles', 'cisco-wrlinux'
    # sles 11 and later do not handle gpg keys well. We can't
    # automatically import the keys because of sad things, so we
    # have to manually import it once we install the release
    # package. We'll have to remember to update this block when
    # we update the signing keys
    if variant == 'sles' && version >= '11'
      %w[puppet puppet-20250406].each do |gpg_key|
        wget_on(host, "https://yum.puppet.com/RPM-GPG-KEY-#{gpg_key}") do |filename|
          host.exec(Beaker::Command.new("rpm --import '#{filename}'"))
        end
      end
    end

    url = "#{repos[:yum]}/#{collection}-release-#{variant}-#{version}.noarch.rpm"
    host.install_package(url)
  when 'debian', 'ubuntu'
    relname = (implementation == 'openvox') ? "#{variant}#{version}" : host['platform'].codename
    url = "#{repos[:apt]}/#{collection}-release-#{relname}.deb"
    wget_on(host, url) do |filename|
      host.install_package(filename)
    end
    host.exec(Beaker::Command.new('apt-get update'))

    # On Debian we can't count on /etc/profile.d
    host.add_env_var('PATH', '/opt/puppetlabs/bin')
  else
    raise "No repository installation step for #{variant} yet..."
  end
end

.openvox_package_nameString

Determine the openvox package name

Returns:

  • (String)

    The openvox package name



150
151
152
# File 'lib/beaker_puppet_helpers/install_utils.rb', line 150

def self.openvox_package_name
  'openvox-agent'
end

.package_name(host, prefer_aio: true, implementation: 'openvox') ⇒ String

Determine the correct package name, based on implementation, AIO and OS

Parameters:

  • host (Beaker::Host)

    The host to act on

  • prefer_aio (Boolean) (defaults to: true)

    Whether to prefer AIO packages or OS packages

  • implementation (String) (defaults to: 'openvox')

    If we are on OpenVox or Perforce

Returns:

  • (String)

    the package name



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/beaker_puppet_helpers/install_utils.rb', line 96

def self.package_name(host, prefer_aio: true, implementation: 'openvox')
  case implementation
  when 'openvox'
    openvox_package_name
  when 'puppet'
    puppet_package_name(host, prefer_aio: prefer_aio)
  when 'none'
    'puppet'
  else
    raise StandardError, "Unknown requirement '#{implementation}'"
  end
end

.puppet_package_name(host, prefer_aio: true) ⇒ String

Determine the Puppet package name

Parameters:

  • host (Beaker::Host)

    The host to act on

  • prefer_aio (Boolean) (defaults to: true)

    Whether to prefer AIO packages or OS packages

Returns:

  • (String)

    The Puppet package name



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/beaker_puppet_helpers/install_utils.rb', line 130

def self.puppet_package_name(host, prefer_aio: true)
  case host['packaging_platform'].split('-', 3).first
  when 'debian'
    # 12 started to ship puppet-agent with puppet as a legacy package
    (prefer_aio || host['packaging_platform'].split('-', 3)[1].to_i >= 12) ? 'puppet-agent' : 'puppet'
  when /el|fedora|sles|cisco_/
    prefer_aio ? 'puppet-agent' : 'puppet'
  when /freebsd/
    'sysutils/puppet8'
  when 'ubuntu'
    # 23.04 started to ship puppet-agent with puppet as a legacy package
    (prefer_aio || host['packaging_platform'].split('-', 3)[1].to_i >= 2304) ? 'puppet-agent' : 'puppet'
  else
    'puppet'
  end
end

.wget_on(host, url) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • host (Beaker::Host)

    The host to act on



157
158
159
160
161
162
163
164
165
166
167
# File 'lib/beaker_puppet_helpers/install_utils.rb', line 157

def self.wget_on(host, url)
  extension = File.extname(url)
  name = File.basename(url, extension)
  target = host.tmpfile(name, extension)
  begin
    host.exec(Beaker::Command.new("wget -O '#{target}' '#{url}'"))
    yield target
  ensure
    host.rm_rf(target)
  end
end