Module: Beaker::DSL::InstallUtils::FOSSUtils

Includes:
AIODefaults, FOSSDefaults, PuppetUtils, WindowsUtils
Included in:
BeakerPuppet
Defined in:
lib/beaker-puppet/install_utils/foss_utils.rb

Overview

This module contains methods to install FOSS puppet from various sources

To mix this is into a class you need the following:

  • a method hosts that yields any hosts implementing Host‘s interface to act upon.

  • a method options that provides an options hash, see Options::OptionsHash

  • the module Roles that provides access to the various hosts implementing Host‘s interface to act upon

  • the module Wrappers the provides convenience methods for Command creation

Constant Summary collapse

SourcePath =

The default install path

'/opt/puppet-git-repos'
GitURI =

A regex to know if the uri passed is pointing to a git repo

%r{^(git|https?|file)://|^git@|^gitmirror@}
GitHubSig =

Github’s ssh signature for cloning via ssh

'github.com,207.97.227.239 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=='

Constants included from FOSSDefaults

Beaker::DSL::InstallUtils::FOSSDefaults::FOSS_DEFAULTS, Beaker::DSL::InstallUtils::FOSSDefaults::FOSS_DEFAULT_DOWNLOAD_URLS

Constants included from AIODefaults

AIODefaults::AIO_DEFAULTS

Instance Method Summary collapse

Methods included from WindowsUtils

#create_install_msi_batch_on, #generic_install_msi_on, #get_system_temp_path, #install_msi_on, #msi_install_script

Methods included from PuppetUtils

#add_puppet_paths_on, #configure_defaults_on, #configure_type_defaults_on, #construct_puppet_path, #normalize_type, #puppet_agent_version_on, #puppet_collection_for, #puppetserver_version_on, #remove_defaults_on, #remove_puppet_paths_on, #stop_firewall_with_puppet_on

Methods included from FOSSDefaults

#add_foss_defaults_on, #add_platform_foss_defaults, #remove_foss_defaults_on, #remove_platform_foss_defaults

Methods included from AIODefaults

#add_aio_defaults_on, #add_platform_aio_defaults, #remove_aio_defaults_on, #remove_platform_aio_defaults

Instance Method Details

#build_git_url(project_name, git_fork = nil, git_server = nil, git_protocol = 'https') ⇒ String Also known as: build_giturl

TODO: enable other protocols, clarify, git-scm.com/book/ch4-1.html

Parameters:

  • project_name (String)
  • git_fork (String) (defaults to: nil)

    When not provided will use PROJECT_FORK environment variable

  • git_server (String) (defaults to: nil)

    When not provided will use PROJECT_SERVER environment variable

  • git_protocol (String) (defaults to: 'https')

    ‘git’,‘ssh’,‘https’

Returns:

  • (String)

    Returns a git-usable url



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 90

def build_git_url(project_name, git_fork = nil, git_server = nil, git_protocol = 'https')
  git_fork   ||= lookup_in_env('FORK',   project_name, 'puppetlabs')
  git_server ||= lookup_in_env('SERVER', project_name, 'github.com')

  case git_protocol
  when /(ssh|git)/
    git_protocol = 'git@'
  when /https/
    git_protocol = 'https://'
  end

  repo = (git_server == 'github.com') ? "#{git_fork}/#{project_name}.git" : "#{git_fork}-#{project_name}.git"
  (git_protocol == 'git@') ? "#{git_protocol}#{git_server}:#{repo}" : "#{git_protocol}#{git_server}/#{repo}"
end

#bundle_command(host, type = 'aio') ⇒ Object



1386
1387
1388
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 1386

def bundle_command(host, type = 'aio')
  get_command('bundle', host, type)
end

#clone_git_repo_on(host, path, repository, opts = {}) ⇒ Object

Note:

This requires the helper methods:

  • Helpers#on

Parameters:

  • host (Host)

    An object implementing Hosts‘s interface.

  • path (String)

    The path on the remote [host] to the repository

  • repository (Hash{Symbol=>String})

    A hash representing repo info like that emitted by #extract_repo_info_from



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 188

def clone_git_repo_on(host, path, repository, opts = {})
  opts = { accept_all_exit_codes: true }.merge(opts)
  name          = repository[:name]
  repo          = repository[:path]
  rev           = repository[:rev]
  depth         = repository[:depth]
  depth_branch  = repository[:depth_branch]
  target        = "#{path}/#{name}"

  depth_branch = rev if depth_branch.nil?

  clone_cmd = "git clone #{repo} #{target}"
  clone_cmd = "git clone --branch #{depth_branch} --depth #{depth} #{repo} #{target}" if depth

  logger.notify("\n  * Clone #{repo} if needed")

  on host, "test -d #{path} || mkdir -p #{path}", opts
  on host, "test -d #{target} || #{clone_cmd}", opts

  logger.notify("\n  * Update #{name} and check out revision #{rev}")
  commands = ["cd #{target}",
              'remote rm origin',
              "remote add origin #{repo}",
              'fetch origin +refs/pull/*:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/*',
              'clean -fdx',
              "checkout -f #{rev}",]
  on host, commands.join(' && git '), opts
end

#compute_puppet_msi_name(host, opts) ⇒ 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.



593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 593

def compute_puppet_msi_name(host, opts)
  version = opts[:version]
  install_32 = host['install_32'] || opts['install_32']
  less_than_3_dot_7 = version && version_is_less(version, '3.7')

  # If there's no version declared, install the latest in the 3.x series
  if !version
    host['dist'] = if !host.is_x86_64? || install_32
                     'puppet-latest'
                   else
                     'puppet-x64-latest'
                   end

  # Install Puppet 3.x with the x86 installer if:
  # - we are on puppet < 3.7, or
  # - we are less than puppet 4.0 and on an x86 host, or
  # - we have install_32 set on host or globally
  # Install Puppet 3.x with the x64 installer if:
  # - we are otherwise trying to install Puppet 3.x on a x64 host
  elsif less_than_3_dot_7 or !host.is_x86_64? or install_32
    host['dist'] = "puppet-#{version}"

  elsif host.is_x86_64?
    host['dist'] = "puppet-#{version}-x64"

  else
    raise "I don't understand how to install Puppet version: #{version}"
  end
end

#configure_gem_mirror(hosts) ⇒ Object

Configures gem sources on hosts to use a mirror, if specified This is a duplicate of the Gemfile logic.



1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 1396

def configure_gem_mirror(hosts)
  gem_source = ENV.fetch('GEM_SOURCE', nil)

  # Newer versions of rubygems always default the source to https://rubygems.org
  # and versions >= 3.1 will try to prompt (and fail) if you add a source that is
  # too similar to rubygems.org to prevent typo squatting:
  # https://github.com/rubygems/rubygems/commit/aa967b85dd96bbfb350f104125f23d617e82a00a
  return unless gem_source && gem_source !~ /rubygems\.org/

  Array(hosts).each do |host|
    gem = gem_command(host)
    on host, "#{gem} source --clear-all"
    on(host, "#{gem} source --add #{gem_source}")
  end
end

#configure_puppet(opts = {}) ⇒ Object

Deprecated.

Use #configure_puppet_on instead.



445
446
447
448
449
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 445

def configure_puppet(opts = {})
  hosts.each do |host|
    configure_puppet_on(host, opts)
  end
end

#configure_puppet_on(hosts, opts = {}) ⇒ Object

Configure puppet.conf on the given host(s) based upon a provided hash

Examples:

will configure /etc/puppet.conf on the puppet master.

config = {
  'main' => {
    'server'   => 'testbox.test.local',
    'certname' => 'testbox.test.local',
    'logdir'   => '/var/log/puppet',
    'vardir'   => '/var/lib/puppet',
    'ssldir'   => '/var/lib/puppet/ssl',
    'rundir'   => '/var/run/puppet'
  },
  'agent' => {
    'environment' => 'dev'
  }
}
configure_puppet_on(master, config)

Parameters:

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

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

  • opts (Hash{Symbol=>String}) (defaults to: {})

Options Hash (opts):

  • :main (Hash{String=>String})

    configure the main section of puppet.conf

  • :agent (Hash{String=>String})

    configure the agent section of puppet.conf

  • :run_in_parallel (Boolean)

    Whether to run on each host in parallel.

Returns:

  • nil



476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 476

def configure_puppet_on(hosts, opts = {})
  puppet_conf_text = ''
  opts.each do |section, options|
    puppet_conf_text << "[#{section}]\n"
    options.each do |option, value|
      puppet_conf_text << "#{option}=#{value}\n"
    end
    puppet_conf_text << "\n"
  end
  logger.debug("setting config '#{puppet_conf_text}' on hosts #{hosts}")
  block_on hosts, opts do |host|
    puppet_conf_path = host.puppet['config']
    create_remote_file(host, puppet_conf_path, puppet_conf_text)
  end
end

#dev_builds_accessible?(url = ) ⇒ Boolean

Returns Whether Puppet’s internal builds are accessible from all the SUTs.

Returns:

  • (Boolean)

    Whether Puppet’s internal builds are accessible from all the SUTs



62
63
64
65
66
67
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 62

def dev_builds_accessible?(url = FOSS_DEFAULT_DOWNLOAD_URLS[:dev_builds_url])
  block_on hosts do |host|
    return false unless dev_builds_accessible_on?(host, url)
  end
  true
end

#dev_builds_accessible_on?(host, url = ) ⇒ Boolean

true for puppet amazon platfroms

Parameters:

  • A (Host)

    beaker host

Returns:

  • (Boolean)

    Whether Puppet’s internal builds are accessible from the host /



72
73
74
75
76
77
78
79
80
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 72

def dev_builds_accessible_on?(host, url = FOSS_DEFAULT_DOWNLOAD_URLS[:dev_builds_url])
  return true if host.host_hash[:template] =~ /^amazon-*/ && host.hostname =~ /.puppet.net$/

  # redhat-8-arm64 is provided from amazon
  return true if host.host_hash[:template] == 'redhat-8-arm64' && host.hostname =~ /.puppet.net$/

  result = on(host, %(curl --location -fI "#{url}"), accept_all_exit_codes: true)
  result.exit_code.zero?
end

#extract_repo_info_from(uri) ⇒ Hash{Symbol=>String}

Returns a hash containing the project name, repository path, and revision (defaults to HEAD)

Examples:

Usage

project = extract_repo_info_from '[email protected]:puppetlabs/SuperSecretSauce#what_is_justin_doing'

puts project[:name]
#=> 'SuperSecretSauce'

puts project[:rev]
#=> 'what_is_justin_doing'

Parameters:

  • uri (String)

    A uri in the format of <git uri>#<revision> the ‘git://`, `http://`, `https://`, and ssh (if cloning as the remote git user) protocols are valid for <git uri>

Returns:

  • (Hash{Symbol=>String})

    Returns a hash containing the project name, repository path, and revision (defaults to HEAD)



124
125
126
127
128
129
130
131
132
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 124

def extract_repo_info_from(uri)
  require 'pathname'
  project = {}
  repo, rev = uri.split('#', 2)
  project[:name] = Pathname.new(repo).basename('.git').to_s
  project[:path] = repo
  project[:rev]  = rev || 'HEAD'
  project
end

#find_git_repo_versions(host, path, repository) ⇒ Hash

Note:

This requires the helper methods:

  • Helpers#on

Returns Executes git describe on [host] and returns a Hash with the key of [repository] and value of the output from git describe.

Examples:

Getting multiple project versions

versions = [puppet_repo, facter_repo, hiera_repo].inject({}) do |vers, repo_info|
  vers.merge(find_git_repo_versions(host, '/opt/git-puppet-repos', repo_info) )
end

Parameters:

  • host (Host)

    An object implementing Hosts‘s interface.

  • path (String)

    The path on the remote [host] to the repository

  • repository (Hash{Symbol=>String})

    A hash representing repo info like that emitted by #extract_repo_info_from

Returns:

  • (Hash)

    Executes git describe on [host] and returns a Hash with the key of [repository] and value of the output from git describe.



166
167
168
169
170
171
172
173
174
175
176
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 166

def find_git_repo_versions(host, path, repository)
  logger.notify("\n  * Grab version for #{repository[:name]}")

  version = {}
  on host, "cd #{path}/#{repository[:name]} && " +
           'git describe || true' do
    version[repository[:name]] = stdout.chomp
  end

  version
end

#gem_command(host, type = 'aio') ⇒ Object



1390
1391
1392
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 1390

def gem_command(host, type = 'aio')
  get_command('gem', host, type)
end

#get_command(command_name, host, type = 'aio') ⇒ Object



1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 1374

def get_command(command_name, host, type = 'aio')
  if %w[aio git].include?(type)
    if host['platform'] =~ /windows/
      "env PATH=\"#{host['privatebindir']}:${PATH}\" cmd /c #{command_name}"
    else
      "env PATH=\"#{host['privatebindir']}:${PATH}\" #{command_name}"
    end
  else
    on(host, "which #{command_name}").stdout.chomp
  end
end

#get_latest_puppet_agent_build_from_url(url) ⇒ String

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.

Returns the latest puppet-agent version number from a given url.

Parameters:

Returns:

  • (String)

    version puppet-agent version number (e.g. 1.4.1) Empty string if none found.



821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 821

def get_latest_puppet_agent_build_from_url(url)
  require 'oga'
  require 'net/http'

  full_url = "#{url}/index_by_lastModified_reverse.html"
  response = Net::HTTP.get_response(URI(full_url))
  counter = 0

  # Redirect following
  while response.is_a?(Net::HTTPRedirection) && counter < 15
    response = Net::HTTP.get_response(URI.parse(Net::HTTP.get_response(URI(full_url))['location']))
    counter += 1
  end

  unless response.is_a?(Net::HTTPSuccess)
    raise "The URL for puppet-agent download, #{response.uri}, returned #{response.message} with #{response.code}"
  end

  document = Oga.parse_html(response.body)
  agents = document.xpath('//a[contains(@href, "puppet-agent")]')

  latest_match = agents.shift.attributes[0].value
  latest_match = agents.shift.attributes[0].value while (latest_match =~ /puppet-agent-\d(.*)/).nil?

  re = /puppet-agent-(.*)-/
  latest_match = latest_match.match re

  if latest_match
    latest_match[1]
  else
    ''
  end
end

#install_a_puppet_msi_on(hosts, opts) ⇒ 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.



669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 669

def install_a_puppet_msi_on(hosts, opts)
  block_on hosts do |host|
    link = msi_link_path(host, opts)
    msi_download_path = "#{host.system_temp_path}\\#{host['dist']}.msi"

    if host.is_cygwin?
      # NOTE: it is critical that -o be before -O on Windows
      proxy = opts[:package_proxy] ? "-x #{opts[:package_proxy]} " : ''
      on host, "curl #{proxy}--location --output \"#{msi_download_path}\" --remote-name #{link}"

      # Because the msi installer doesn't add Puppet to the environment path
      # Add both potential paths for simplicity
      # NOTE - this is unnecessary if the host has been correctly identified as 'foss' during set up
      puppetbin_path = '"/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/bin":"/cygdrive/c/Program Files/Puppet Labs/Puppet/bin"'
      on host, %( echo 'export PATH=$PATH:#{puppetbin_path}' > /etc/bash.bashrc )
    else
      webclient_proxy = opts[:package_proxy] ? "$webclient.Proxy = New-Object System.Net.WebProxy('#{opts[:package_proxy]}',$true); " : ''
      on host,
         powershell("$webclient = New-Object System.Net.WebClient; #{webclient_proxy}$webclient.DownloadFile('#{link}','#{msi_download_path}')")
    end

    opts = { debug: host[:pe_debug] || opts[:pe_debug] }
    install_msi_on(host, msi_download_path, {}, opts)

    configure_type_defaults_on(host)

    host.mkdir_p host['distmoduledir'] unless host.is_cygwin?
  end
end

#install_cert_on_windows(host, cert_name, cert) ⇒ Object

This method will install a pem file certificate on a windows host

Parameters:

  • host (Host)

    A host object

  • cert_name (String)

    The name of the pem file

  • cert (String)

    The contents of the certificate



1184
1185
1186
1187
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 1184

def install_cert_on_windows(host, cert_name, cert)
  create_remote_file(host, "C:\\Windows\\Temp\\#{cert_name}.pem", cert)
  on host, "certutil -v -addstore Root C:\\Windows\\Temp\\#{cert_name}.pem"
end

#install_from_git_on(host, path, repository, opts = {}) ⇒ Object Also known as: install_from_git

Note:

This assumes the target repository application can be installed via an install.rb ruby script.



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 220

def install_from_git_on(host, path, repository, opts = {})
  opts = { accept_all_exit_codes: true }.merge(opts)
  clone_git_repo_on host, path, repository, opts
  name = repository[:name]
  logger.notify("\n  * Install #{name} on the system")
  # The solaris ruby IPS package has bindir set to /usr/ruby/1.8/bin.
  # However, this is not the path to which we want to deliver our
  # binaries. So if we are using solaris, we have to pass the bin and
  # sbin directories to the install.rb
  target = "#{path}/#{name}"
  install_opts = ''
  install_opts = '--bindir=/usr/bin --sbindir=/usr/sbin' if host['platform'].include? 'solaris'

  on host,  "cd #{target} && " +
            'if [ -f install.rb ]; then ' +
            "ruby ./install.rb #{install_opts}; " +
            'else true; fi', opts
end

#install_packages_from_local_dev_repo(host, package_name) ⇒ Object

Note:

This method only works on redhat-like and debian-like hosts.

Note:

This method is paired to be run directly after #install_puppetlabs_dev_repo

Installs packages from the local development repository on the given host

Parameters:

  • host (Host)

    An object implementing Hosts‘s interface.

  • package_name (Regexp)

    The name of the package whose repository is being installed.



1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 1163

def install_packages_from_local_dev_repo(host, package_name)
  if host['platform'] =~ /debian|ubuntu/
    find_filename = '*.deb'
    find_command  = 'dpkg -i'
  elsif host['platform'] =~ /fedora|el|redhat|centos/
    find_filename = '*.rpm'
    find_command  = 'rpm -ivh'
  else
    raise "No repository installation step for #{host['platform']} yet..."
  end
  find_command = "find /root/#{package_name} -type f -name '#{find_filename}' -exec #{find_command} {} \\;"
  on host, find_command
  configure_type_defaults_on(host)
end

#install_packages_on(hosts, package_hash, options = {}) ⇒ Object

Installs packages on the hosts.

Parameters:

  • hosts (Array<Host>)

    Array of hosts to install packages to.

  • package_hash (Hash{Symbol=>Array<String,Array<String,String>>})

    Keys should be a symbol for a platform in PLATFORM_PATTERNS. Values should be an array of package names to install, or of two element arrays where a is the command we expect to find on the platform and a is the package name (when they are different).

  • options (Hash{Symbol=>Boolean}) (defaults to: {})

Options Hash (options):

  • :check_if_exists (Boolean)

    First check to see if command is present before installing package. (Default false)

Returns:

  • true



1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 1333

def install_packages_on(hosts, package_hash, options = {})
  platform_patterns = {
    redhat: /fedora|el-|centos/,
    debian: /debian|ubuntu/,
    debian_ruby18: /debian|ubuntu-lucid|ubuntu-precise/,
    solaris_10: /solaris-10/,
    solaris_11: /solaris-11/,
    windows: /windows/,
    eos: /^eos-/,
    sles: /sles/,
  }.freeze

  check_if_exists = options[:check_if_exists]
  Array(hosts).each do |host|
    package_hash.each do |platform_key, package_list|
      unless pattern = platform_patterns[platform_key]
        raise("Unknown platform '#{platform_key}' in package_hash")
      end
      next unless pattern.match(host['platform'])

      package_list.each do |cmd_pkg|
        if cmd_pkg.is_a?(Array)
          command, package = cmd_pkg
        else
          command = package = cmd_pkg
        end
        next unless !check_if_exists || !host.check_for_package(command)

        host.logger.notify("Installing #{package}")
        additional_switches = '--allow-unauthenticated' if platform_key == :debian
        host.install_package(package, additional_switches)
      end
    end
  end
  true
end

#install_puppet(opts = {}) ⇒ Object

Deprecated.

Use #install_puppet_on instead.



241
242
243
244
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 241

def install_puppet(opts = {})
  # send in the global hosts!
  install_puppet_on(hosts, opts)
end

#install_puppet_agent_from_dmg_on(hosts, opts) ⇒ 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.

Installs puppet-agent and dependencies from dmg on provided host(s).

Parameters:

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

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

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :puppet_agent_version (String)

    The version of Puppet Agent to install, defaults to latest

  • :mac_download_url (String)

    Url to download msi pattern of %url%/puppet-%version%.dmg

  • :puppet_collection (String)

    Defaults to ‘PC1’

Returns:

  • nil



779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 779

def install_puppet_agent_from_dmg_on(hosts, opts)
  opts[:puppet_collection] ||= 'PC1'
  opts[:puppet_collection] = opts[:puppet_collection].upcase if opts[:puppet_collection].match(/pc1/i)
  block_on hosts do |host|
    add_role(host, 'aio') # we are installing agent, so we want aio role

    variant, version, arch, codename = host['platform'].to_array

    if opts[:puppet_collection].match(/puppet\d*/)
      url = if opts[:puppet_collection].match(/-nightly$/)
              opts[:nightly_mac_download_url]
            else
              opts[:mac_download_url]
            end
      download_url = "#{url}/#{opts[:puppet_collection]}/#{version}/#{arch}"
    else
      download_url = "#{opts[:mac_download_url]}/#{version}/#{opts[:puppet_collection]}/#{arch}"
    end

    latest = get_latest_puppet_agent_build_from_url(download_url)

    agent_version = opts[:puppet_agent_version] || latest
    raise "no puppet-agent version specified or found on at #{download_url}" unless agent_version.length > 0

    pkg_name = "puppet-agent-#{agent_version}*"
    dmg_name = "puppet-agent-#{agent_version}-1.osx#{version}.dmg"
    on host, "curl --location --remote-name #{download_url}/#{dmg_name}"

    host.install_package(pkg_name)

    configure_type_defaults_on(host)
  end
end

#install_puppet_agent_from_msi_on(hosts, opts) ⇒ Object

Note:

on windows, the :ruby_arch host parameter can determine in addition

Installs Puppet Agent and dependencies from msi on provided host(s).

to other settings whether the 32 or 64bit install is used

Parameters:

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

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

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :puppet_agent_version (String)

    The version of Puppet Agent to install

  • :win_download_url (String)

    The url to download puppet from



633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 633

def install_puppet_agent_from_msi_on(hosts, opts)
  block_on hosts do |host|
    add_role(host, 'aio') # we are installing agent, so we want aio role
    is_config_32 = true == (host['ruby_arch'] == 'x86') || host['install_32'] || opts['install_32']
    should_install_64bit = host.is_x86_64? && !is_config_32
    arch = should_install_64bit ? 'x64' : 'x86'

    # If we don't specify a version install the latest MSI for puppet-agent
    host['dist'] = if opts[:puppet_agent_version]
                     "puppet-agent-#{opts[:puppet_agent_version]}-#{arch}"
                   else
                     "puppet-agent-#{arch}-latest"
                   end

    install_a_puppet_msi_on(host, opts)
  end
end

#install_puppet_agent_on(hosts, opts = {}) ⇒ Object

Note:

This will attempt to add a repository for apt.puppetlabs.com on Debian or Ubuntu machines, or yum.puppetlabs.com on EL or Fedora machines, then install the package ‘puppet-agent’.

Install Puppet Agent or Puppet as a gem based on specified hosts using provided options

Examples:

will install puppet-agent 1.1.0 from native puppetlabs provided packages wherever possible and will fail over to gem installing latest puppet

install_puppet_agent_on(hosts, {
  :puppet_agent_version          => '1.1.0',
  :default_action                => 'gem_install',
 })

Will install latest packages on Enterprise Linux, Debian based distros, Windows, OSX and fail hard on all othere platforms.

install_puppet_agent_on(hosts)

Parameters:

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

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

  • opts (Hash{Symbol=>String}) (defaults to: {})

Options Hash (opts):

  • :puppet_agent_version (String)

    Version of puppet to download

  • :puppet_gem_version (String)

    Version of puppet to install via gem if no puppet-agent package is available

  • :mac_download_url (String)

    Url to download msi pattern of %url%/puppet-agent-%version%.msi

  • :win_download_url (String)

    Url to download dmg pattern of %url%/puppet-agent-%version%.msi

  • :puppet_collection (String)

    Collection to install from. Defaults to ‘pc1’ (contains the latest puppet 4). Other valid options are ‘puppet’ (for the latest release), ‘puppet5’ (for the latest puppet 5), or ‘puppet6’ (for the latest puppet 6). Only works for platforms that rely on repos.

  • :run_in_parallel (Boolean)

    Whether to run on each host in parallel.

Returns:

  • nil

Raises:

  • (StandardError)

    When encountering an unsupported platform by default, or if gem cannot be found when default_action => ‘gem_install’

  • (FailTest)

    When error occurs during the actual installation process



375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 375

def install_puppet_agent_on(hosts, opts = {})
  opts = sanitize_opts(opts)
  opts[:puppet_agent_version] ||= opts[:version] # backwards compatability with old parameter name
  opts[:puppet_collection] ||= puppet_collection_for(:puppet_agent, opts[:puppet_agent_version]) || 'pc1'

  # the collection names are case sensitive
  opts[:puppet_collection] = opts[:puppet_collection].downcase

  run_in_parallel = run_in_parallel? opts, @options, 'install'
  block_on hosts, { run_in_parallel: run_in_parallel } do |host|
    # AIO refers to FOSS agents that contain puppet 4+, that is, puppet-agent packages
    # in the 1.x series, or the 5.x series, or later. Previous versions are not supported,
    # so 'aio' is the only role that makes sense here.
    add_role(host, 'aio')
    package_name = nil

    # If inside the Puppet VPN, install from development builds.
    if opts[:puppet_agent_version] && opts[:puppet_agent_version] != 'latest' && dev_builds_accessible_on?(
      host, opts[:dev_builds_url]
    )
      install_puppet_agent_from_dev_builds_on(host, opts[:puppet_agent_version])
    else
      if opts[:puppet_agent_version] == 'latest'
        opts[:puppet_collection] += '-nightly' unless opts[:puppet_collection].end_with? '-nightly'

        # Since we have modified the collection, we don't want to pass `latest`
        # in to `install_package` as the version. That'll fail. Instead, if
        # we pass `nil`, `install_package` will just install the latest available
        # package version from the enabled repo.
        opts.delete(:puppet_agent_version)
        opts.delete(:version)
      end

      case host['platform']
      when /amazon|el-|redhat|fedora|sles|centos/
        package_name = 'puppet-agent'
        package_name << "-#{opts[:puppet_agent_version]}" if opts[:puppet_agent_version]
      when /debian|ubuntu/
        package_name = 'puppet-agent'
        if opts[:puppet_agent_version]
          package_name << "=#{opts[:puppet_agent_version]}-1#{host['platform'].codename}"
        end
      when /windows/
        install_puppet_agent_from_msi_on(host, opts)
      when /osx/
        install_puppet_agent_from_dmg_on(host, opts)
      when /freebsd/
        install_puppet_from_freebsd_ports_on(host, opts)
      when /archlinux/
        install_puppet_from_pacman_on(host, opts)
      else
        if opts[:default_action] == 'gem_install'
          opts[:version] = opts[:puppet_gem_version]
          install_puppet_from_gem_on(host, opts)
          on host, "echo '' >> #{host.puppet['hiera_config']}"
        else
          raise 'install_puppet_agent_on() called for unsupported ' +
                "platform '#{host['platform']}' on '#{host.name}'"
        end
      end

      if package_name
        install_puppetlabs_release_repo(host, opts[:puppet_collection], opts)
        host.install_package(package_name)
      end
    end
  end
end

#install_puppet_from_deb_on(hosts, opts) ⇒ Object Also known as: install_puppet_from_deb

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.

Installs Puppet and dependencies from deb on provided host(s).

Parameters:

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

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

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :version (String)

    The version of Puppet to install, if nil installs latest version

  • :facter_version (String)

    The version of Facter to install, if nil installs latest version

  • :hiera_version (String)

    The version of Hiera to install, if nil installs latest version

Returns:

  • nil



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 537

def install_puppet_from_deb_on(hosts, opts)
  block_on hosts do |host|
    install_puppetlabs_release_repo(host)

    host.install_package("facter=#{opts[:facter_version]}-1puppetlabs1") if opts[:facter_version]

    host.install_package("hiera=#{opts[:hiera_version]}-1puppetlabs1") if opts[:hiera_version]

    if opts[:version]
      host.install_package("puppet-common=#{opts[:version]}-1puppetlabs1")
      host.install_package("puppet=#{opts[:version]}-1puppetlabs1")
    else
      host.install_package('puppet')
    end
    configure_type_defaults_on(host)
  end
end

#install_puppet_from_dmg_on(hosts, opts) ⇒ Object Also known as: install_puppet_from_dmg

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.

Installs Puppet and dependencies from dmg on provided host(s).

Parameters:

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

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

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :version (String)

    The version of Puppet to install

  • :puppet_version (String)

    The version of puppet-agent to install

  • :facter_version (String)

    The version of Facter to install

  • :hiera_version (String)

    The version of Hiera to install

  • :mac_download_url (String)

    Url to download msi pattern of %url%/puppet-%version%.msi

Returns:

  • nil



733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 733

def install_puppet_from_dmg_on(hosts, opts)
  block_on hosts do |host|
    # install puppet-agent if puppet version > 4.0 OR not puppet version is provided
    if (opts[:version] && !version_is_less(opts[:version], '4.0.0')) || !opts[:version]
      if opts[:puppet_agent_version].nil?
        raise 'You must specify the version of puppet-agent you ' +
              'want to install if you want to install Puppet 4.0 ' +
              'or greater on OSX'
      end

      install_puppet_agent_from_dmg_on(host, opts)

    else
      puppet_ver = opts[:version] || 'latest'
      facter_ver = opts[:facter_version] || 'latest'
      hiera_ver = opts[:hiera_version] || 'latest'

      raise "You need to specify versions for OSX host\n eg. install_puppet({:version => '3.6.2',:facter_version => '2.1.0',:hiera_version  => '1.3.4',})" if [
        puppet_ver, facter_ver, hiera_ver,
      ].include?(nil)

      on host, "curl --location --remote-name #{opts[:mac_download_url]}/puppet-#{puppet_ver}.dmg"
      on host, "curl --location --remote-name #{opts[:mac_download_url]}/facter-#{facter_ver}.dmg"
      on host, "curl --location --remote-name #{opts[:mac_download_url]}/hiera-#{hiera_ver}.dmg"

      host.install_package("puppet-#{puppet_ver}")
      host.install_package("facter-#{facter_ver}")
      host.install_package("hiera-#{hiera_ver}")

      configure_type_defaults_on(host)
    end
  end
end

#install_puppet_from_freebsd_ports_on(hosts, opts) ⇒ Object Also known as: install_puppet_from_freebsd_ports

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.

Installs Puppet and dependencies from FreeBSD ports

Parameters:

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

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

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :version (String)

    The version of Puppet to install (shows warning)

Returns:

  • nil



708
709
710
711
712
713
714
715
716
717
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 708

def install_puppet_from_freebsd_ports_on(hosts, opts)
  if opts[:version]
    logger.warn "If you wish to choose a specific Puppet version, use `install_puppet_from_gem_on('~> 3.*')`"
  end

  block_on hosts do |host|
    host.install_package('sysutils/puppet7')
    configure_type_defaults_on(host)
  end
end

#install_puppet_from_gem_on(hosts, opts) ⇒ Object Also known as: install_puppet_from_gem, install_puppet_agent_from_gem_on

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.

Installs Puppet and dependencies from gem on provided host(s)

Parameters:

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

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

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :version (String)

    The version of Puppet to install, if nil installs latest

  • :facter_version (String)

    The version of Facter to install, if nil installs latest

  • :hiera_version (String)

    The version of Hiera to install, if nil installs latest

Returns:

  • nil

Raises:

  • (StandardError)

    if gem does not exist on target host



908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 908

def install_puppet_from_gem_on(hosts, opts)
  block_on hosts do |host|
    # There are a lot of special things to do for Solaris and Solaris 10.
    # This is easier than checking host['platform'] every time.
    is_solaris10 = host['platform'] =~ /solaris-10/
    is_solaris = host['platform'] =~ /solaris/

    # Hosts may be provisioned with csw but pkgutil won't be in the
    # PATH by default to avoid changing the behavior for Puppet's tests
    on host, 'ln -s /opt/csw/bin/pkgutil /usr/bin/pkgutil' if is_solaris10

    # Solaris doesn't necessarily have this, but gem needs it
    on host, 'mkdir -p /var/lib' if is_solaris

    unless host.check_for_command('gem')
      gempkg = case host['platform']
               when /solaris-11/                   then 'ruby-18'
               when /ubuntu-14/                    then 'ruby'
               when /solaris-10|ubuntu|debian|el-/ then 'rubygems'
               when /openbsd/ then 'ruby'
               else
                 raise 'install_puppet() called with default_action ' +
                       "'gem_install' but program `gem' is " +
                       "not installed on #{host.name}"
               end

      host.install_package gempkg
    end

    # Link 'gem' to /usr/bin instead of adding /opt/csw/bin to PATH.
    on host, 'ln -s /opt/csw/bin/gem /usr/bin/gem' if is_solaris10

    if host['platform'] =~ /debian|ubuntu|solaris/
      gem_env = YAML.load(on(host, 'gem environment').stdout)
      gem_paths_array = gem_env['RubyGems Environment'].find { |h| h['GEM PATHS'] != nil }['GEM PATHS']
      path_with_gem = 'export PATH=' + gem_paths_array.join(':') + ':${PATH}'
      on host, "echo '#{path_with_gem}' >> ~/.bashrc"
    end

    gemflags = '--no-document --no-format-executable'

    on host, "gem install facter -v'#{opts[:facter_version]}' #{gemflags}" if opts[:facter_version]

    on host, "gem install hiera -v'#{opts[:hiera_version]}' #{gemflags}" if opts[:hiera_version]

    ver_cmd = opts[:version] ? "-v '#{opts[:version]}'" : ''
    on host, "gem install puppet #{ver_cmd} #{gemflags}"

    # Similar to the treatment of 'gem' above.
    # This avoids adding /opt/csw/bin to PATH.
    if is_solaris
      gem_env = YAML.load(on(host, 'gem environment').stdout)
      # This is the section we want - this has the dir where gem executables go.
      env_sect = 'EXECUTABLE DIRECTORY'
      # Get the directory where 'gem' installs executables.
      # On Solaris 10 this is usually /opt/csw/bin
      gem_exec_dir = gem_env['RubyGems Environment'].find { |h| !h[env_sect].nil? }[env_sect]

      on host, "ln -s #{gem_exec_dir}/hiera /usr/bin/hiera"
      on host, "ln -s #{gem_exec_dir}/facter /usr/bin/facter"
      on host, "ln -s #{gem_exec_dir}/puppet /usr/bin/puppet"
    end

    # A gem install might not necessarily create these
    %w[confdir logdir codedir].each do |key|
      host.mkdir_p host.puppet[key] if host.puppet.has_key?(key)
    end

    configure_type_defaults_on(host)
  end
end

#install_puppet_from_msi_on(hosts, opts) ⇒ Object Also known as: install_puppet_from_msi

Note:

on windows, the :ruby_arch host parameter can determine in addition

Installs Puppet and dependencies from msi on provided host(s).

to other settings whether the 32 or 64bit install is used

Parameters:

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

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

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :version (String)

    The version of Puppet to install

  • :puppet_agent_version (String)

    The version of the puppet-agent package to install, required if version is 4.0.0 or greater

  • :win_download_url (String)

    The url to download puppet from



568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 568

def install_puppet_from_msi_on(hosts, opts)
  block_on hosts do |host|
    version = opts[:version]

    if version && !version_is_less(version, '4.0.0')
      if opts[:puppet_agent_version].nil?
        raise 'You must specify the version of puppet agent you ' +
              'want to install if you want to install Puppet 4.0 ' +
              'or greater on Windows'
      end

      opts[:version] = opts[:puppet_agent_version]
      install_puppet_agent_from_msi_on(host, opts)

    else
      compute_puppet_msi_name(host, opts)
      install_a_puppet_msi_on(host, opts)

    end
    configure_type_defaults_on(host)
  end
end

#install_puppet_from_openbsd_packages_on(hosts, opts) ⇒ 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.

Installs Puppet and dependencies from OpenBSD packages

Parameters:

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

    The host to install packages on

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :version (String)

    The version of Puppet to install (shows warning)

Returns:

  • nil



863
864
865
866
867
868
869
870
871
872
873
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 863

def install_puppet_from_openbsd_packages_on(hosts, opts)
  if opts[:version]
    logger.warn "If you wish to choose a specific Puppet version, use `install_puppet_from_gem_on('~> 3.*')`"
  end

  block_on hosts do |host|
    host.install_package('puppet')

    configure_type_defaults_on(host)
  end
end

#install_puppet_from_pacman_on(hosts, opts) ⇒ 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.

Installs Puppet and dependencies from Arch Linux Pacman

Parameters:

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

    The host to install packages on

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :version (String)

    The version of Puppet to install (shows warning)

Returns:

  • nil



883
884
885
886
887
888
889
890
891
892
893
894
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 883

def install_puppet_from_pacman_on(hosts, opts)
  if opts[:version]
    # Arch is rolling release, only the latest package versions are supported
    logger.warn "If you wish to choose a specific Puppet version, use `install_puppet_from_gem_on('~> 3.*')`"
  end

  block_on hosts do |host|
    host.install_package('puppet')

    configure_type_defaults_on(host)
  end
end

#install_puppet_from_rpm_on(hosts, opts) ⇒ Object Also known as: install_puppet_from_rpm

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.

Installs Puppet and dependencies using rpm on provided host(s).

Parameters:

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

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

  • opts (Hash{Symbol=>String})

    An options hash

Options Hash (opts):

  • :version (String)

    The version of Puppet to install, if nil installs latest version

  • :facter_version (String)

    The version of Facter to install, if nil installs latest version

  • :hiera_version (String)

    The version of Hiera to install, if nil installs latest version

  • :release (String)

    The major release of the OS

  • :family (String)

    The OS family (one of ‘el’ or ‘fedora’)

Returns:

  • nil



505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 505

def install_puppet_from_rpm_on(hosts, opts)
  block_on hosts do |host|
    if opts[:puppet_collection] && opts[:puppet_collection].match(/puppet\d*/)
      install_puppetlabs_release_repo(host, opts[:puppet_collection], opts)
    elsif host[:type] == 'aio'
      install_puppetlabs_release_repo(host, 'pc1', opts)
    else
      install_puppetlabs_release_repo(host, nil, opts)
    end

    host.install_package("facter-#{opts[:facter_version]}") if opts[:facter_version]

    host.install_package("hiera-#{opts[:hiera_version]}") if opts[:hiera_version]

    puppet_pkg = opts[:version] ? "puppet-#{opts[:version]}" : 'puppet'
    host.install_package("#{puppet_pkg}")
    configure_type_defaults_on(host)
  end
end

#install_puppet_on(hosts, opts = options) ⇒ Object

Note:

This will attempt to add a repository for apt.puppetlabs.com on Debian or Ubuntu machines, or yum.puppetlabs.com on EL or Fedora machines, then install the package ‘puppet’ or ‘puppet-agent’.

Install FOSS based on specified hosts using provided options

Examples:

will install puppet 3.6.1 from native puppetlabs provided packages wherever possible and will fail over to gem installation when impossible

install_puppet_on(hosts, {
  :version          => '3.6.1',
  :facter_version   => '2.0.1',
  :hiera_version    => '1.3.3',
  :default_action   => 'gem_install',
 })

will install puppet 4 from native puppetlabs provided puppet-agent 1.x package wherever possible and will fail over to gem installation when impossible

install_puppet({
  :version              => '4',
  :default_action       => 'gem_install'
})

will install puppet 4.1.0 from native puppetlabs provided puppet-agent 1.1.0 package wherever possible and will fail over to gem installation when impossible

install_puppet({
  :version              => '4.1.0',
  :puppet_agent_version => '1.1.0',
  :default_action       => 'gem_install'
})

Will install latest packages on Enterprise Linux and Debian based distros and fail hard on all othere platforms.

install_puppet_on(hosts)

Parameters:

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

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

  • opts (Hash{Symbol=>String}) (defaults to: options)

Options Hash (opts):

  • :version (String)

    Version of puppet to download

  • :puppet_agent_version (String)

    Version of puppet agent to download

  • :mac_download_url (String)

    Url to download msi pattern of %url%/puppet-%version%.msi

  • :win_download_url (String)

    Url to download dmg pattern of %url%/(puppet|hiera|facter)-%version%.msi

  • :run_in_parallel (Boolean)

    Whether to install on all hosts in parallel. Defaults to false.

Returns:

  • nil

Raises:

  • (StandardError)

    When encountering an unsupported platform by default, or if gem cannot be found when default_action => ‘gem_install’

  • (FailTest)

    When error occurs during the actual installation process



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 289

def install_puppet_on(hosts, opts = options)
  opts = sanitize_opts(opts)

  # If version isn't specified assume the latest in the 3.x series
  if opts[:version] and !version_is_less(opts[:version], '4.0.0')
    # backwards compatability
    opts[:puppet_agent_version] ||= opts[:version]
    install_puppet_agent_on(hosts, opts)
  else
    # Use option specified in the method call, otherwise check whether the global
    # run_in_parallel option includes install
    run_in_parallel = run_in_parallel? opts, @options, 'install'
    block_on hosts, { run_in_parallel: run_in_parallel } do |host|
      if host['platform'] =~ /(el|fedora)-(\d+)/
        family = ::Regexp.last_match(1)
        relver = ::Regexp.last_match(2)
        install_puppet_from_rpm_on(host, opts.merge(release: relver, family: family))
      elsif host['platform'] =~ /(ubuntu|debian)/
        install_puppet_from_deb_on(host, opts)
      elsif host['platform'] =~ /windows/
        relver = opts[:version]
        install_puppet_from_msi_on(host, opts)
      elsif host['platform'] =~ /osx/
        install_puppet_from_dmg_on(host, opts)
      elsif host['platform'] =~ /openbsd/
        install_puppet_from_openbsd_packages_on(host, opts)
      elsif host['platform'] =~ /freebsd/
        install_puppet_from_freebsd_ports_on(host, opts)
      elsif host['platform'] =~ /archlinux/
        install_puppet_from_pacman_on(host, opts)
      else
        unless opts[:default_action] == 'gem_install'
          raise "install_puppet() called for unsupported platform '#{host['platform']}' on '#{host.name}'"
        end

        opts[:version] ||= '~> 3.x'
        install_puppet_from_gem_on(host, opts)

      end

      host[:version] = opts[:version]

      # Certain install paths may not create the config dirs/files needed
      host.mkdir_p host['puppetpath'] unless host[:type] =~ /aio/

      if (host['platform'] =~ /windows/) and !host.is_cygwin?
        # Do nothing
      else
        on host, "echo '' >> #{host.puppet['hiera_config']}"
      end
    end
  end

  nil
end

#install_puppetlabs_dev_repo(host, package_name, build_version, repo_configs_dir = nil, opts = options) ⇒ Object

Note:

This method only works on redhat-like and debian-like hosts.

Install development repository on the given host. This method pushes all repository information including package files for the specified package_name to the host and modifies the repository configuration file to point at the new repository. This is particularly useful for installing development packages on hosts that can’t access the builds server.

Parameters:

  • host (Host)

    An object implementing Hosts‘s interface.

  • package_name (String)

    The name of the package whose repository is being installed.

  • build_version (String)

    A string identifying the output of a packaging job for use in looking up repository directory information

  • repo_configs_dir (String) (defaults to: nil)

    A local directory where repository files will be stored as an intermediate step before pushing them to the given host.

  • opts (Hash{Symbol=>String}) (defaults to: options)

    Options to alter execution.

Options Hash (opts):

  • :dev_builds_url (String)

    The URL to look for dev builds.



1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 1127

def install_puppetlabs_dev_repo(host, package_name, build_version,
                                repo_configs_dir = nil,
                                opts = options)
  variant, version, arch, codename = host['platform'].to_array
  if variant !~ /^(amazon|fedora|el|redhat|centos|debian|ubuntu|sles)$/
    raise "No repository installation step for #{variant} yet..."
  end

  repo_configs_dir ||= 'tmp/repo_configs'

  platform_configs_dir = File.join(repo_configs_dir, variant)
  opts = sanitize_opts(opts)

  # some of the uses of dev_builds_url below can't include protocol info,
  # plus this opens up possibility of switching the behavior on provided
  # url type
  _, protocol, hostname = opts[:dev_builds_url].partition %r{.*://}
  dev_builds_url = protocol + hostname
  dev_builds_url = opts[:dev_builds_url] if variant =~ /^(amazon|fedora|el|redhat|centos)$/

  install_repo_configs(host, dev_builds_url, package_name,
                       build_version, platform_configs_dir)

  configure_type_defaults_on(host)
end

#install_puppetlabs_release_repo_on(hosts, repo = nil, opts = options) ⇒ Object Also known as: install_puppetlabs_release_repo

Note:

This method only works on redhat-like and debian-like hosts.

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

Parameters:

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

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



989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 989

def install_puppetlabs_release_repo_on(hosts, repo = nil, opts = options)
  block_on hosts do |host|
    variant, version, arch, codename = host['platform'].to_array
    repo_name = repo || opts[:puppet_collection] || 'puppet'
    opts = sanitize_opts(opts)

    case variant
    when /^(amazon|fedora|el|redhat|centos|sles)$/
      variant_url_value = (%w[redhat centos].include?(::Regexp.last_match(1)) ? 'el' : ::Regexp.last_match(1))
      if repo_name.match(/puppet\d*/)
        url = if repo_name.match(/-nightly$/)
                opts[:nightly_yum_repo_url]
              else
                opts[:release_yum_repo_url]
              end
        remote = format('%s/%s-release-%s-%s.noarch.rpm', url, repo_name, variant_url_value, version)
      else
        remote = format('%s/%s-release-%s-%s.noarch.rpm', opts[:release_yum_repo_url], repo_name,
                        variant_url_value, version)
      end

      # 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|
          on host, "wget -O /tmp/#{gpg_key} https://yum.puppet.com/RPM-GPG-KEY-#{gpg_key}"
          on host, "rpm --import /tmp/#{gpg_key}"
          on host, "rm -f /tmp/#{gpg_key}"
        end
      end

      opts[:package_proxy] ||= false
      host.install_package_with_rpm(remote, '--replacepkgs',
                                    { package_proxy: opts[:package_proxy] })

    when /^(debian|ubuntu)$/
      if repo_name.match(/puppet\d*/)
        url = if repo_name.match(/-nightly$/)
                opts[:nightly_apt_repo_url]
              else
                opts[:release_apt_repo_url]
              end
        remote = format('%s/%s-release-%s.deb', url, repo_name, codename)
      else
        remote = format('%s/%s-release-%s.deb', opts[:release_apt_repo_url], repo_name, codename)
      end

      on host, "wget -O /tmp/puppet.deb #{remote}"
      on host, 'dpkg -i --force-all /tmp/puppet.deb'
      on host, 'apt-get update'
    else
      raise "No repository installation step for #{variant} yet..."
    end
    configure_type_defaults_on(host)
  end
end

#install_puppetserver_on(host, opts = {}) ⇒ Object

Install puppetserver on the target host from released repos, nightlies, or Puppet’s internal build servers.

The default behavior is to install the latest release of puppetserver from the ‘puppet’ official repo.

Parameters:

  • host (Host)

    A beaker host

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :version (String)

    Specific puppetserver version. If set, this overrides all other options and installs the specific version from Puppet’s internal build servers or Puppet’s public release servers. If this version of puppetserver does not exist, the install attempt will fail.

  • :nightlies (Boolean)

    Whether to install from nightlies. Defaults to false.

  • :release_stream (String)

    Which release stream to install repos from. Defaults to ‘puppet’, which installs the latest released version. Other valid values are puppet5, puppet6.

  • :nightly_builds_url (String)

    Custom nightly builds URL. Defaults to :nightly_builds_url.

  • :nightly_yum_builds_url (String)

    Custom nightly builds URL for yum. Defaults to :nightly_yum_repo_url or a custom defined :nightly_builds_url

  • :apt_nightly_builds_url (String)

    Custom nightly builds URL for apt. Defaults to :nightly_builds_url or a custom defined :nightly_builds_url

  • :dev_builds_url (String)

    Custom internal builds URL. Defaults to DEFAULT_DEV_BUILDS_URL.



1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 1216

def install_puppetserver_on(host, opts = {})
  opts = sanitize_opts(opts)

  # Default to installing latest
  opts[:version] ||= 'latest'

  # If inside the Puppet VPN, install from development builds.
  if opts[:version] && opts[:version] != 'latest' && dev_builds_accessible_on?(host, opts[:dev_builds_url])
    build_yaml_uri = %(#{opts[:dev_builds_url]}/puppetserver/#{opts[:version]}/artifacts/#{opts[:version]}.yaml)
    return install_from_build_data_url('puppetserver', build_yaml_uri, host)
  end

  # Determine the release stream's name, for repo selection. The default
  # is 'puppet', which installs the latest release. Other valid values
  # are 'puppet5' or 'puppet6'.
  release_stream = opts[:release_stream] || 'puppet'

  # Installing a release repo will call configure_type_defaults_on,
  # which will try and fail to add PE defaults by default. This is a
  # FOSS install method, so we don't want that. Set the type to AIO,
  # which refers to FOSS with puppet 4+ (note that a value of `:foss`
  # here would be incorrect - that refers to FOSS puppet 3 only).
  host[:type] = :aio

  if opts[:version] == 'latest'
    release_stream += '-nightly' if opts[:nightlies] && !(release_stream.end_with? '-nightly')

    # Since we have modified the collection, we don't want to pass `latest`
    # in to `install_package` as the version. That'll fail. Instead, if
    # we pass `nil`, `install_package` will just install the latest available
    # package version from the enabled repo.
    opts.delete(:version)
  end

  # We have to do some silly version munging if we're on a deb-based platform
  case host['platform']
  when /debian|ubuntu/
    opts[:version] = "#{opts[:version]}-1#{host['platform'].codename}" if opts[:version]
  end

  install_puppetlabs_release_repo_on(host, release_stream, opts)
  install_package(host, 'puppetserver', opts[:version])

  logger.notify("Installed puppetserver version #{puppetserver_version_on(host)} on #{host}")
end

#install_repo_configs(host, buildserver_url, package_name, build_version, copy_dir) ⇒ Object

Installs the repo configs on a given host

Parameters:

  • host (Beaker::Host)

    Host to install configs on

  • buildserver_url (String)

    URL of the buildserver

  • package_name (String)

    Name of the package

  • build_version (String)

    Version of the package

  • copy_dir (String)

    Local directory to fetch files into & SCP out of

Returns:

  • nil



1059
1060
1061
1062
1063
1064
1065
1066
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 1059

def install_repo_configs(host, buildserver_url, package_name, build_version, copy_dir)
  repo_filename = host.repo_filename(package_name, build_version)
  repo_config_folder_url = format('%s/%s/%s/repo_configs/%s/', buildserver_url, package_name, build_version,
                                  host.repo_type)

  repo_config_url = "#{repo_config_folder_url}/#{repo_filename}"
  install_repo_configs_from_url(host, repo_config_url, copy_dir)
end

#install_repo_configs_from_url(host, repo_config_url, copy_dir = nil) ⇒ Object

Installs the repo configs on a given host

Parameters:

  • host (Beaker::Host)

    Host to install configs on

  • repo_config_url (String)

    URL to the repo configs

  • copy_dir (String) (defaults to: nil)

    Local directory to fetch files into & SCP out of

Returns:

  • nil



1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 1075

def install_repo_configs_from_url(host, repo_config_url, copy_dir = nil)
  copy_dir ||= Dir.mktmpdir
  repoconfig_filename = File.basename(repo_config_url)
  repoconfig_folder   = File.dirname(repo_config_url)

  repo = fetch_http_file(
    repoconfig_folder,
    repoconfig_filename,
    copy_dir,
  )

  if host['platform'].variant =~ /^(ubuntu|debian)$/
    # Bypass signing checks on this repo and its packages
    original_contents = File.read(repo)
    logger.debug 'INFO original repo contents:'
    logger.debug original_contents
    contents = original_contents.gsub(/^deb http/, 'deb [trusted=yes] http')
    logger.debug 'INFO new repo contents:'
    logger.debug contents

    File.write(repo, contents)
  end

  to_path = host.package_config_dir
  scp_to(host, repo, to_path)

  on(host, 'apt-get update') if host['platform'] =~ /ubuntu-|debian-/
  nil
end

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.



652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 652

def msi_link_path(host, opts)
  if opts[:puppet_collection] && opts[:puppet_collection].match(/puppet\d*/)
    url = if opts[:puppet_collection].match(/-nightly$/)
            opts[:nightly_win_download_url]
          else
            opts[:win_download_url]
          end
    link = "#{url}/#{opts[:puppet_collection]}/#{host['dist']}.msi"
  else
    link = "#{opts[:win_download_url]}/#{host['dist']}.msi"
  end
  raise "Puppet MSI at #{link} does not exist!" unless link_exists?(link)

  link
end

#remove_puppet_on(hosts) ⇒ Object

Ensures Puppet and dependencies are no longer installed on host(s).

Parameters:

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

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

Returns:

  • nil



1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 1269

def remove_puppet_on(hosts)
  block_on hosts do |host|
    cmdline_args = ''
    # query packages
    case host[:platform]
    when /ubuntu/
      pkgs = on(host, "dpkg-query -l  | awk '{print $2}' | grep -E '(^pe-|puppet)'",
                acceptable_exit_codes: [0, 1]).stdout.chomp.split(/\n+/)
    when /aix|sles|el|redhat|centos|oracle|scientific/
      pkgs = on(host, "rpm -qa  | grep -E '(^pe-|puppet)'",
                acceptable_exit_codes: [0, 1]).stdout.chomp.split(/\n+/)
    when /solaris-10/
      cmdline_args = '-a noask'
      pkgs = on(host, "pkginfo | egrep '(^pe-|puppet)' | cut -f2 -d ' '",
                acceptable_exit_codes: [0, 1]).stdout.chomp.split(/\n+/)
    when /solaris-11/
      pkgs = on(host, "pkg list | egrep '(^pe-|puppet)' | awk '{print $1}'",
                acceptable_exit_codes: [0, 1]).stdout.chomp.split(/\n+/)
    else
      raise 'remove_puppet_on() called for unsupported ' +
            "platform '#{host['platform']}' on '#{host.name}'"
    end

    # uninstall packages
    host.uninstall_package(pkgs.join(' '), cmdline_args) if pkgs.length > 0

    if host[:platform] =~ /solaris-11/
      # FIXME: This leaves things in a state where Puppet Enterprise (3.x) cannot be cleanly installed
      #        but is required to put things in a state that puppet-agent can be installed
      # extra magic for expunging left over publisher
      publishers = ['puppetlabs.com', 'com.puppetlabs']
      publishers.each do |publisher|
        # First, try to remove the publisher altogether
        next unless on(host, "pkg publisher #{publisher}",
                       acceptable_exit_codes: [0, 1]).exit_code == 0 && (on(host, "pkg unset-publisher #{publisher}",
                                                                            acceptable_exit_codes: [0, 1]).exit_code == 1)

        # If that doesn't work, we're in a non-global zone and the
        # publisher is from a global zone. As such, just remove any
        # references to the non-global zone uri.
        on(host, "pkg set-publisher -G '*' #{publisher}", acceptable_exit_codes: [0, 1])
      end
    end

    # delete any residual files
    result = on(host, 'find / -name "*puppet*" -print | xargs rm -rf', accept_all_exit_codes: true)
    unless result.exit_code == 0
      logger.notify("Attempt to clean residual puppet files errored, but can maybe be ignored.\n #{result.stderr}")
    end
  end
end

#ruby_command(host) ⇒ Object



1370
1371
1372
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 1370

def ruby_command(host)
  "env PATH=\"#{host['privatebindir']}:${PATH}\" ruby"
end

#sanitize_opts(opts) ⇒ Hash

Merge given options with our default options in a consistent way This will remove any nil values so that we always have a set default.

Parameters:

  • the (Hash)

    original options to be merged with the default options

Returns:

  • (Hash)

    The finalized set of options



40
41
42
43
44
45
46
47
48
49
# File 'lib/beaker-puppet/install_utils/foss_utils.rb', line 40

def sanitize_opts(opts)
  # If any of the nightly urls are not set, but the main `:nightly_builds_url`
  # is set, we should overwrite anything not set.
  opts[:nightly_apt_repo_url]     ||= opts[:nightly_builds_url]
  opts[:nightly_yum_repo_url]     ||= opts[:nightly_builds_url]
  opts[:nightly_win_download_url] ||= opts[:nightly_builds_url]
  opts[:nightly_mac_download_url] ||= opts[:nightly_builds_url]

  FOSS_DEFAULT_DOWNLOAD_URLS.merge(opts.reject { |k, v| v.nil? })
end