lib/beaker/dsl/install_utils/pe_utils.rb
#Perform a Puppet Enterprise upgrade or install
# @param [Array<Host>] hosts The hosts to install or upgrade PE on
# @param  [Hash{Symbol=>Symbol, String}] opts The options
# @option opts [String] :pe_dir Default directory or URL to pull PE package from
#                  (Otherwise uses individual hosts pe_dir)
# @option opts [String] :pe_ver Default PE version to install or upgrade to
#                  (Otherwise uses individual hosts pe_ver)
# @option opts [String] :pe_ver_win Default PE version to install or upgrade to on Windows hosts
#                  (Otherwise uses individual Windows hosts pe_ver)
# @option opts [Symbol] :type (:install) One of :upgrade or :install
# @option opts [Boolean] :set_console_password Should we set the PE console password in the answers file?  Used during upgrade only.
# @option opts [Hash<String>] :answers Pre-set answers based upon ENV vars and defaults
#                             (See {Beaker::Options::Presets.env_vars})
# @option opts [Boolean] :fetch_local_then_push_to_host determines whether
#                 you use Beaker as the middleman for this (true), or curl the
#                 file from the host (false; default behavior)
# @option opts [Boolean] :masterless Are we performing a masterless installation?
#
# @example
#  do_install(hosts, {:type => :upgrade, :pe_dir => path, :pe_ver => version, :pe_ver_win =>  version_win})
#
# @note on windows, the +:ruby_arch+ host parameter can determine in addition
# to other settings whether the 32 or 64bit install is used
#
# @api private
#
Perform a Puppet Enterprise upgrade or install
Perform a Puppet Enterprise upgrade or install
def do_install hosts, opts = {}
          masterless = opts[:masterless]
          opts[:type] = opts[:type] || :install
          unless masterless
            pre30database = version_is_less(opts[:pe_ver] || database['pe_ver'], '3.0')
            pre30master = version_is_less(opts[:pe_ver] || master['pe_ver'], '3.0')
          end
          pe_versions = ( [] << opts['pe_ver'] << hosts.map{ |host| host['pe_ver'] } ).flatten.compact
          agent_only_check_needed = version_is_less('3.99', max_version(pe_versions, '3.8'))
          if agent_only_check_needed
            hosts_agent_only, hosts_not_agent_only = create_agent_specified_arrays(hosts)
          else
            hosts_agent_only, hosts_not_agent_only = [], hosts.dup
          end
          use_all_tar = ENV['PE_USE_ALL_TAR'] == 'true'
          hosts.each do |host|
            next if agent_only_check_needed && hosts_agent_only.include?(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']}"
            elsif host['platform'] =~ /windows/
              version = host[:pe_ver] || opts['pe_ver_win']
              is_config_32 = true == (host['ruby_arch'] == 'x86') || host['install_32'] || opts['install_32']
              should_install_64bit = !(version_is_less(version, '3.4')) && host.is_x86_64? && !is_config_32
              if !(version_is_less(version, '3.99'))
                if should_install_64bit
                  host['dist'] = "puppet-agent-#{version}-x64"
                else
                  host['dist'] = "puppet-agent-#{version}-x86"
                end
              elsif should_install_64bit
                host['dist'] = "puppet-enterprise-#{version}-x64"
              else
                host['dist'] = "puppet-enterprise-#{version}"
              end
            end
            host['working_dir'] = host.tmpdir(Time.new.strftime("%Y-%m-%d_%H.%M.%S"))
          end
          fetch_pe(hosts_not_agent_only, opts)
          install_hosts = hosts.dup
          unless masterless
            install_hosts.delete(database) if pre30database and database != master and database != dashboard
          end
          install_hosts.each do |host|
            if agent_only_check_needed && hosts_agent_only.include?(host)
              host['type'] = 'aio'
              install_puppet_agent_pe_promoted_repo_on(host, { :puppet_agent_version => host[:puppet_agent_version] || opts[:puppet_agent_version],
                                                               :puppet_agent_sha => host[:puppet_agent_sha] || opts[:puppet_agent_sha],
                                                               :pe_ver => host[:pe_ver] || opts[:pe_ver],
                                                               :puppet_collection => host[:puppet_collection] || opts[:puppet_collection] })
              acceptable_exit_codes = [0, 1]
              acceptable_exit_codes << 2 if opts[:type] == :upgrade
              setup_defaults_and_config_helper_on(host, master, acceptable_exit_codes)
            elsif host['platform'] =~ /windows/
              opts = { :debug => host[:pe_debug] || opts[:pe_debug] }
              msi_path = "#{host['working_dir']}\\#{host['dist']}.msi"
              install_msi_on(host, msi_path, {}, opts)
              acceptable_exit_codes = 1
              setup_defaults_and_config_helper_on(host, master, acceptable_exit_codes)
            else
              version = host['pe_ver'] || opts[:pe_ver]
              if host['roles'].include?('frictionless') &&  (! version_is_less(version, '3.2.0'))
                if host['platform'] != master['platform'] 
                  deploy_frictionless_to_master(host)
                end
                on host, installer_cmd(host, opts)
                configure_type_defaults_on(host)
              elsif host['platform'] =~ /osx|eos/
                on host, installer_cmd(host, opts)
                acceptable_codes = host['platform'] =~ /osx/ ? [1] : [0, 1]
                setup_defaults_and_config_helper_on(host, master, acceptable_codes)
              else
                answers = BeakerAnswers::Answers.create(opts[:pe_ver] || host['pe_ver'], hosts, opts)
                create_remote_file host, "#{host['working_dir']}/answers", answers.answer_string(host)
                on host, installer_cmd(host, opts)
                configure_type_defaults_on(host)
              end
            end
            sign_certificate_for(host) unless masterless
            stop_agent_on(host)
          end
          unless masterless
            sleep_until_puppetdb_started(database) unless pre30database
            install_hosts.each do |host|
              on host, puppet_agent('-t'), :acceptable_exit_codes => [0,2]
              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 version_is_less(master[:pe_ver], '3.99')
              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"
            end
            on install_hosts, puppet_agent('-t'), :acceptable_exit_codes => [0,2]
          end
        end
def do_install hosts , opts = { } masterless = opts [ :masterless ] opts [ :type ] = opts [ :type ] || :install unless masterless pre30database = version_is_less ( opts [ :pe_ver ] || database [ 'pe_ver' ] , '3.0' ) pre30master = version_is_less ( opts [ :pe_ver ] || master [ 'pe_ver' ] , '3.0' ) end pe_versions = ( [ ] << opts [ 'pe_ver' ] << hosts . map { | host | host [ 'pe_ver' ] } ) . flatten . compact agent_only_check_needed = version_is_less ( '3.99' , max_version ( pe_versions , '3.8' ) ) if agent_only_check_needed hosts_agent_only , hosts_not_agent_only = create_agent_specified_arrays ( hosts ) else hosts_agent_only , hosts_not_agent_only = [ ] , hosts . dup end use_all_tar = ENV [ 'PE_USE_ALL_TAR' ] == 'true' hosts . each do | host | next if agent_only_check_needed && hosts_agent_only . include? ( 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']}" elsif host [ 'platform' ] =~ / windows / version = host [ :pe_ver ] || opts [ 'pe_ver_win' ] is_config_32 = true == ( host [ 'ruby_arch' ] == 'x86' ) || host [ 'install_32' ] || opts [ 'install_32' ] should_install_64bit = ! ( version_is_less ( version , '3.4' ) ) && host . is_x86_64? && ! is_config_32 if ! ( version_is_less ( version , '3.99' ) ) if should_install_64bit host [ 'dist' ] = "puppet-agent-#{version}-x64" else host [ 'dist' ] = "puppet-agent-#{version}-x86" end elsif should_install_64bit host [ 'dist' ] = "puppet-enterprise-#{version}-x64" else host [ 'dist' ] = "puppet-enterprise-#{version}" end end host [ 'working_dir' ] = host . tmpdir ( Time . new . strftime ( "%Y-%m-%d_%H.%M.%S" ) ) end fetch_pe ( hosts_not_agent_only , opts ) install_hosts = hosts . dup unless masterless install_hosts . delete ( database ) if pre30database and database != master and database != dashboard end install_hosts . each do | host | if agent_only_check_needed && hosts_agent_only . include? ( host ) host [ 'type' ] = 'aio' install_puppet_agent_pe_promoted_repo_on ( host , { :puppet_agent_version => host [ :puppet_agent_version ] || opts [ :puppet_agent_version ] , :puppet_agent_sha => host [ :puppet_agent_sha ] || opts [ :puppet_agent_sha ] , :pe_ver => host [ :pe_ver ] || opts [ :pe_ver ] , :puppet_collection => host [ :puppet_collection ] || opts [ :puppet_collection ] } ) acceptable_exit_codes = [ 0 , 1 ] acceptable_exit_codes << 2 if opts [ :type ] == :upgrade setup_defaults_and_config_helper_on ( host , master , acceptable_exit_codes ) elsif host [ 'platform' ] =~ / windows / opts = { :debug => host [ :pe_debug ] || opts [ :pe_debug ] } msi_path = "#{host['working_dir']}\\#{host['dist']}.msi" install_msi_on ( host , msi_path , { } , opts ) acceptable_exit_codes = 1 setup_defaults_and_config_helper_on ( host , master , acceptable_exit_codes ) else version = host [ 'pe_ver' ] || opts [ :pe_ver ] if host [ 'roles' ] . include? ( 'frictionless' ) && ( ! version_is_less ( version , '3.2.0' ) ) if host [ 'platform' ] != master [ 'platform' ] deploy_frictionless_to_master ( host ) end on host , installer_cmd ( host , opts ) configure_type_defaults_on ( host ) elsif host [ 'platform' ] =~ / osx|eos / on host , installer_cmd ( host , opts ) acceptable_codes = host [ 'platform' ] =~ / osx / ? [ 1 ] : [ 0 , 1 ] setup_defaults_and_config_helper_on ( host , master , acceptable_codes ) else answers = BeakerAnswers :: Answers . create ( opts [ :pe_ver ] || host [ 'pe_ver' ] , hosts , opts ) create_remote_file host , "#{host['working_dir']}/answers" , answers . answer_string ( host ) on host , installer_cmd ( host , opts ) configure_type_defaults_on ( host ) end end sign_certificate_for ( host ) unless masterless stop_agent_on ( host ) end unless masterless sleep_until_puppetdb_started ( database ) unless pre30database install_hosts . each do | host | on host , puppet_agent ( '-t' ) , :acceptable_exit_codes => [ 0 , 2 ] 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 version_is_less ( master [ :pe_ver ] , '3.99' ) 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" end on install_hosts , puppet_agent ( '-t' ) , :acceptable_exit_codes => [ 0 , 2 ] end end
Perform a Puppet Enterprise upgrade or install
Perform a Puppet Enterprise upgrade or install
# Set PE distribution for all the hosts, create working dir #only install 64bit builds if # - we are on pe version 3.4+ # - we do not have install_32 set on host # - we do not have install_32 set globally # If we're installing a database version less than 3.0, ignore the database host # 1 since no certificate found and waitforcert disabled # 1 since no certificate found and waitforcert disabled # We only need answers if we're using the classic installer # If We're *not* running the classic installer, we want # to make sure the master has packages for us. # only need to do this if platform differs # If we're not frictionless, we need to run the OSX special-case # On each agent, we ensure the certificate is signed then shut down the agent # Wait for PuppetDB to be totally up and running (post 3.0 version of pe only) # Run the agent once to ensure everything is in the dashboard # 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. # only appropriate for pre-3.9 builds # Now that all hosts are in the dashbaord, run puppet one more # time to configure mcollective
hosts
<not_specific>
opts
None
<not_specific>
opts The options
opts The options
example
do_install(hosts, {:type => :upgrade, :pe_dir => path, :pe_ver => version, :pe_ver_win => version_win})
do_install ( hosts { : type = > : upgrade : pe_dir = > path : pe_ver = > version : pe_ver_win = > version_win } )
note
on windows, the +:ruby_arch+ host parameter can determine in addition to other settings whether the 32 or 64bit install is used
on windows the + : ruby_arch + host parameter can determine in addition to other settings whether the 32 or 64bit install is used
api
None