Class: Kitchen::Provisioner::PuppetBolt

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/provisioner/puppet_bolt.rb

Overview

Puppet Bolt provisioner.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tmp_dirObject

Returns the value of attribute tmp_dir.



38
39
40
# File 'lib/kitchen/provisioner/puppet_bolt.rb', line 38

def tmp_dir
  @tmp_dir
end

Instance Method Details

#cleanup_sandboxObject



198
199
200
201
202
203
204
205
# File 'lib/kitchen/provisioner/puppet_bolt.rb', line 198

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_sandboxObject



193
194
195
196
# File 'lib/kitchen/provisioner/puppet_bolt.rb', line 193

def create_sandbox
  super
  debug("Creating local sandbox in #{sandbox_path}")
end

#custom_install_commandObject



171
172
173
174
175
# File 'lib/kitchen/provisioner/puppet_bolt.rb', line 171

def custom_install_command
  <<-INSTALL
    #{config[:custom_install_command]}
  INSTALL
end

#custom_pre_install_commandObject



165
166
167
168
169
# File 'lib/kitchen/provisioner/puppet_bolt.rb', line 165

def custom_pre_install_command
  <<-INSTALL
    #{config[:custom_pre_install_command]}
  INSTALL
end

#init_commandObject



189
190
191
# File 'lib/kitchen/provisioner/puppet_bolt.rb', line 189

def init_command
  debug('Init Command')
end

#install_boltObject



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/kitchen/provisioner/puppet_bolt.rb', line 177

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_commandObject

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



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/kitchen/provisioner/puppet_bolt.rb', line 74

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_commandObject

rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



161
162
163
# File 'lib/kitchen/provisioner/puppet_bolt.rb', line 161

def install_omnibus_command
  error('Installing bolt using an omnibus install script not currently supported')
end

#run_commandObject



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/kitchen/provisioner/puppet_bolt.rb', line 207

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