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
  "\#{config[:custom_install_command]}\n"
end

#custom_pre_install_commandObject



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

def custom_pre_install_command
  "\#{config[:custom_pre_install_command]}\n"
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]
    "\#{sudo('gem')} install --no-rdoc --no-ri bolt -v \#{config[:bolt_version]}\n"
  else
    "\#{sudo('gem')} install --no-rdoc --no-ri bolt\n"
  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

      "\n\#{custom_pre_install_command}\nif [ ! $(which bolt) ]; then\n\#{sudo('apt-get')} install -y make gcc ruby-dev\n\#{install_bolt}\nfi\n\#{custom_install_command}\n"
    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

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

      "\n\#{custom_pre_install_command}\nif [ ! $(which bolt) ]; then\n\#{sudo('dnf')} install -y make gcc redhat-rpm-config ruby-devel rubygem-rdoc\n\#{install_bolt}\nfi\n\#{custom_install_command}\n"
    when /^windows.*/
      info("Installing puppet on #{bolt_platform}")
      info('Powershell is not recognised by core test-kitchen assuming it is present') unless powershell_shell?
      "if(Get-Command bolt -ErrorAction 0) { return; }\nWrite-Host \"Disabling UAC...\"\nNew-ItemProperty -Path HKLM:Software\\\\Microsoft\\Windows\\\\CurrentVersion\\\\Policies\\\\System -Name EnableLUA -PropertyType DWord -Value 0 -Force\nNew-ItemProperty -Path HKLM:Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\System -Name ConsentPromptBehaviorAdmin -PropertyType DWord -Value 0 -Force\nWrite-Host \"Install Chocolatey....\"\niex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))\nWrite-Host \"Install Ruby....\"\nchoco install ruby\nrefreshenv\nWrite-Host \"Install Bolt....\"\ngem install bolt\n"
    else
      info('Installing bolt, will try to determine platform os')
      # need to add a CR to avoid trouble with proxy settings concatenation

      "\n\#{custom_pre_install_command}\nif [ ! $(which bolt) ]; then\nif [ -f  /etc/fedora-release ]; then\n\#{sudo('dnf')} install -y make gcc redhat-rpm-config ruby-devel rubygem-rdoc\nelse\nif [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then\n\#{sudo('yum')} install -y make gcc ruby-devel\nelse\nif [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then\n\#{sudo('yum')} install -y make gcc ruby-devel\nelse\n\#{sudo('apt-get')} install -y make gcc ruby-dev\nfi\nfi\nfi\n\#{install_bolt}\nfi\n\#{custom_install_command}\n"
    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 = "function custom_post_bolt_command {\n\#{config[:custom_post_bolt_command]}\n}\ntrap custom_post_bolt_command EXIT\n"
  end
  result = "\#{config[:custom_pre_bolt_command]}\n\#{custom_post_bolt_trap}\n"
  bolt_commands_to_run.each do |a|
    result = "\#{result}\n\#{a}\n"
  end
  info("Going to invoke bolt with: #{result}")
  result
end