class Kitchen::Provisioner::PuppetApply

Puppet Apply provisioner.

Attributes

tmp_dir[RW]

Public Instance Methods

calculate_path(path, type = :directory) click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 188
def calculate_path(path, type = :directory)
  base = config[:test_base_path]
  candidates = []
  candidates << File.join(base, instance.suite.name, 'puppet', path)
  candidates << File.join(base, instance.suite.name, path)
  candidates << File.join(base, path)
  candidates << File.join(Dir.pwd, path)

  candidates.find do |c|
    type == :directory ? File.directory?(c) : File.file?(c)
  end
end
cleanup_sandbox() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 597
def cleanup_sandbox
  return if sandbox_path.nil?
  debug("Cleaning up local sandbox in #{sandbox_path}")
  FileUtils.rmtree(sandbox_path)
  return if remove_repo.nil?
  debug("Cleaning up remote sandbox: #{remove_repo}")
  instance.remote_exec remove_repo
end
create_sandbox() { || ... } click to toggle source
Calls superclass method
# File lib/kitchen/provisioner/puppet_apply.rb, line 578
def create_sandbox
  super
  debug("Creating local sandbox in #{sandbox_path}")
  yield if block_given?
  prepare_modules
  prepare_manifests
  prepare_files
  prepare_facter_file
  prepare_facts
  prepare_puppet_config
  prepare_hiera_config
  prepare_puppet_environment
  prepare_fileserver_config
  prepare_hiera_data
  prepare_enc
  prepare_spec_files
  info('Finished Preparing files for transfer')
end
custom_install_command() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 555
      def custom_install_command
        <<-INSTALL
          #{config[:custom_install_command]}
        INSTALL
      end
custom_pre_install_command() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 549
      def custom_pre_install_command
        <<-INSTALL
          #{config[:custom_pre_install_command]}
        INSTALL
      end
hiera_package() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 510
def hiera_package
  "#{config[:hiera_package]}#{puppet_hiera_debian_version}"
end
init_command() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 561
def init_command
  todelete = %w[modules manifests files hiera hiera.yaml hiera.global.yaml facter spec enc environment]
             .map { |dir| File.join(config[:root_path], dir) }
  todelete += [hiera_data_remote_path,
               '/etc/hiera.yaml',
               "#{puppet_dir}/hiera.yaml",
               spec_files_remote_path.to_s,
               "#{puppet_dir}/fileserver.conf"]
  todelete << File.join(puppet_dir, puppet_environment) if puppet_environment
  todelete << File.join(puppet_environmentpath_remote_path, puppet_environment) if puppet_environment_config && puppet_environment
  cmd = "#{sudo(rm_command_paths(todelete))};"
  cmd += " #{mkdir_command} #{config[:root_path]};"
  cmd += " #{sudo(mkdir_command)} #{puppet_dir}"
  debug(cmd)
  cmd
end
install_busser() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 451
      def install_busser
        return unless config[:require_chef_for_busser]
        info("Install busser on #{puppet_platform}")
        case puppet_platform
        when /^windows.*/
          # https://raw.githubusercontent.com/opscode/knife-windows/master/lib/chef/knife/bootstrap/windows-chef-client-msi.erb
          <<-INSTALL
            $webclient = New-Object System.Net.WebClient;  $webclient.DownloadFile('https://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chef-windows-11.12.8-1.windows.msi','chef-windows-11.12.8-1.windows.msi')
            msiexec /qn /i chef-windows-11.12.8-1.windows.msi

            cmd.exe /C "SET PATH=%PATH%;`"C:\\opscode\\chef\\embedded\\bin`";`"C:\\tmp\\busser\\gems\\bin`""

          INSTALL
        else
          <<-INSTALL
          #{Util.shell_helpers}
          # install chef omnibus so that busser works as this is needed to run tests :(
          # TODO: work out how to install enough ruby
          # and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
          # whole chef client
          if [ ! -d "/opt/chef" ]
          then
            echo '-----> Installing Chef Omnibus to install busser to run tests'
            #{export_http_proxy_parm}
            #{export_https_proxy_parm}
            #{export_no_proxy_parm}
            do_download #{chef_url} /tmp/install.sh
            #{sudo('sh')} /tmp/install.sh
          fi
          INSTALL
        end
      end
install_command() click to toggle source

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

# File lib/kitchen/provisioner/puppet_apply.rb, line 202
      def install_command
        return unless config[:require_puppet_collections] || config[:require_puppet_repo] || config[:require_puppet_omnibus]
        if config[:require_puppet_omnibus]
          install_omnibus_command
        elsif config[:require_puppet_collections]
          install_command_collections
        else
          case puppet_platform
          when 'debian', 'ubuntu'
            info("Installing puppet on #{config[:platform]}")
            # need to add a CR to avoid trouble with proxy settings concatenation
            <<-INSTALL

              #{custom_pre_install_command}
              if [ ! $(which puppet) ]; then
                #{sudo('apt-get')} -y install wget
                #{sudo('apt-get')} -y install apt-transport-https
                #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
                #{sudo('dpkg')} -i #{puppet_apt_repo_file}
                #{update_packages_debian_cmd}
                #{sudo_env('apt-get')} -y install facter#{facter_debian_version}
                #{sudo_env('apt-get')} -y install puppet-common#{puppet_debian_version}
                #{sudo_env('apt-get')} -y install puppet#{puppet_debian_version}
                #{install_hiera}
              fi
              #{install_eyaml}
              #{install_eyaml_gpg}
              #{install_deep_merge}
              #{install_busser}
              #{custom_install_command}
            INSTALL
          when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
            info("Installing puppet from yum on #{puppet_platform}")
            # need to add a CR to avoid trouble with proxy settings concatenation
            <<-INSTALL

              #{custom_pre_install_command}
              if [ ! $(which puppet) ]; then
                #{install_puppet_yum_repo}
              fi
              #{install_eyaml}
              #{install_eyaml_gpg}
              #{install_deep_merge}
              #{install_busser}
              #{custom_install_command}
            INSTALL
          when /^windows.*/
            info("Installing puppet on #{puppet_platform}")
            info('Powershell is not recognised by core test-kitchen assuming it is present') unless powershell_shell?
            <<-INSTALL
              #{custom_pre_install_command}
              if(Get-Command puppet -ErrorAction 0) { return; }
              if( '#{puppet_windows_msi_url}' -ne '') {
                $MsiUrl = '#{puppet_windows_msi_url}'
              }
              else
              {
                $architecture = if( [Environment]::Is64BitOperatingSystem ) { 'x64' } else { 'x86' }
                if( '#{puppet_windows_version}' -eq 'latest' ) {
                    $MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-agent-${architecture}-latest.msi"
                } elseif( '#{puppet_windows_version}' -match '(\\d)\\.' ) {
                    $MsiUrl = "https://downloads.puppetlabs.com/windows/puppet$($Matches[1])/puppet-agent-#{puppet_windows_version}-${architecture}.msi"
                } else {
                    $MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-#{puppet_windows_version}${architecture}.msi"
                }
              }
              Invoke-WebRequest $MsiUrl -UseBasicParsing -OutFile "C:/puppet.msi" #{posh_proxy_parm}
              $process = Start-Process -FilePath msiexec.exe -Wait -PassThru -ArgumentList '/qn', '/norestart', '/i', 'C:\\puppet.msi'
              if ($process.ExitCode -ne 0) {
                  Write-Host "Installer failed."
                  Exit 1
              }
              #{install_busser}
              #{custom_install_command}
            INSTALL
          else
            info('Installing puppet, will try to determine platform os')
            # need to add a CR to avoid trouble with proxy settings concatenation
            <<-INSTALL

              #{custom_pre_install_command}
              if [ ! $(which puppet) ]; then
                if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
                    #{install_puppet_yum_repo}
                else
                  if [ -f /etc/system-release ] || grep -q 'Amazon Linux' /etc/system-release; then
                     #{install_puppet_yum_repo}
                  else
                    #{sudo('apt-get')} -y install wget
                    #{sudo('apt-get')} -y install apt-transport-https
                    #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
                    #{sudo('dpkg')} -i #{puppet_apt_repo_file}
                    #{update_packages_debian_cmd}
                    #{sudo_env('apt-get')} -y install facter#{facter_debian_version}
                    #{sudo_env('apt-get')} -y install puppet-common#{puppet_debian_version}
                    #{sudo_env('apt-get')} -y install puppet#{puppet_debian_version}
                    #{install_hiera}
                  fi
                fi
              fi
              #{install_eyaml}
              #{install_eyaml_gpg}
              #{install_deep_merge}
              #{install_busser}
              #{custom_install_command}
            INSTALL
          end
        end
      end
install_command_collections() click to toggle source

rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

# File lib/kitchen/provisioner/puppet_apply.rb, line 313
      def install_command_collections
        case puppet_platform
        when 'debian', 'ubuntu'
          info("Installing Puppet Collections on #{puppet_platform}")
          <<-INSTALL

          #{Util.shell_helpers}
          #{custom_pre_install_command}
          if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
            if [ ! -f "#{config[:puppet_apt_collections_repo]}" ]; then
              #{sudo('apt-get')} -y install wget
              #{sudo('apt-get')} -y install apt-transport-https
              #{sudo('wget')} #{wget_proxy_parm} #{config[:puppet_apt_collections_repo]}
            fi
            #{sudo('dpkg')} -i #{puppet_apt_coll_repo_file}
            #{sudo('apt-get')} update
            #{sudo_env('apt-get')} -y install puppet-agent#{puppet_debian_version}
          fi
          #{install_eyaml("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
          #{install_eyaml_gpg("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
          #{install_deep_merge}
          #{install_busser}
          #{custom_install_command}
          INSTALL
        when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
          info("Installing Puppet Collections on #{puppet_platform}")
          <<-INSTALL

          #{Util.shell_helpers}
          #{custom_pre_install_command}
          if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
            echo "-----> #{sudo_env('yum')} -y --nogpgcheck install #{config[:puppet_yum_collections_repo]}"
            #{sudo_env('yum')} clean all
            #{sudo_env('yum')} -y --nogpgcheck install #{config[:puppet_yum_collections_repo]}
            #{sudo_env('yum')} -y --nogpgcheck install puppet-agent#{puppet_redhat_version}
          fi
          #{install_eyaml("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
          #{install_eyaml_gpg("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
          #{install_deep_merge}
          #{install_busser}
          #{custom_install_command}
          INSTALL
        when /^windows.*/
          info("Installing Puppet Collections on #{puppet_platform}")
          info('Powershell is not recognised by core test-kitchen assuming it is present') unless powershell_shell?
          <<-INSTALL
            #{custom_pre_install_command}
            if(Get-Command puppet -ErrorAction 0) { return; }
            if( '#{puppet_windows_msi_url}' -ne '') {
              $MsiUrl = '#{puppet_windows_msi_url}'
            }
            else
            {
              $architecture = if( [Environment]::Is64BitOperatingSystem ) { 'x64' } else { 'x86' }
              if( '#{puppet_windows_version}' -eq 'latest' ) {
                  $MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-agent-${architecture}-latest.msi"
              } elseif( '#{puppet_windows_version}' -match '(\\d)\\.' ) {
                  $MsiUrl = "https://downloads.puppetlabs.com/windows/puppet$($Matches[1])/puppet-agent-#{puppet_windows_version}-${architecture}.msi"
              } else {
                  $MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-agent-#{puppet_windows_version}-${architecture}.msi"
              }
            }
            Invoke-WebRequest $MsiUrl -UseBasicParsing -OutFile "C:/puppet-agent.msi" #{posh_proxy_parm}
            $process = Start-Process -FilePath msiexec.exe -Wait -PassThru -ArgumentList '/qn', '/norestart', '/i', 'C:\\puppet-agent.msi'
            if ($process.ExitCode -ne 0) {
                Write-Host "Installer failed."
                Exit 1
            }
            #{install_busser}
            #{custom_install_command}
          INSTALL
        else
          info('Installing Puppet Collections, will try to determine platform os')
          <<-INSTALL

            #{Util.shell_helpers}
            #{custom_pre_install_command}
            if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
              if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ] || \
                 [ -f /etc/system-release ] || grep -q 'Amazon Linux' /etc/system-release; then
                echo "-----> #{sudo_env('yum')} -y --nogpgcheck install #{config[:puppet_yum_collections_repo]}"
                #{sudo_env('yum')} -y --nogpgcheck install #{config[:puppet_yum_collections_repo]}
                #{sudo_env('yum')} -y --nogpgcheck install puppet-agent#{puppet_redhat_version}
              else
                #{sudo('apt-get')} -y install wget
                #{sudo('apt-get')} -y install apt-transport-https
                #{sudo('wget')} #{wget_proxy_parm} #{config[:puppet_apt_collections_repo]}
                #{sudo('dpkg')} -i #{puppet_apt_coll_repo_file}
                #{sudo('apt-get')} update
                #{sudo_env('apt-get')} -y install puppet-agent#{puppet_debian_version}
              fi
            fi
            #{install_eyaml("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
            #{install_eyaml_gpg("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
            #{install_deep_merge}
            #{install_busser}
            #{custom_install_command}
          INSTALL
        end
      end
install_deep_merge() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 414
      def install_deep_merge
        return unless config[:hiera_deep_merge]
        <<-INSTALL
          # Support for hash merge lookups to recursively merge hash keys
          if [[ $(#{sudo('gem')} list deep_merge -i) == 'false' ]]; then
            echo '-----> Installing deep_merge to provide deep_merge of hiera hashes'
            #{sudo('gem')} install #{gem_proxy_parm} --no-ri --no-rdoc deep_merge
          fi
        INSTALL
      end
install_eyaml(gem_cmd = 'gem') click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 425
      def install_eyaml(gem_cmd = 'gem')
        return unless config[:hiera_eyaml]
        <<-INSTALL
          # A backend for Hiera that provides per-value asymmetric encryption of sensitive data
          if [[ $(#{sudo(gem_cmd)} list hiera-eyaml -i) == 'false' ]]; then
            echo '-----> Installing hiera-eyaml to provide encryption of hiera data'
            #{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc highline -v 1.6.21
            #{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml
          fi
        INSTALL
      end
install_eyaml_gpg(gem_cmd = 'gem') click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 437
      def install_eyaml_gpg(gem_cmd = 'gem')
        return unless config[:hiera_eyaml_gpg]
        <<-INSTALL
          # A backend for Hiera that provides per-value asymmetric encryption of sensitive data
          if [[ $(#{sudo(gem_cmd)} list hiera-eyaml-gpg -i) == 'false' ]]; then
            echo '-----> Installing hiera-eyaml-gpg to provide encryption of hiera data'
            #{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc highline -v 1.6.21
            #{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml
            #{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml-gpg
            #{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc ruby_gpg
          fi
        INSTALL
      end
install_hiera() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 503
      def install_hiera
        return unless config[:install_hiera]
        <<-INSTALL
        #{sudo_env('apt-get')} -y install #{hiera_package}
        INSTALL
      end
install_omnibus_command() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 484
      def install_omnibus_command
        info('Installing puppet using puppet omnibus')

        version = ''
        version = "-v #{config[:puppet_version]}" unless config[:puppet_version].nil?

        <<-INSTALL
        #{Util.shell_helpers}
        if [ ! $(which puppet) ]; then
          echo "-----> Installing Puppet Omnibus"
          #{export_http_proxy_parm}
          #{export_https_proxy_parm}
          #{export_no_proxy_parm}
          do_download #{config[:puppet_omnibus_url]} /tmp/install_puppet.sh
          #{sudo_env('sh')} /tmp/install_puppet.sh #{version}
        fi
        INSTALL
      end
install_puppet_yum_repo() click to toggle source

/bin/wget -P /etc/pki/rpm-gpg/ yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs changed to curl

# File lib/kitchen/provisioner/puppet_apply.rb, line 517
      def install_puppet_yum_repo
        <<-INSTALL
          rhelversion=$(cat /etc/redhat-release | grep 'release 7')
          # For CentOS7/RHEL7 the rdo release contains puppetlabs repo, creating conflict. Create temp-repo
          #{sudo_env('curl')} -o /etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
          if [ -n "$rhelversion" ]; then
          echo '[puppettemp-products]
          name=Puppet Labs Products - \$basearch
          baseurl=http://yum.puppetlabs.com/el/7/products/\$basearch
          gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs
          enabled=0
          gpgcheck=1
          [puppettemp-deps]
          name=Puppet Labs Dependencies - \$basearch
          baseurl=http://yum.puppetlabs.com/el/7/dependencies/\$basearch
          gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs
          enabled=0
          gpgcheck=1' | sudo tee /etc/yum.repos.d/puppettemp.repo > /dev/null
          sudo sed -i 's/^[ \t]*//' /etc/yum.repos.d/puppettemp.repo
            #{update_packages_redhat_cmd}
            #{sudo_env('yum')} -y --enablerepo=puppettemp-products --enablerepo=puppettemp-deps install puppet#{puppet_redhat_version}
            # Clean up temporary puppet repo
            sudo rm -rf /etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs
            sudo rm -rf /etc/yum.repos.d/puppettemp.repo
          else
            #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
            #{update_packages_redhat_cmd}
            #{sudo_env('yum')} -y --nogpgcheck install puppet#{puppet_redhat_version}
          fi
        INSTALL
      end
prepare_command() click to toggle source

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

# File lib/kitchen/provisioner/puppet_apply.rb, line 607
def prepare_command
  commands = []
  if puppet_git_init
    commands << [
      sudo('rm -rf'), '/etc/puppet'
    ].join(' ')

    commands << [
      sudo('git clone'), puppet_git_init, '/etc/puppet'
    ].join(' ')
  end

  if puppet_git_pr
    commands << [
      sudo('git'),
      '--git-dir=/etc/puppet/.git/',
      'fetch -f',
      'origin',
      "pull/#{puppet_git_pr}/head:pr_#{puppet_git_pr}"
    ].join(' ')

    commands << [
      sudo('git'),
      '--git-dir=/etc/puppet/.git/',
      '--work-tree=/etc/puppet/',
      'checkout',
      "pr_#{puppet_git_pr}"
    ].join(' ')
  end

  if puppet_config
    commands << [
      sudo(cp_command),
      File.join(config[:root_path], 'puppet.conf'),
      puppet_dir
    ].join(' ')
  end

  if fileserver_config
    commands << [
      sudo(cp_command),
      File.join(config[:root_path], 'fileserver.conf'),
      puppet_dir
    ].join(' ')
  end

  if hiera_data
    commands << [
      sudo(mkdir_command), hiera_data_remote_path
    ].join(' ')
    commands << [
      sudo("#{cp_command} -r"), File.join(config[:root_path], 'hiera/*'), hiera_data_remote_path
    ].join(' ')
  end

  if hiera_eyaml
    commands << [
      sudo(mkdir_command), hiera_eyaml_key_remote_path
    ].join(' ')
    commands << [
      sudo("#{cp_command} -r"), File.join(config[:root_path], 'hiera_keys/*'), hiera_eyaml_key_remote_path
    ].join(' ')
  end

  if hiera_eyaml_gpg
    commands << [
      sudo('mkdir -p'), hiera_eyaml_gpg_remote_path
    ].join(' ')
    commands << [
      sudo('cp -r'), File.join(config[:root_path], hiera_eyaml_gpg_recipients), hiera_eyaml_gpg_remote_path
    ].join(' ')
    commands << [
      sudo('cp -r'), File.join(config[:root_path], hiera_eyaml_gpg_secring), hiera_eyaml_gpg_remote_path
    ].join(' ')
    commands << [
      sudo('cp -r'), File.join(config[:root_path], hiera_eyaml_gpg_pubring), hiera_eyaml_gpg_remote_path
    ].join(' ')
  end

  if puppet_environment
    commands << [
      sudo('ln -s '), config[:root_path], File.join(puppet_dir, puppet_environment)
    ].join(' ')
  end

  if puppet_environment_config && puppet_environment
    commands << [
      sudo(mkdir_command), puppet_environmentpath_remote_path
    ].join(' ')
    commands << [
      sudo(mkdir_command), File.join(puppet_environmentpath_remote_path, puppet_environment)
    ].join(' ')
    commands << [
      sudo('ln -s '), File.join(config[:root_path], 'modules'), File.join(puppet_environmentpath_remote_path, puppet_environment, puppet_environment_remote_modules_path)
    ].join(' ')
    commands << [
      sudo('ln -s '), File.join(config[:root_path], 'manifests'), File.join(puppet_environmentpath_remote_path, puppet_environment, puppet_environment_remote_manifests_path)
    ].join(' ')
    commands << [
      sudo('ln -s '), File.join(config[:root_path], 'hiera'), File.join(puppet_environmentpath_remote_path, puppet_environment, puppet_environment_remote_hieradata_path)
    ].join(' ')
    commands << [
      sudo('cp'), File.join(config[:root_path], 'environment', 'environment.conf'), File.join(puppet_environmentpath_remote_path, puppet_environment, 'environment.conf')
    ].join(' ')
    commands << [
      sudo('cp'), File.join(config[:root_path], 'environment', 'hiera.yaml'), File.join(puppet_environmentpath_remote_path, puppet_environment, 'hiera.yaml')
    ].join(' ')
  end

  if spec_files_path && spec_files_remote_path
    commands << [
      sudo(mkdir_command), spec_files_remote_path
    ].join(' ')
    commands << [
      sudo("#{cp_command} -r"), File.join(config[:root_path], 'spec/*'), spec_files_remote_path
    ].join(' ')
  end

  if config[:puppet_enc]
    commands << [
      sudo('chmod 755'), File.join("#{config[:root_path]}/enc", File.basename(config[:puppet_enc]))
    ].join(' ')
  end

  command = powershell? ? commands.join('; ') : commands.join(' && ')
  debug(command)
  command
end
run_command() click to toggle source

rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

# File lib/kitchen/provisioner/puppet_apply.rb, line 737
      def run_command
        return config[:puppet_apply_command] unless config[:puppet_apply_command].nil?
        result = [
          facterlib,
          custom_facts,
          puppet_manifestdir,
          puppet_cmd,
          'apply',
          File.join(config[:root_path], 'manifests', manifest),
          "--modulepath=#{File.join(config[:root_path], 'modules')}",
          "--fileserverconfig=#{File.join(config[:root_path], 'fileserver.conf')}",
          custom_options,
          puppet_environment_flag,
          puppet_noop_flag,
          puppet_enc_flag,
          puppet_hiera_flag,
          puppet_detailed_exitcodes_flag,
          puppet_verbose_flag,
          puppet_debug_flag,
          puppet_logdest_flag,
          puppet_future_parser_flag,
          puppet_show_diff_flag,
          puppet_whitelist_exit_code
        ].join(' ')
        if config[:custom_post_apply_command]
          custom_post_apply_trap = <<-TRAP
            function custom_post_apply_command {
              #{config[:custom_post_apply_command]}
            }
            trap custom_post_apply_command EXIT
          TRAP
        end
        result = <<-RUN
          #{config[:custom_pre_apply_command]}
          #{custom_post_apply_trap}
          #{result}
        RUN
        info("Going to invoke puppet apply with: #{result}")
        result
      end

Protected Instance Methods

chef_url() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1249
def chef_url
  config[:chef_bootstrap_url]
end
copy_modules(modules, destination) click to toggle source

rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

# File lib/kitchen/provisioner/puppet_apply.rb, line 1342
def copy_modules(modules, destination)
  excluded_paths = %w[modules pkg] + config[:ignored_paths_from_root]
  debug("Copying modules to directory: #{destination}")
  modules.each do |name, source|
    next unless File.directory?(source)
    debug("Copying module #{name} from #{source}...")
    target = "#{destination}/#{name}"
    FileUtils.mkdir_p(target) unless File.exist? target
    FileUtils.cp_r(
      Dir.glob("#{source}/*").reject { |entry| entry =~ /#{excluded_paths.join('$|')}$/ },
      target,
      remove_destination: true
    )
  end
end
cp_command() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1480
def cp_command
  return 'cp -force' if powershell?
  'cp'
end
custom_facts() click to toggle source

rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

# File lib/kitchen/provisioner/puppet_apply.rb, line 1090
def custom_facts
  return nil if config[:custom_facts].none?
  return nil if config[:install_custom_facts]
  if powershell?
    environment_vars = config[:custom_facts].map { |k, v| "$env:FACTER_#{k}='#{v}'" }.join('; ')
    environment_vars = "#{environment_vars};"
  else
    environment_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
    environment_vars = "export #{environment_vars};"
  end
  debug(environment_vars)
  environment_vars
end
custom_options() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1011
def custom_options
  config[:custom_options] || ''
end
export_http_proxy_parm() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1225
def export_http_proxy_parm
  http_proxy ? "export http_proxy=#{http_proxy}" : nil
end
export_https_proxy_parm() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1229
def export_https_proxy_parm
  https_proxy ? "export https_proxy=#{https_proxy}" : nil
end
export_no_proxy_parm() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1233
def export_no_proxy_parm
  no_proxy ? "export no_proxy=#{no_proxy}" : nil
end
facter_debian_version() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 970
def facter_debian_version
  config[:facter_version] ? "=#{config[:facter_version]}" : nil
end
facterlib() click to toggle source

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

# File lib/kitchen/provisioner/puppet_apply.rb, line 1077
def facterlib
  factpath = nil
  factpath = File.join(config[:root_path], 'facter').to_s if config[:install_custom_facts] && config[:custom_facts].any?
  factpath = File.join(config[:root_path], 'facter').to_s if config[:facter_file]
  factpath = "#{factpath}:" if config[:facterlib] && !factpath.nil?
  factpath = "#{factpath}#{config[:facterlib]}" if config[:facterlib]
  return nil if factpath.nil?
  bash_vars = "export FACTERLIB='#{factpath}';"
  debug(bash_vars)
  bash_vars
end
files() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 822
def files
  config[:files_path] || 'files'
end
fileserver_config() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 869
def fileserver_config
  config[:fileserver_config_path]
end
gem_proxy_parm() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1202
def gem_proxy_parm
  p = http_proxy ? "--http-proxy #{http_proxy}" : nil
  n = no_proxy ? "--no-http-proxy #{no_proxy}" : nil
  p || n ? "#{p} #{n}" : nil
end
hiera_config() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 861
def hiera_config
  config[:hiera_config_path]
end
hiera_config_dir() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 961
def hiera_config_dir
  return 'C:/ProgramData/PuppetLabs/puppet/etc' if powershell?
  config[:require_puppet_collections] ? '/etc/puppetlabs/code' : '/etc/puppet'
end
hiera_data() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 873
def hiera_data
  config[:hiera_data_path]
end
hiera_data_remote_path() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 877
def hiera_data_remote_path
  return config[:hiera_data_remote_path] if config[:hiera_data_remote_path]

  if config[:require_puppet_collections]
    powershell? ? 'C:/ProgramData/PuppetLabs/code/environments/production/hieradata' : '/etc/puppetlabs/code/environments/production/hieradata'
  else
    powershell? ? 'C:/ProgramData/PuppetLabs/hiera/var' : '/var/lib/hiera'
  end
end
hiera_deep_merge() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 923
def hiera_deep_merge
  config[:hiera_deep_merge]
end
hiera_eyaml() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 891
def hiera_eyaml
  config[:hiera_eyaml]
end
hiera_eyaml_gpg() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 895
def hiera_eyaml_gpg
  config[:hiera_eyaml_gpg]
end
hiera_eyaml_gpg_pubring() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 907
def hiera_eyaml_gpg_pubring
  config[:hiera_eyaml_gpg_pubring]
end
hiera_eyaml_gpg_recipients() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 899
def hiera_eyaml_gpg_recipients
  config[:hiera_eyaml_gpg_recipients]
end
hiera_eyaml_gpg_remote_path() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 911
def hiera_eyaml_gpg_remote_path
  config[:hiera_eyaml_gpg_remote_path]
end
hiera_eyaml_gpg_secring() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 903
def hiera_eyaml_gpg_secring
  config[:hiera_eyaml_gpg_secring]
end
hiera_eyaml_key_path() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 915
def hiera_eyaml_key_path
  config[:hiera_eyaml_key_path]
end
hiera_eyaml_key_remote_path() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 919
def hiera_eyaml_key_remote_path
  config[:hiera_eyaml_key_remote_path]
end
hiera_writer() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 887
def hiera_writer
  config[:hiera_writer_files]
end
http_proxy() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1237
def http_proxy
  config[:http_proxy]
end
https_proxy() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1241
def https_proxy
  config[:https_proxy]
end
librarian_puppet_ssl_file() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 927
def librarian_puppet_ssl_file
  config[:librarian_puppet_ssl_file]
end
load_needed_dependencies!() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 780
def load_needed_dependencies!
  return unless File.exist?(puppetfile)
  return unless config[:resolve_with_librarian_puppet] || config[:resolve_with_r10k]
  if config[:resolve_with_librarian_puppet]
    require 'kitchen/provisioner/puppet/librarian'
    debug("Puppetfile found at #{puppetfile}, loading Librarian-Puppet")
    Puppet::Librarian.load!(logger)
  elsif config[:resolve_with_r10k]
    require 'kitchen/provisioner/puppet/r10k'
    debug("Puppetfile found at #{puppetfile}, loading R10K")
    Puppet::R10K.load!(logger)
  end
end
manifest() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 810
def manifest
  config[:manifest]
end
manifests() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 814
def manifests
  config[:manifests_path]
end
metadata_json() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 806
def metadata_json
  config[:metadata_json_path] || ''
end
mkdir_command() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1490
def mkdir_command
  return 'mkdir -force -path' if powershell?
  'mkdir -p'
end
modulefile() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 802
def modulefile
  config[:modulefile_path] || ''
end
modules() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 818
def modules
  config[:modules_path]
end
no_proxy() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1245
def no_proxy
  config[:no_proxy]
end
posh_proxy_parm() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1215
def posh_proxy_parm
  http_proxy ? "-Proxy #{http_proxy}" : nil
end
powershell?() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1219
def powershell?
  return true if powershell_shell?
  return true if puppet_platform =~ /^windows.*/
  false
end
prepare_enc() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1383
def prepare_enc
  return unless config[:puppet_enc]
  info 'Copying enc file'
  enc_dir = File.join(sandbox_path, 'enc')
  FileUtils.mkdir_p(enc_dir)
  FileUtils.cp_r(config[:puppet_enc], File.join(enc_dir, '/'))
end
prepare_facter_file() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1276
def prepare_facter_file
  return unless config[:facter_file]
  info 'Copying facter file'
  facter_dir = File.join(sandbox_path, 'facter')
  FileUtils.mkdir_p(facter_dir)
  FileUtils.cp_r(config[:facter_file], facter_dir)
end
prepare_facts() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1284
def prepare_facts
  return unless config[:install_custom_facts]
  return unless config[:custom_facts]
  info 'Installing custom facts'
  facter_dir = File.join(sandbox_path, 'facter')
  FileUtils.mkdir_p(facter_dir)
  tmp_facter_file = File.join(facter_dir, 'kitchen.rb')
  facter_facts = Hash[config[:custom_facts]]
  File.open(tmp_facter_file, 'a') do |out|
    facter_facts.each do |k, v|
      out.write "\nFacter.add(:#{k}) do\n"
      out.write "  setcode do\n"
      if [Array, Hash].include? v.class
        out.write "    #{v}\n"
      else
        out.write "    \"#{v}\"\n"
      end
      out.write "  end\n"
      out.write "end\n"
    end
  end
end
prepare_files() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1262
def prepare_files
  info('Preparing files')
  unless File.directory?(files)
    info 'nothing to do for files'
    return
  end

  debug("Using files from #{files}")

  tmp_files_dir = File.join(sandbox_path, 'files')
  FileUtils.mkdir_p(tmp_files_dir)
  FileUtils.cp_r(Dir.glob("#{files}/*"), tmp_files_dir)
end
prepare_fileserver_config() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1416
def prepare_fileserver_config
  return unless fileserver_config

  info('Preparing fileserver')
  debug("Using fileserver config from #{fileserver_config}")

  FileUtils.cp_r(fileserver_config, File.join(sandbox_path, 'fileserver.conf'))
end
prepare_hiera_config() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1407
def prepare_hiera_config
  return unless hiera_config

  info('Preparing hiera (global layer)')
  debug("Using hiera from #{hiera_config}")

  FileUtils.cp_r(hiera_config, File.join(sandbox_path, 'hiera.global.yaml'))
end
prepare_hiera_data() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1425
def prepare_hiera_data
  return unless hiera_data
  info('Preparing hiera data')
  tmp_hiera_dir = File.join(sandbox_path, 'hiera')
  debug("Copying hiera data from #{hiera_data} to #{tmp_hiera_dir}")
  FileUtils.mkdir_p(tmp_hiera_dir)
  FileUtils.cp_r(Dir.glob("#{hiera_data}/*"), tmp_hiera_dir)
  if hiera_writer
    hiera_writer.each do |file|
      file.each do |filename, hiera_hash|
        debug("Creating hiera yaml file #{tmp_hiera_dir}/#{filename}")
        dir = File.join(tmp_hiera_dir, File.dirname(filename.to_s))
        FileUtils.mkdir_p(dir)
        output_file = open(File.join(dir, File.basename(filename.to_s)), 'w')
        # convert json and back before converting to yaml to recursively convert symbols to strings, heh
        output_file.write JSON[hiera_hash.to_json].to_yaml
        output_file.close
      end
    end
  end
  return unless hiera_eyaml_key_path
  tmp_hiera_key_dir = File.join(sandbox_path, 'hiera_keys')
  debug("Copying hiera eyaml keys from #{hiera_eyaml_key_path} to #{tmp_hiera_key_dir}")
  FileUtils.mkdir_p(tmp_hiera_key_dir)
  FileUtils.cp_r(Dir.glob("#{hiera_eyaml_key_path}/*"), tmp_hiera_key_dir)
end
prepare_manifests() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1253
def prepare_manifests
  info('Preparing manifests')
  debug("Using manifests from #{manifests}")

  tmp_manifests_dir = File.join(sandbox_path, 'manifests')
  FileUtils.mkdir_p(tmp_manifests_dir)
  FileUtils.cp_r(Dir.glob("#{manifests}/*"), tmp_manifests_dir)
end
prepare_modules() click to toggle source

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

# File lib/kitchen/provisioner/puppet_apply.rb, line 1308
def prepare_modules
  info('Preparing modules')

  FileUtils.mkdir_p(tmpmodules_dir)
  resolve_with_librarian if File.exist?(puppetfile) && config[:resolve_with_librarian_puppet]
  resolve_with_r10k if File.exist?(puppetfile) && config[:resolve_with_r10k] && !config[:resolve_with_librarian_puppet]
  modules_to_copy = {}

  # If root dir (.) is a module, add it for copying
  self_name = read_self_module_name
  modules_to_copy[self_name] = '.' if self_name

  if modules
    modules_array = modules.split(':')
    modules_array.each do |m_path|
      Dir.glob("#{m_path}/*").each do |m|
        name = File.basename(m)
        if modules_to_copy.include? name
          debug("Found duplicated module: #{name}. The path taking precedence: '#{modules_to_copy[name]}', ignoring '#{m}'")
        else
          modules_to_copy[name] = m
        end
      end
    end
  end

  if modules_to_copy.empty?
    info 'Nothing to do for modules'
  else
    copy_modules(modules_to_copy, tmpmodules_dir)
  end
end
prepare_puppet_config() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1374
def prepare_puppet_config
  return unless puppet_config

  info('Preparing puppet.conf')
  debug("Using puppet config from #{puppet_config}")

  FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
end
prepare_puppet_environment() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1391
def prepare_puppet_environment
  return unless puppet_environment_config

  info('Preparing Environment Config')
  environment_dir = File.join(sandbox_path, 'environment')
  FileUtils.mkdir_p(environment_dir)
  debug("Using Environment Config environment.conf from #{puppet_environment_config}")
  FileUtils.cp_r(puppet_environment_config, File.join(environment_dir, 'environment.conf'))
  if puppet_environment_hiera_config
    debug("Using Environment Hiera Config hiera.yaml from #{puppet_environment_hiera_config}")
    FileUtils.cp_r(puppet_environment_hiera_config, File.join(environment_dir, 'hiera.yaml'))
  else
    info('No Environment hiera.yaml found')
  end
end
prepare_spec_files() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1452
def prepare_spec_files
  return unless spec_files_path
  info('Preparing spec files')
  tmp_spec_dir = File.join(sandbox_path, 'spec')
  debug("Copying specs from #{spec_files_path} to #{tmp_spec_dir}")
  FileUtils.mkdir_p(tmp_spec_dir)
  FileUtils.cp_r(Dir.glob(File.join(spec_files_path, '*')).reject { |entry| entry =~ /fixtures$/ }, tmp_spec_dir) if config[:ignore_spec_fixtures]
  FileUtils.cp_r(Dir.glob("#{spec_files_path}/*"), tmp_spec_dir) unless config[:ignore_spec_fixtures]
end
proxy_parm() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1198
def proxy_parm
  http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
end
puppet_apt_coll_repo_file() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1190
def puppet_apt_coll_repo_file
  config[:puppet_apt_collections_repo].split('/').last
end
puppet_apt_repo() click to toggle source

rubocop:disable Metrics/CyclomaticComplexity

# File lib/kitchen/provisioner/puppet_apply.rb, line 1131
def puppet_apt_repo
  platform_version = config[:platform].partition('-')[2]
  case puppet_platform
  when 'ubuntu'
    case platform_version
    when '20.04'
      # focal Repo
      'https://apt.puppetlabs.com/puppet-release-focal.deb'
    when '18.04'
      # bionic Repo
      'https://apt.puppetlabs.com/puppet-release-bionic.deb'
    when '16.04'
      # xenial Repo
      'https://apt.puppetlabs.com/puppet-release-xenial.deb'          
    when '14.10'
      # Utopic Repo
      'https://apt.puppetlabs.com/puppetlabs-release-utopic.deb'
    when '14.04'
      # Trusty Repo
      'https://apt.puppetlabs.com/puppetlabs-release-trusty.deb'
    when '12.04'
      # Precise Repo
      'https://apt.puppetlabs.com/puppetlabs-release-precise.deb'
    else
      # Configured Repo
      config[:puppet_apt_repo]
    end
  when 'debian'
    case platform_version.gsub(/\..*/, '')
     when '10'
       # Debian buster
       'https://apt.puppetlabs.com/puppet-tools-release-buster.deb'
     when '9'
       # Debian xenial
      'https://apt.puppetlabs.com/puppet-tools-release-stretch.deb'
    when '8'
      # Debian Jessie
      'https://apt.puppetlabs.com/puppetlabs-release-jessie.deb'
    when '7'
      # Debian Wheezy
      'https://apt.puppetlabs.com/puppetlabs-release-wheezy.deb'
    when '6'
      # Debian Squeeze
      'https://apt.puppetlabs.com/puppetlabs-release-squeeze.deb'
    else
      # Configured Repo
      config[:puppet_apt_repo]
    end
  else
    debug("Apt repo detection failed with platform - #{config[:platform]}")
    false
  end
end
puppet_apt_repo_file() click to toggle source

rubocop:enable Metrics/CyclomaticComplexity

# File lib/kitchen/provisioner/puppet_apply.rb, line 1186
def puppet_apt_repo_file
  puppet_apt_repo.split('/').last if puppet_apt_repo
end
puppet_cmd() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 935
def puppet_cmd
  return '& "C:\Program Files\Puppet Labs\Puppet\bin\puppet"' if powershell?

  puppet_bin = config[:require_puppet_collections] ? "#{config[:puppet_coll_remote_path]}/bin/puppet" : config[:puppet_binary]

  if config[:puppet_no_sudo]
    puppet_bin
  else
    sudo_env(puppet_bin)
  end
end
puppet_config() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 826
def puppet_config
  config[:puppet_config_path]
end
puppet_debian_version() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 966
def puppet_debian_version
  config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
end
puppet_debug_flag() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1019
def puppet_debug_flag
  config[:puppet_debug] ? '-d' : nil
end
puppet_detailed_exitcodes_flag() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1112
def puppet_detailed_exitcodes_flag
  config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
end
puppet_dir() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 947
def puppet_dir
  return 'C:/ProgramData/PuppetLabs/puppet/etc' if powershell?
  config[:require_puppet_collections] ? '/etc/puppetlabs/puppet' : '/etc/puppet'
end
puppet_enc_flag() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1104
def puppet_enc_flag
  config[:puppet_enc] ? "--node_terminus=exec --external_nodes=#{config[:root_path]}/enc/#{File.basename(config[:puppet_enc])}" : nil
end
puppet_environment() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 830
def puppet_environment
  config[:puppet_environment]
end
puppet_environment_config() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 834
def puppet_environment_config
  if config[:puppet_environment_config_path] && !puppet_environment
    raise("ERROR: found environment config '#{config[:puppet_environment_config_path]}', however no 'puppet_environment' is specified. Please specify 'puppet_environment' or unset 'puppet_environment_config_path' in .kitchen.yml")
  end
  config[:puppet_environment_config_path]
end
puppet_environment_flag() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 994
def puppet_environment_flag
  if config[:puppet_version] =~ /^2/
    config[:puppet_environment] ? "--environment=#{puppet_environment}" : nil
  else
    config[:puppet_environment] ? "--environment=#{puppet_environment} --environmentpath=#{puppet_environmentpath_remote_path}" : nil
  end
end
puppet_environment_hiera_config() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 865
def puppet_environment_hiera_config
  config[:puppet_environment_hiera_config_path]
end
puppet_environment_remote_hieradata_path() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 849
def puppet_environment_remote_hieradata_path
  config[:puppet_environment_remote_hieradata_path]
end
puppet_environment_remote_manifests_path() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 845
def puppet_environment_remote_manifests_path
  config[:puppet_environment_remote_manifests_path]
end
puppet_environment_remote_modules_path() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 841
def puppet_environment_remote_modules_path
  config[:puppet_environment_remote_modules_path]
end
puppet_environmentpath_remote_path() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 952
def puppet_environmentpath_remote_path
  return config[:puppet_environmentpath_remote_path] if config[:puppet_environmentpath_remote_path]
  if config[:puppet_version] =~ /^3/
    powershell? ? 'C:/ProgramData/PuppetLabs/puppet/etc' : '/etc/puppet/environments'
  else
    powershell? ? 'C:/ProgramData/PuppetLabs/code/environments' : '/etc/puppetlabs/code/environments'
  end
end
puppet_future_parser_flag() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1031
def puppet_future_parser_flag
  config[:puppet_future_parser] ? '--parser=future' : nil
end
puppet_git_init() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 853
def puppet_git_init
  config[:puppet_git_init]
end
puppet_git_pr() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 857
def puppet_git_pr
  config[:puppet_git_pr]
end
puppet_hiera_debian_version() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 974
def puppet_hiera_debian_version
  config[:hiera_version] ? "=#{config[:hiera_version]}" : nil
end
puppet_hiera_flag() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1108
def puppet_hiera_flag
  hiera_config ? "--hiera_config=#{config[:root_path]}/hiera.global.yaml" : nil
end
puppet_logdest_flag() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1035
def puppet_logdest_flag
  return nil unless config[:puppet_logdest]
  destinations = ''
  config[:puppet_logdest].each do |dest|
    destinations << "--logdest #{dest} "
  end
  destinations
end
puppet_manifestdir() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1002
def puppet_manifestdir
  return nil if config[:require_puppet_collections]
  return nil if config[:puppet_environment]
  return nil if powershell?
  bash_vars = "export MANIFESTDIR='#{File.join(config[:root_path], 'manifests')}';"
  debug(bash_vars)
  bash_vars
end
puppet_noop_flag() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1015
def puppet_noop_flag
  config[:puppet_noop] ? '--noop' : nil
end
puppet_platform() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1044
def puppet_platform
  config[:platform].gsub(/-.*/, '')
end
puppet_redhat_version() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 978
def puppet_redhat_version
  if puppet_platform == 'amazon'
    config[:puppet_version]
  else
    config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
  end
end
puppet_show_diff_flag() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1027
def puppet_show_diff_flag
  config[:puppet_show_diff] ? '--show_diff' : nil
end
puppet_verbose_flag() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1023
def puppet_verbose_flag
  config[:puppet_verbose] ? '-v' : nil
end
puppet_whitelist_exit_code() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1120
def puppet_whitelist_exit_code
  if config[:puppet_whitelist_exit_code].nil?
    powershell? ? '; exit $LASTEXITCODE' : nil
  elsif powershell?
    "; if(@(#{[config[:puppet_whitelist_exit_code]].join(', ')}) -contains $LASTEXITCODE) {exit 0} else {exit $LASTEXITCODE}"
  else
    '; RC=$?; [ ' + [config[:puppet_whitelist_exit_code]].flatten.map { |x| "\$RC -eq #{x}" }.join(' -o ') + ' ] && exit 0; exit $RC'
  end
end
puppet_windows_msi_url() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 990
def puppet_windows_msi_url
  config[:puppet_windows_msi_url]
end
puppet_windows_version() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 986
def puppet_windows_version
  config[:puppet_version] ? config[:puppet_version].to_s : 'latest'
end
puppet_yum_repo() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1194
def puppet_yum_repo
  config[:puppet_yum_repo]
end
puppetfile() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 798
def puppetfile
  config[:puppetfile_path] || ''
end
r10k_ssl_file() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 931
def r10k_ssl_file
  config[:r10k_puppet_ssl_file] || config[:librarian_puppet_ssl_file]
end
read_self_module_name() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1358
def read_self_module_name
  if File.exist?(modulefile)
    warn('Modulefile found but this is deprecated, ignoring it, see https://tickets.puppetlabs.com/browse/PUP-1188')
  end

  return unless File.exist?(metadata_json)
  module_name = nil
  begin
    module_name = JSON.parse(IO.read(metadata_json))['name'].split('-').last
  rescue JSON::ParserError
    error("not able to load or parse #{metadata_json} for the name of the module")
  end

  module_name
end
remove_puppet_repo() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1064
def remove_puppet_repo
  config[:remove_puppet_repo]
end
remove_repo() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1116
def remove_repo
  remove_puppet_repo ? "#{sudo('rm')} -rf /tmp/kitchen #{hiera_data_remote_path} #{hiera_eyaml_key_remote_path} #{puppet_dir}/* " : nil
end
resolve_with_librarian() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1462
def resolve_with_librarian
  require 'kitchen/provisioner/puppet/librarian'
  Kitchen.mutex.synchronize do
    ENV['SSL_CERT_FILE'] = librarian_puppet_ssl_file if librarian_puppet_ssl_file
    Puppet::Librarian.new(puppetfile, tmpmodules_dir, logger).resolve
    ENV['SSL_CERT_FILE'] = '' if librarian_puppet_ssl_file
  end
end
resolve_with_r10k() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1471
def resolve_with_r10k
  require 'kitchen/provisioner/puppet/r10k'
  Kitchen.mutex.synchronize do
    ENV['SSL_CERT_FILE'] = r10k_ssl_file if r10k_ssl_file
    Puppet::R10K.new(puppetfile, tmpmodules_dir, logger).resolve
    ENV['SSL_CERT_FILE'] = '' if r10k_ssl_file
  end
end
rm_command() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1485
def rm_command
  return 'rm -force -recurse' if powershell?
  'rm -rf'
end
rm_command_paths(paths) click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1495
def rm_command_paths(paths)
  return :nil if paths.length.zero?
  return "#{rm_command} \"#{paths.join('", "')}\"" if powershell?
  "#{rm_command} #{paths.join(' ')}"
end
spec_files_path() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1068
def spec_files_path
  config[:spec_files_path]
end
spec_files_remote_path() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1072
def spec_files_remote_path
  config[:spec_files_remote_path]
end
sudo_env(pm) click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1057
def sudo_env(pm)
  s = https_proxy ? "https_proxy=#{https_proxy}" : nil
  p = http_proxy ? "http_proxy=#{http_proxy}" : nil
  n = no_proxy ? "no_proxy=#{no_proxy}" : nil
  p || s ? "#{sudo('env')} #{p} #{s} #{n} #{pm}" : sudo(pm).to_s
end
tmpmodules_dir() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 794
def tmpmodules_dir
  File.join(sandbox_path, 'modules')
end
update_packages_debian_cmd() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1048
def update_packages_debian_cmd
  config[:update_package_repos] ? "#{sudo_env('apt-get')} update" : nil
end
update_packages_redhat_cmd() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1052
def update_packages_redhat_cmd
  # #{sudo('yum')}
  config[:update_package_repos] ? "#{sudo_env('yum')} makecache" : nil
end
wget_proxy_parm() click to toggle source
# File lib/kitchen/provisioner/puppet_apply.rb, line 1208
def wget_proxy_parm
  p = http_proxy ? "-e http_proxy=#{http_proxy}" : nil
  s = https_proxy ? "-e https_proxy=#{https_proxy}" : nil
  n = no_proxy ? "-e no_proxy=#{no_proxy}" : nil
  p || s ? "-e use_proxy=yes #{p} #{s} #{n}" : nil
end