class Kitchen::Provisioner::PuppetBolt

Puppet Bolt provisioner.

Attributes

tmp_dir[RW]

Public Instance Methods

cleanup_sandbox() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 197
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_bolt.rb, line 192
def create_sandbox
  super
  debug("Creating local sandbox in #{sandbox_path}")
end
custom_install_command() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 170
      def custom_install_command
        <<-INSTALL
          #{config[:custom_install_command]}
        INSTALL
      end
custom_pre_install_command() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 164
      def custom_pre_install_command
        <<-INSTALL
          #{config[:custom_pre_install_command]}
        INSTALL
      end
init_command() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 188
def init_command
  debug('Init Command')
end
install_bolt() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 176
      def install_bolt
        if config[:bolt_version]
          <<-INSTALL
            #{sudo('gem')} install --no-rdoc --no-ri bolt -v #{config[:bolt_version]}
          INSTALL
        else
          <<-INSTALL
            #{sudo('gem')} install --no-rdoc --no-ri bolt
          INSTALL
        end
      end
install_command() click to toggle source

Install the dependencies for your platform. On CentOS 7 or Red Hat Enterprise Linux 7, run yum install -y make gcc ruby-devel On Fedora 25, run dnf install -y make gcc redhat-rpm-config ruby-devel rubygem-rdoc On Debian 9 or Ubuntu 16.04, run apt-get install -y make gcc ruby-dev On Mac OS X, run xcode-select –install Install Bolt as a gem by running gem install bolt rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

# File lib/kitchen/provisioner/puppet_bolt.rb, line 73
      def install_command
        return unless config[:require_bolt_repo] || config[:require_bolt_omnibus]
        if config[:require_bolt_omnibus]
          install_omnibus_command
        else
          case bolt_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 bolt) ]; then
                #{sudo('apt-get')} install -y make gcc ruby-dev
                #{install_bolt}
              fi
              #{custom_install_command}
            INSTALL
          when 'redhat', 'centos', 'oracle', 'amazon'
            info("Installing puppet from yum on #{bolt_platform}")
            # need to add a CR to avoid trouble with proxy settings concatenation
            <<-INSTALL

              #{custom_pre_install_command}
              if [ ! $(which bolt) ]; then
                #{sudo('yum')} install -y make gcc ruby-devel
                #{install_bolt}
              fi
              #{custom_install_command}
            INSTALL
          when 'fedora'
            info("Installing bolt from dnf on #{bolt_platform}")
            # need to add a CR to avoid trouble with proxy settings concatenation
            <<-INSTALL

              #{custom_pre_install_command}
              if [ ! $(which bolt) ]; then
                #{sudo('dnf')} install -y make gcc redhat-rpm-config ruby-devel rubygem-rdoc
                #{install_bolt}
              fi
              #{custom_install_command}
            INSTALL
          when /^windows.*/
            info("Installing puppet on #{bolt_platform}")
            info('Powershell is not recognised by core test-kitchen assuming it is present') unless powershell_shell?
            <<-INSTALL
              if(Get-Command bolt -ErrorAction 0) { return; }
              Write-Host "Disabling UAC..."
              New-ItemProperty -Path HKLM:Software\\Microsoft\Windows\\CurrentVersion\\Policies\\System -Name EnableLUA -PropertyType DWord -Value 0 -Force
              New-ItemProperty -Path HKLM:Software\\Microsoft\\Windows\\CurrentVersion\\Policies\System -Name ConsentPromptBehaviorAdmin -PropertyType DWord -Value 0 -Force
              Write-Host "Install Chocolatey...."
              iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
              Write-Host "Install Ruby...."
              choco install ruby
              refreshenv
              Write-Host "Install Bolt...."
              gem install bolt
            INSTALL
          else
            info('Installing bolt, 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 bolt) ]; then
                if [ -f  /etc/fedora-release ]; then
                    #{sudo('dnf')} install -y make gcc redhat-rpm-config ruby-devel rubygem-rdoc
                else
                  if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
                      #{sudo('yum')} install -y make gcc ruby-devel
                  else
                    if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
                       #{sudo('yum')} install -y make gcc ruby-devel
                    else
                      #{sudo('apt-get')} install -y make gcc ruby-dev
                    fi
                  fi
                fi
                #{install_bolt}
              fi
              #{custom_install_command}
            INSTALL
          end
        end
      end
install_omnibus_command() click to toggle source

rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

# File lib/kitchen/provisioner/puppet_bolt.rb, line 160
def install_omnibus_command
  error('Installing bolt using an omnibus install script not currently supported')
end
run_command() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 206
      def run_command
        if config[:custom_post_bolt_command]
          custom_post_bolt_trap = <<-TRAP
            function custom_post_bolt_command {
              #{config[:custom_post_bolt_command]}
            }
            trap custom_post_bolt_command EXIT
          TRAP
        end
        result = <<-RUN
          #{config[:custom_pre_bolt_command]}
          #{custom_post_bolt_trap}
        RUN
        bolt_commands_to_run.each do |a|
          result = <<-RUN
          #{result}
          #{a}
          RUN
        end
        info("Going to invoke bolt with: #{result}")
        result
      end

Protected Instance Methods

bolt_commands_to_run() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 231
def bolt_commands_to_run
  if config[:bolt_commands]
    config[:bolt_commands].is_a?(Array) ? config[:bolt_commands] : [config[:bolt_commands]]
  else
    []
  end
end
bolt_platform() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 239
def bolt_platform
  config[:platform].gsub(/-.*/, '')
end
export_http_proxy_parm() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 281
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_bolt.rb, line 285
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_bolt.rb, line 289
def export_no_proxy_parm
  no_proxy ? "export no_proxy=#{no_proxy}" : nil
end
gem_proxy_parm() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 258
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
http_proxy() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 293
def http_proxy
  config[:http_proxy]
end
https_proxy() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 297
def https_proxy
  config[:https_proxy]
end
no_proxy() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 301
def no_proxy
  config[:no_proxy]
end
posh_proxy_parm() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 271
def posh_proxy_parm
  http_proxy ? "-Proxy #{http_proxy}" : nil
end
powershell?() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 275
def powershell?
  return true if powershell_shell?
  return true if bolt_platform =~ /^windows.*/
  false
end
proxy_parm() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 254
def proxy_parm
  http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
end
remove_repo() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 243
def remove_repo
  config[:remove_bolt_repo] ? "#{sudo('rm')} -rf /tmp/kitchen " : nil
end
sudo_env(pm) click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 247
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
wget_proxy_parm() click to toggle source
# File lib/kitchen/provisioner/puppet_bolt.rb, line 264
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