Module: Beaker::DSL::InstallUtils
- Included in:
- Beaker::DSL
- Defined in:
- lib/beaker/dsl/install_utils.rb
Overview
This module contains methods to help cloning, extracting git info, ordering of Puppet packages, and installing ruby projects that contain an ‘install.rb` script.
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=='
Instance Method Summary collapse
-
#deploy_frictionless_to_master(host) ⇒ Object
private
Classify the master so that it can deploy frictionless packages for a given host.
-
#do_higgs_install(host, opts) ⇒ Object
private
Perform a Puppet Enterprise Higgs install up until web browser interaction is required, runs on linux hosts only.
-
#do_install(hosts, opts = {}) ⇒ Object
private
Perform a Puppet Enterprise upgrade or install.
-
#extract_repo_info_from(uri) ⇒ Hash{Symbol=>String}
Returns a hash containing the project name, repository path, and revision (defaults to HEAD).
-
#fetch_puppet(hosts, opts) ⇒ Object
private
Determine the PE package to download/upload per-host, download/upload that package onto the host and unpack it.
-
#fetch_puppet_on_mac(host, opts) ⇒ Object
private
Determine the PE package to download/upload on a mac host, download/upload that package onto the host.
-
#fetch_puppet_on_unix(host, opts) ⇒ Object
private
Determine the PE package to download/upload on a unix style host, download/upload that package onto the host and unpack it.
-
#fetch_puppet_on_windows(host, opts) ⇒ Object
private
Determine the PE package to download/upload on a windows host, download/upload that package onto the host.
-
#find_git_repo_versions(host, path, repository) ⇒ Hash
Executes git describe on [host] and returns a Hash with the key of [repository] and value of the output from git describe.
-
#higgs_installer_cmd(host) ⇒ Object
private
Create the Higgs install command string based upon the host and options settings.
- #install_from_git(host, path, repository) ⇒ Object
-
#install_higgs(higgs_host = master) ⇒ Object
Install Higgs up till the point where you need to continue installation in a web browser, defaults to execution on the master node.
-
#install_pe ⇒ Object
Install PE based upon host configuration and options.
-
#install_puppet(opts = {}) ⇒ Object
Install FOSS based upon host configuration and options.
-
#install_puppet_from_deb(host, opts) ⇒ Object
private
Installs Puppet and dependencies from deb.
-
#install_puppet_from_dmg(host, opts) ⇒ Object
private
Installs Puppet and dependencies from dmg.
-
#install_puppet_from_gem(host, opts) ⇒ Object
private
Installs Puppet and dependencies from gem.
-
#install_puppet_from_msi(host, opts) ⇒ Object
private
Installs Puppet and dependencies from msi.
-
#install_puppet_from_rpm(host, opts) ⇒ Object
private
Installs Puppet and dependencies using rpm.
-
#install_puppetlabs_dev_repo(host, package_name, build_version, repo_configs_dir = 'tmp/repo_configs') ⇒ Object
Install development repository on the given host.
-
#install_puppetlabs_release_repo(host) ⇒ Object
Install official puppetlabs release repository configuration on host.
-
#installer_cmd(host, opts) ⇒ Object
private
Create the PE install command string based upon the host and options settings.
-
#link_exists?(link) ⇒ Boolean
private
Determine is a given URL is accessible.
-
#upgrade_pe(path = nil) ⇒ Object
Upgrade PE based upon host configuration and options.
Instance Method Details
#deploy_frictionless_to_master(host) ⇒ 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.
Classify the master so that it can deploy frictionless packages for a given host.
389 390 391 392 393 394 395 |
# File 'lib/beaker/dsl/install_utils.rb', line 389 def deploy_frictionless_to_master(host) klass = host['platform'].gsub(/-/, '_').gsub(/\./,'') klass = "pe_repo::platform::#{klass}" on dashboard, "cd /opt/puppet/share/puppet-dashboard && /opt/puppet/bin/bundle exec /opt/puppet/bin/rake nodeclass:add[#{klass},skip]" on dashboard, "cd /opt/puppet/share/puppet-dashboard && /opt/puppet/bin/bundle exec /opt/puppet/bin/rake node:addclass[#{master},#{klass}]" on master, "puppet agent -t", :acceptable_exit_codes => [0,2] end |
#do_higgs_install(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.
Perform a Puppet Enterprise Higgs install up until web browser interaction is required, runs on linux hosts only.
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/beaker/dsl/install_utils.rb', line 520 def do_higgs_install host, opts use_all_tar = ENV['PE_USE_ALL_TAR'] == 'true' platform = use_all_tar ? 'all' : host['platform'] version = host['pe_ver'] || opts[:pe_ver] host['dist'] = "puppet-enterprise-#{version}-#{platform}" use_all_tar = ENV['PE_USE_ALL_TAR'] == 'true' host['pe_installer'] ||= 'puppet-enterprise-installer' host['working_dir'] = host.tmpdir(Time.new.strftime("%Y-%m-%d_%H.%M.%S")) fetch_puppet([host], opts) host['higgs_file'] = "higgs_#{File.basename(host['working_dir'])}.log" on host, higgs_installer_cmd(host), opts #wait for output to host['higgs_file'] #we're all done when we find this line in the PE installation log higgs_re = /Please\s+go\s+to\s+https:\/\/.*\s+in\s+your\s+browser\s+to\s+continue\s+installation/m res = Result.new(host, 'tmp cmd') tries = 10 attempts = 0 prev_sleep = 0 cur_sleep = 1 while (res.stdout !~ higgs_re) and (attempts < tries) res = on host, "cd #{host['working_dir']}/#{host['dist']} && cat #{host['higgs_file']}", :acceptable_exit_codes => (0..255) attempts += 1 sleep( cur_sleep ) prev_sleep = cur_sleep cur_sleep = cur_sleep + prev_sleep end if attempts >= tries raise "Failed to kick off PE (Higgs) web installation" end end |
#do_install(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.
Perform a Puppet Enterprise upgrade or install
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 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/beaker/dsl/install_utils.rb', line 415 def do_install hosts, opts = {} opts[:type] = opts[:type] || :install hostcert='uname | grep -i sunos > /dev/null && hostname || hostname -s' master_certname = on(master, hostcert).stdout.strip pre30database = version_is_less(opts[:pe_ver] || database['pe_ver'], '3.0') pre30master = version_is_less(opts[:pe_ver] || master['pe_ver'], '3.0') # Set PE distribution for all the hosts, create working dir use_all_tar = ENV['PE_USE_ALL_TAR'] == 'true' hosts.each do |host| host['pe_installer'] ||= 'puppet-enterprise-installer' if host['platform'] !~ /windows|osx/ platform = use_all_tar ? 'all' : host['platform'] version = host['pe_ver'] || opts[:pe_ver] host['dist'] = "puppet-enterprise-#{version}-#{platform}" elsif host['platform'] =~ /osx/ version = host['pe_ver'] || opts[:pe_ver] host['dist'] = "puppet-enterprise-#{version}-#{host['platform']}" end host['working_dir'] = host.tmpdir(Time.new.strftime("%Y-%m-%d_%H.%M.%S")) end fetch_puppet(hosts, opts) # If we're installing a database version less than 3.0, ignore the database host install_hosts = hosts.dup install_hosts.delete(database) if pre30database and database != master and database != dashboard install_hosts.each do |host| if host['platform'] =~ /windows/ on host, installer_cmd(host, opts) elsif host['platform'] =~ /osx/ on host, installer_cmd(host, opts) #set the certname and master on host, puppet("config set server #{master}") on host, puppet("config set certname #{host}") #run once to request cert on host, puppet_agent('-t'), :acceptable_exit_codes => [1] else # We only need answers if we're using the classic installer version = host['pe_ver'] || opts[:pe_ver] if (! host['roles'].include? 'frictionless') || version_is_less(version, '3.2.0') answers = Beaker::Answers.answers(opts[:pe_ver] || host['pe_ver'], hosts, master_certname, opts) create_remote_file host, "#{host['working_dir']}/answers", Beaker::Answers.answer_string(host, answers) else # If We're *not* running the classic installer, we want # to make sure the master has packages for us. deploy_frictionless_to_master(host) end on host, installer_cmd(host, opts) end # On each agent, we ensure the certificate is signed then shut down the agent sign_certificate_for(host) stop_agent_on(host) end # Wait for PuppetDB to be totally up and running (post 3.0 version of pe only) sleep_until_puppetdb_started(database) unless pre30database # Run the agent once to ensure everything is in the dashboard install_hosts.each do |host| on host, puppet_agent('-t'), :acceptable_exit_codes => [0,2] # Workaround for PE-1105 when deploying 3.0.0 # The installer did not respect our database host answers in 3.0.0, # and would cause puppetdb to be bounced by the agent run. By sleeping # again here, we ensure that if that bounce happens during an upgrade # test we won't fail early in the install process. if host['pe_ver'] == '3.0.0' and host == database sleep_until_puppetdb_started(database) end end install_hosts.each do |host| wait_for_host_in_dashboard(host) end if pre30master task = 'nodegroup:add_all_nodes group=default' else task = 'defaultgroup:ensure_default_group' end on dashboard, "/opt/puppet/bin/rake -sf /opt/puppet/share/puppet-dashboard/Rakefile #{task} RAILS_ENV=production" # Now that all hosts are in the dashbaord, run puppet one more # time to configure mcollective on install_hosts, puppet_agent('-t'), :acceptable_exit_codes => [0,2] end |
#extract_repo_info_from(uri) ⇒ Hash{Symbol=>String}
Returns a hash containing the project name, repository path, and revision (defaults to HEAD)
47 48 49 50 51 52 53 54 |
# File 'lib/beaker/dsl/install_utils.rb', line 47 def extract_repo_info_from uri project = {} repo, rev = uri.split('#', 2) project[:name] = Pathname.new(repo).basename('.git').to_s project[:path] = repo project[:rev] = rev || 'HEAD' return project end |
#fetch_puppet(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.
Determine the PE package to download/upload per-host, download/upload that package onto the host and unpack it.
371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/beaker/dsl/install_utils.rb', line 371 def fetch_puppet(hosts, opts) hosts.each do |host| # We install Puppet from the master for frictionless installs, so we don't need to *fetch* anything next if host['roles'].include? 'frictionless' and ! version_is_less(opts[:pe_ver] || host['pe_ver'], '3.2.0') if host['platform'] =~ /windows/ fetch_puppet_on_windows(host, opts) elsif host['platform'] =~ /osx/ fetch_puppet_on_mac(host, opts) else fetch_puppet_on_unix(host, opts) end end end |
#fetch_puppet_on_mac(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.
Determine the PE package to download/upload on a mac host, download/upload that package onto the host. Assumed file name format: puppet-enterprise-3.3.0-rc1-559-g97f0833-osx-10.9-x86_64.dmg.
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/beaker/dsl/install_utils.rb', line 279 def fetch_puppet_on_mac(host, opts) path = host['pe_dir'] || opts[:pe_dir] local = File.directory?(path) filename = "#{host['dist']}" extension = ".dmg" if local if not File.exists?("#{path}/#{filename}#{extension}") raise "attempting installation on #{host}, #{path}/#{filename}#{extension} does not exist" end scp_to host, "#{path}/#{filename}#{extension}", "#{host['working_dir']}/#{filename}#{extension}" else if not link_exists?("#{path}/#{filename}#{extension}") raise "attempting installation on #{host}, #{path}/#{filename}#{extension} does not exist" end on host, "cd #{host['working_dir']}; curl -O #{path}/#{filename}#{extension}" end end |
#fetch_puppet_on_unix(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.
Determine the PE package to download/upload on a unix style host, download/upload that package onto the host and unpack it.
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/beaker/dsl/install_utils.rb', line 332 def fetch_puppet_on_unix(host, opts) path = host['pe_dir'] || opts[:pe_dir] local = File.directory?(path) filename = "#{host['dist']}" if local extension = File.exists?("#{path}/#{filename}.tar.gz") ? ".tar.gz" : ".tar" if not File.exists?("#{path}/#{filename}#{extension}") raise "attempting installation on #{host}, #{path}/#{filename}#{extension} does not exist" end scp_to host, "#{path}/#{filename}#{extension}", "#{host['working_dir']}/#{filename}#{extension}" if extension =~ /gz/ on host, "cd #{host['working_dir']}; gunzip #{filename}#{extension}" end if extension =~ /tar/ on host, "cd #{host['working_dir']}; tar -xvf #{filename}.tar" end else extension = link_exists?("#{path}/#{filename}.tar.gz") ? ".tar.gz" : ".tar" if not link_exists?("#{path}/#{filename}#{extension}") raise "attempting installation on #{host}, #{path}/#{filename}#{extension} does not exist" end unpack = 'tar -xvf -' unpack = extension =~ /gz/ ? 'gunzip | ' + unpack : unpack on host, "cd #{host['working_dir']}; curl #{path}/#{filename}#{extension} | #{unpack}" end end |
#fetch_puppet_on_windows(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.
Determine the PE package to download/upload on a windows host, download/upload that package onto the host. Assumed file name format: puppet-enterprise-3.3.0-rc1-559-g97f0833.msi
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/beaker/dsl/install_utils.rb', line 306 def fetch_puppet_on_windows(host, opts) path = host['pe_dir'] || opts[:pe_dir] local = File.directory?(path) version = host['pe_ver'] || opts[:pe_ver_win] filename = "puppet-enterprise-#{version}" extension = ".msi" if local if not File.exists?("#{path}/#{filename}#{extension}") raise "attempting installation on #{host}, #{path}/#{filename}#{extension} does not exist" end scp_to host, "#{path}/#{filename}#{extension}", "#{host['working_dir']}/#{filename}#{extension}" else if not link_exists?("#{path}/#{filename}#{extension}") raise "attempting installation on #{host}, #{path}/#{filename}#{extension} does not exist" end on host, "cd #{host['working_dir']}; curl -O #{path}/#{filename}#{extension}" end end |
#find_git_repo_versions(host, path, repository) ⇒ Hash
This requires the helper methods:
Returns Executes git describe on [host] and returns a Hash with the key of [repository] and value of the output from git describe.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/beaker/dsl/install_utils.rb', line 90 def find_git_repo_versions host, path, repository version = {} step "Grab version for #{repository[:name]}" do on host, "cd #{path}/#{repository[:name]} && " + "git describe || true" do version[repository[:name]] = stdout.chomp end end version end |
#higgs_installer_cmd(host) ⇒ 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.
Create the Higgs install command string based upon the host and options settings. Installation command will be run as a background process. The output of the command will be stored in the provided host.
180 181 182 183 184 |
# File 'lib/beaker/dsl/install_utils.rb', line 180 def higgs_installer_cmd host "cd #{host['working_dir']}/#{host['dist']} ; nohup ./#{host['pe_installer']} <<<Y > #{host['higgs_file']} 2>&1 &" end |
#install_from_git(host, path, repository) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/beaker/dsl/install_utils.rb', line 103 def install_from_git host, path, repository name = repository[:name] repo = repository[:path] rev = repository[:rev] target = "#{path}/#{name}" step "Clone #{repo} if needed" do on host, "test -d #{path} || mkdir -p #{path}" on host, "test -d #{target} || git clone #{repo} #{target}" end step "Update #{name} and check out revision #{rev}" do commands = ["cd #{target}", "remote rm origin", "remote add origin #{repo}", "fetch origin", "clean -fdx", "checkout -f #{rev}"] on host, commands.join(" && git ") end step "Install #{name} on the system" do # 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 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" end end |
#install_higgs(higgs_host = master) ⇒ Object
Either pe_ver and pe_dir should be set in the ENV or each host should have pe_ver and pe_dir set individually. Install file names are assumed to be of the format puppet-enterprise-VERSION-PLATFORM.(tar)|(tar.gz).
Install Higgs up till the point where you need to continue installation in a web browser, defaults to execution on the master node.
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 |
# File 'lib/beaker/dsl/install_utils.rb', line 1010 def install_higgs( higgs_host = master ) #process the version files if necessary master['pe_dir'] ||= [:pe_dir] master['pe_ver'] = master['pe_ver'] || ['pe_ver'] || Beaker::Options::PEVersionScraper.load_pe_version(master[:pe_dir] || [:pe_dir], [:pe_version_file]) if higgs_host['platform'] =~ /osx|windows/ raise "Attempting higgs installation on host #{higgs_host.name} with unsupported platform #{higgs_host['platform']}" end #send in the global options hash do_higgs_install higgs_host, end |
#install_pe ⇒ Object
Either pe_ver and pe_dir should be set in the ENV or each host should have pe_ver and pe_dir set individually. Install file names are assumed to be of the format puppet-enterprise-VERSION-PLATFORM.(tar)|(tar.gz) for Unix like systems and puppet-enterprise-VERSION.msi for Windows systems.
Install PE based upon host configuration and options
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 |
# File 'lib/beaker/dsl/install_utils.rb', line 810 def install_pe #process the version files if necessary hosts.each do |host| host['pe_dir'] ||= [:pe_dir] if host['platform'] =~ /windows/ host['pe_ver'] = host['pe_ver'] || ['pe_ver'] || Beaker::Options::PEVersionScraper.load_pe_version(host[:pe_dir] || [:pe_dir], [:pe_version_file_win]) else host['pe_ver'] = host['pe_ver'] || ['pe_ver'] || Beaker::Options::PEVersionScraper.load_pe_version(host[:pe_dir] || [:pe_dir], [:pe_version_file]) end end #send in the global options hash do_install sorted_hosts, end |
#install_puppet(opts = {}) ⇒ Object
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’.
Install FOSS based upon host configuration and options
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/dsl/install_utils.rb', line 593 def install_puppet(opts = {}) hosts.each do |host| if host['platform'] =~ /el-(5|6|7)/ relver = $1 install_puppet_from_rpm host, opts.merge(:release => relver, :family => 'el') elsif host['platform'] =~ /fedora-(\d+)/ relver = $1 install_puppet_from_rpm host, opts.merge(:release => relver, :family => 'fedora') elsif host['platform'] =~ /(ubuntu|debian)/ install_puppet_from_deb host, opts elsif host['platform'] =~ /windows/ relver = opts[:version] install_puppet_from_msi host, opts elsif host['platform'] =~ /osx/ install_puppet_from_dmg host, opts else if opts[:default_action] == 'gem_install' install_puppet_from_gem host, opts else raise "install_puppet() called for unsupported platform '#{host['platform']}' on '#{host.name}'" end end # Certain install paths may not create the config dirs/files needed on host, "mkdir -p #{host['puppetpath']}" on host, "echo '' >> #{host['hieraconf']}" end nil end |
#install_puppet_from_deb(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.
Installs Puppet and dependencies from deb
666 667 668 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 |
# File 'lib/beaker/dsl/install_utils.rb', line 666 def install_puppet_from_deb( host, opts ) if ! host.check_for_package 'lsb-release' host.install_package('lsb-release') end if ! host.check_for_command 'curl' on host, 'apt-get install -y curl' end on host, 'curl -O http://apt.puppetlabs.com/puppetlabs-release-$(lsb_release -c -s).deb' on host, 'dpkg -i puppetlabs-release-$(lsb_release -c -s).deb' on host, 'apt-get update' if opts[:facter_version] on host, "apt-get install -y facter=#{opts[:facter_version]}-1puppetlabs1" end if opts[:hiera_version] on host, "apt-get install -y hiera=#{opts[:hiera_version]}-1puppetlabs1" end if opts[:version] on host, "apt-get install -y puppet-common=#{opts[:version]}-1puppetlabs1" on host, "apt-get install -y puppet=#{opts[:version]}-1puppetlabs1" else on host, 'apt-get install -y puppet' end end |
#install_puppet_from_dmg(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.
Installs Puppet and dependencies from dmg
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 |
# File 'lib/beaker/dsl/install_utils.rb', line 726 def install_puppet_from_dmg( host, opts ) puppet_ver = opts[:version] facter_ver = opts[:facter_version] hiera_ver = opts[:hiera_version] on host, "curl -O http://downloads.puppetlabs.com/mac/puppet-#{puppet_ver}.dmg" on host, "curl -O http://downloads.puppetlabs.com/mac/facter-#{facter_ver}.dmg" on host, "curl -O http://downloads.puppetlabs.com/mac/hiera-#{hiera_ver}.dmg" on host, "hdiutil attach puppet-#{puppet_ver}.dmg" on host, "hdiutil attach facter-#{facter_ver}.dmg" on host, "hdiutil attach hiera-#{hiera_ver}.dmg" on host, "installer -pkg /Volumes/puppet-#{puppet_ver}/puppet-#{puppet_ver}.pkg -target /" on host, "installer -pkg /Volumes/facter-#{facter_ver}/facter-#{facter_ver}.pkg -target /" on host, "installer -pkg /Volumes/hiera-#{hiera_ver}/hiera-#{hiera_ver}.pkg -target /" end |
#install_puppet_from_gem(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.
Installs Puppet and dependencies from gem
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
# File 'lib/beaker/dsl/install_utils.rb', line 755 def install_puppet_from_gem( host, opts ) # 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 if host['platform'] =~ /solaris-10/ on host, 'ln -s /opt/csw/bin/pkgutil /usr/bin/pkgutil' end # Solaris doesn't necessarily have this, but gem needs it if host['platform'] =~ /solaris/ on host, 'mkdir -p /var/lib' end 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' 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 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 if opts[:facter_version] on host, "gem install facter -v#{opts[:facter_version]} --no-ri --no-rdoc" end if opts[:hiera_version] on host, "gem install hiera -v#{opts[:hiera_version]} --no-ri --no-rdoc" end ver_cmd = opts[:version] ? "-v#{opts[:version]}" : '' on host, "gem install puppet #{ver_cmd} --no-ri --no-rdoc" end |
#install_puppet_from_msi(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.
Installs Puppet and dependencies from msi
703 704 705 706 707 708 709 710 711 712 713 714 |
# File 'lib/beaker/dsl/install_utils.rb', line 703 def install_puppet_from_msi( host, opts ) on host, "curl -O http://downloads.puppetlabs.com/windows/puppet-#{opts[:version]}.msi" on host, "msiexec /qn /i puppet-#{opts[:version]}.msi" #Because the msi installer doesn't add Puppet to the environment path if fact_on(host, 'architecture').eql?('x86_64') install_dir = '/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/bin' else install_dir = '/cygdrive/c/Program Files/Puppet Labs/Puppet/bin' end on host, %Q{ echo 'export PATH=$PATH:"#{install_dir}"' > /etc/bash.bashrc } end |
#install_puppet_from_rpm(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.
Installs Puppet and dependencies using rpm
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 |
# File 'lib/beaker/dsl/install_utils.rb', line 639 def install_puppet_from_rpm( host, opts ) release_package_string = "http://yum.puppetlabs.com/puppetlabs-release-#{opts[:family]}-#{opts[:release]}.noarch.rpm" on host, "rpm -ivh #{release_package_string}" if opts[:facter_version] on host, "yum install -y facter-#{opts[:facter_version]}" end if opts[:hiera_version] on host, "yum install -y hiera-#{opts[:hiera_version]}" end puppet_pkg = opts[:version] ? "puppet-#{opts[:version]}" : 'puppet' on host, "yum install -y #{puppet_pkg}" end |
#install_puppetlabs_dev_repo(host, package_name, build_version, repo_configs_dir = 'tmp/repo_configs') ⇒ Object
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.
906 907 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 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 |
# File 'lib/beaker/dsl/install_utils.rb', line 906 def install_puppetlabs_dev_repo ( host, package_name, build_version, repo_configs_dir = 'tmp/repo_configs' ) variant, version, arch, codename = host['platform'].to_array platform_configs_dir = File.join(repo_configs_dir, variant) # some of the uses of dev_builds_url below can't include protocol info, # pluse this opens up possibility of switching the behavior on provided # url type _, protocol, hostname = [:dev_builds_url].partition /.*:\/\// dev_builds_url = protocol + hostname on host, "mkdir -p /root/#{package_name}" case variant when /^(fedora|el|centos)$/ variant = (($1 == 'centos') ? 'el' : $1) fedora_prefix = ((variant == 'fedora') ? 'f' : '') if host.is_pe? pattern = "pl-%s-%s-repos-pe-%s-%s%s-%s.repo" else pattern = "pl-%s-%s-%s-%s%s-%s.repo" end repo_filename = pattern % [ package_name, build_version, variant, fedora_prefix, version, arch ] repo = fetch_http_file( "%s/%s/%s/repo_configs/rpm/" % [ dev_builds_url, package_name, build_version ], repo_filename, platform_configs_dir) link = "%s/%s/%s/repos/%s/%s%s/products/%s/" % [ dev_builds_url, package_name, build_version, variant, fedora_prefix, version, arch ] if not link_exists?( link ) link = "%s/%s/%s/repos/%s/%s%s/devel/%s/" % [ dev_builds_url, package_name, build_version, variant, fedora_prefix, version, arch ] end if not link_exists?( link ) raise "Unable to reach a repo directory at #{link}" end repo_dir = fetch_http_dir( link, platform_configs_dir ) config_dir = '/etc/yum.repos.d/' scp_to host, repo, config_dir scp_to host, repo_dir, "/root/#{package_name}" search = "baseurl\\s*=\\s*http:\\/\\/#{hostname}.*$" replace = "baseurl=file:\\/\\/\\/root\\/#{package_name}\\/#{arch}" sed_command = "sed -i 's/#{search}/#{replace}/'" find_and_sed = "find #{config_dir} -name \"*.repo\" -exec #{sed_command} {} \\;" on host, find_and_sed when /^(debian|ubuntu)$/ list = fetch_http_file( "%s/%s/%s/repo_configs/deb/" % [ dev_builds_url, package_name, build_version ], "pl-%s-%s-%s.list" % [ package_name, build_version, codename ], platform_configs_dir ) repo_dir = fetch_http_dir( "%s/%s/%s/repos/apt/%s" % [ dev_builds_url, package_name, build_version, codename ], platform_configs_dir ) config_dir = '/etc/apt/sources.list.d' scp_to host, list, config_dir scp_to host, repo_dir, "/root/#{package_name}" search = "deb\\s\\+http:\\/\\/#{hostname}.*$" replace = "deb file:\\/\\/\\/root\\/#{package_name}\\/#{codename} #{codename} main" sed_command = "sed -i 's/#{search}/#{replace}/'" find_and_sed = "find #{config_dir} -name \"*.list\" -exec #{sed_command} {} \\;" on host, find_and_sed on host, "apt-get update" else raise "No repository installation step for #{variant} yet..." end end |
#install_puppetlabs_release_repo(host) ⇒ Object
This method only works on redhat-like and debian-like hosts.
Install official puppetlabs release repository configuration on host.
863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 |
# File 'lib/beaker/dsl/install_utils.rb', line 863 def install_puppetlabs_release_repo ( host ) variant, version, arch, codename = host['platform'].to_array case variant when /^(fedora|el|centos)$/ variant = (($1 == 'centos') ? 'el' : $1) rpm = [:release_yum_repo_url] + "/puppetlabs-release-%s-%s.noarch.rpm" % [variant, version] on host, "rpm -ivh --force #{rpm}" when /^(debian|ubuntu)$/ deb = URI.join([:release_apt_repo_url], "puppetlabs-release-%s.deb" % codename) on host, "wget -O /tmp/puppet.deb #{deb}" on host, "dpkg -i --force-all /tmp/puppet.deb" on host, "apt-get update" else raise "No repository installation step for #{variant} yet..." end end |
#installer_cmd(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.
Create the PE install command string based upon the host and options settings
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/beaker/dsl/install_utils.rb', line 152 def installer_cmd(host, opts) version = host['pe_ver'] || opts[:pe_ver] if host['platform'] =~ /windows/ version = host[:pe_ver] || opts['pe_ver_win'] log_file = "#{File.basename(host['working_dir'])}.log" pe_debug = host[:pe_debug] || opts[:pe_debug] ? " && cat #{log_file}" : '' "cd #{host['working_dir']} && cmd /C 'start /w msiexec.exe /qn /L*V #{log_file} /i puppet-enterprise-#{version}.msi PUPPET_MASTER_SERVER=#{master} PUPPET_AGENT_CERTNAME=#{host}'#{pe_debug}" elsif host['platform'] =~ /osx/ version = host['pe_ver'] || opts[:pe_ver] pe_debug = host[:pe_debug] || opts[:pe_debug] ? ' -verboseR' : '' "cd #{host['working_dir']} && hdiutil attach #{host['dist']}.dmg && installer#{pe_debug} -pkg /Volumes/puppet-enterprise-#{version}/puppet-enterprise-installer-#{version}.pkg -target /" # Frictionless install didn't exist pre-3.2.0, so in that case we fall # through and do a regular install. elsif host['roles'].include? 'frictionless' and ! version_is_less(version, '3.2.0') pe_debug = host[:pe_debug] || opts[:pe_debug] ? ' -x' : '' "cd #{host['working_dir']} && curl -kO https://#{master}:8140/packages/#{version}/install.bash && bash#{pe_debug} install.bash" else pe_debug = host[:pe_debug] || opts[:pe_debug] ? ' -D' : '' "cd #{host['working_dir']}/#{host['dist']} && ./#{host['pe_installer']}#{pe_debug} -a #{host['working_dir']}/answers" end end |
#link_exists?(link) ⇒ Boolean
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.
Determine is a given URL is accessible
192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/beaker/dsl/install_utils.rb', line 192 def link_exists?(link) require "net/http" require "net/https" require "open-uri" url = URI.parse(link) http = Net::HTTP.new(url.host, url.port) http.use_ssl = (url.scheme == 'https') http.start do |http| return http.head(url.request_uri).code == "200" end end |
#upgrade_pe(path = nil) ⇒ Object
Install file names are assumed to be of the format puppet-enterprise-VERSION-PLATFORM.(tar)|(tar.gz) for Unix like systems and puppet-enterprise-VERSION.msi for Windows systems.
Upgrade PE based upon host configuration and options
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 |
# File 'lib/beaker/dsl/install_utils.rb', line 837 def upgrade_pe path=nil hosts.each do |host| host['pe_dir'] = host['pe_upgrade_dir'] || path if host['platform'] =~ /windows/ host['pe_ver'] = host['pe_upgrade_ver'] || ['pe_upgrade_ver'] || Options::PEVersionScraper.load_pe_version(host['pe_dir'], [:pe_version_file_win]) else host['pe_ver'] = host['pe_upgrade_ver'] || ['pe_upgrade_ver'] || Options::PEVersionScraper.load_pe_version(host['pe_dir'], [:pe_version_file]) end if version_is_less(host['pe_ver'], '3.0') host['pe_installer'] ||= 'puppet-enterprise-upgrader' end end #send in the global options hash do_install(sorted_hosts, .merge({:type => :upgrade})) ['upgrade'] = true end |