kitchen-puppet 3.4.1 → 3.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,307 +1,307 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- #
4
- # Author:: Neill Turner (<neillwturner@gmail.com>
5
- #
6
- # Copyright (C) 2017 Neill Turner
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
- #
20
- #
21
-
22
- require 'uri'
23
- require 'json'
24
- require 'kitchen'
25
-
26
- module Kitchen
27
- module Configurable
28
- def platform_name
29
- instance.platform.name
30
- end
31
- end
32
-
33
- module Provisioner
34
- #
35
- # Puppet Bolt provisioner.
36
- #
37
- class PuppetBolt < Base
38
- attr_accessor :tmp_dir
39
-
40
- default_config :bolt_version, nil
41
- default_config :require_bolt_repo, true
42
- default_config :remove_bolt_repo, false
43
- default_config :custom_install_command, nil
44
- default_config :custom_pre_install_command, nil
45
- default_config :custom_pre_bolt_command, nil
46
- default_config :custom_post_bolt_command, nil
47
- default_config :require_bolt_omnibus, false
48
- default_config :bolt_commands, []
49
- default_config :platform, &:platform_name
50
- default_config :http_proxy, nil
51
- default_config :https_proxy, nil
52
- default_config :no_proxy, nil
53
- # for future use
54
- # bolt command run <COMMAND>, bolt script run, bolt task run, bolt plan run, bolt file upload
55
- default_config :bolt_cmd, nil
56
- default_config :bolt_nodes, nil
57
- # BOLT_USER env variable
58
- default_config :bolt_user, nil
59
- default_config :bolt_password, nil
60
- # Required for tasks and plans. The path to the module containing the task. Separate multiple paths with a semicolon (;) on Windows or a colon (:) on all other platforms.
61
- default_config :bolt_modulepath, []
62
- default_config :bolt_params, nil
63
- default_config :bolt_tty, false
64
- default_config :bolt_insecure, true
65
- default_config :bolt_transport, nil
66
-
67
- # Install the dependencies for your platform.
68
- # On CentOS 7 or Red Hat Enterprise Linux 7, run yum install -y make gcc ruby-devel
69
- # On Fedora 25, run dnf install -y make gcc redhat-rpm-config ruby-devel rubygem-rdoc
70
- # On Debian 9 or Ubuntu 16.04, run apt-get install -y make gcc ruby-dev
71
- # On Mac OS X, run xcode-select --install
72
- # Install Bolt as a gem by running gem install bolt
73
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
74
- def install_command
75
- return unless config[:require_bolt_repo] || config[:require_bolt_omnibus]
76
- if config[:require_bolt_omnibus]
77
- install_omnibus_command
78
- else
79
- case bolt_platform
80
- when 'debian', 'ubuntu'
81
- info("Installing puppet on #{config[:platform]}")
82
- # need to add a CR to avoid trouble with proxy settings concatenation
83
- <<-INSTALL
84
-
85
- #{custom_pre_install_command}
86
- if [ ! $(which bolt) ]; then
87
- #{sudo('apt-get')} install -y make gcc ruby-dev
88
- #{install_bolt}
89
- fi
90
- #{custom_install_command}
91
- INSTALL
92
- when 'redhat', 'centos', 'oracle', 'amazon'
93
- info("Installing puppet from yum on #{bolt_platform}")
94
- # need to add a CR to avoid trouble with proxy settings concatenation
95
- <<-INSTALL
96
-
97
- #{custom_pre_install_command}
98
- if [ ! $(which bolt) ]; then
99
- #{sudo('yum')} install -y make gcc ruby-devel
100
- #{install_bolt}
101
- fi
102
- #{custom_install_command}
103
- INSTALL
104
- when 'fedora'
105
- info("Installing bolt from dnf on #{bolt_platform}")
106
- # need to add a CR to avoid trouble with proxy settings concatenation
107
- <<-INSTALL
108
-
109
- #{custom_pre_install_command}
110
- if [ ! $(which bolt) ]; then
111
- #{sudo('dnf')} install -y make gcc redhat-rpm-config ruby-devel rubygem-rdoc
112
- #{install_bolt}
113
- fi
114
- #{custom_install_command}
115
- INSTALL
116
- when /^windows.*/
117
- info("Installing puppet on #{bolt_platform}")
118
- info('Powershell is not recognised by core test-kitchen assuming it is present') unless powershell_shell?
119
- <<-INSTALL
120
- if(Get-Command bolt -ErrorAction 0) { return; }
121
- Write-Host "Disabling UAC..."
122
- New-ItemProperty -Path HKLM:Software\\Microsoft\Windows\\CurrentVersion\\Policies\\System -Name EnableLUA -PropertyType DWord -Value 0 -Force
123
- New-ItemProperty -Path HKLM:Software\\Microsoft\\Windows\\CurrentVersion\\Policies\System -Name ConsentPromptBehaviorAdmin -PropertyType DWord -Value 0 -Force
124
- Write-Host "Install Chocolatey...."
125
- iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
126
- Write-Host "Install Ruby...."
127
- choco install ruby
128
- refreshenv
129
- Write-Host "Install Bolt...."
130
- gem install bolt
131
- INSTALL
132
- else
133
- info('Installing bolt, will try to determine platform os')
134
- # need to add a CR to avoid trouble with proxy settings concatenation
135
- <<-INSTALL
136
-
137
- #{custom_pre_install_command}
138
- if [ ! $(which bolt) ]; then
139
- if [ -f /etc/fedora-release ]; then
140
- #{sudo('dnf')} install -y make gcc redhat-rpm-config ruby-devel rubygem-rdoc
141
- else
142
- if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
143
- #{sudo('yum')} install -y make gcc ruby-devel
144
- else
145
- if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
146
- #{sudo('yum')} install -y make gcc ruby-devel
147
- else
148
- #{sudo('apt-get')} install -y make gcc ruby-dev
149
- fi
150
- fi
151
- fi
152
- #{install_bolt}
153
- fi
154
- #{custom_install_command}
155
- INSTALL
156
- end
157
- end
158
- end
159
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
160
-
161
- def install_omnibus_command
162
- error('Installing bolt using an omnibus install script not currently supported')
163
- end
164
-
165
- def custom_pre_install_command
166
- <<-INSTALL
167
- #{config[:custom_pre_install_command]}
168
- INSTALL
169
- end
170
-
171
- def custom_install_command
172
- <<-INSTALL
173
- #{config[:custom_install_command]}
174
- INSTALL
175
- end
176
-
177
- def install_bolt
178
- if config[:bolt_version]
179
- <<-INSTALL
180
- #{sudo('gem')} install --no-rdoc --no-ri bolt -v #{config[:bolt_version]}
181
- INSTALL
182
- else
183
- <<-INSTALL
184
- #{sudo('gem')} install --no-rdoc --no-ri bolt
185
- INSTALL
186
- end
187
- end
188
-
189
- def init_command
190
- debug('Init Command')
191
- end
192
-
193
- def create_sandbox
194
- super
195
- debug("Creating local sandbox in #{sandbox_path}")
196
- end
197
-
198
- def cleanup_sandbox
199
- return if sandbox_path.nil?
200
- debug("Cleaning up local sandbox in #{sandbox_path}")
201
- FileUtils.rmtree(sandbox_path)
202
- return if remove_repo.nil?
203
- debug("Cleaning up remote sandbox: #{remove_repo}")
204
- instance.remote_exec remove_repo
205
- end
206
-
207
- def run_command
208
- if config[:custom_post_bolt_command]
209
- custom_post_bolt_trap = <<-TRAP
210
- function custom_post_bolt_command {
211
- #{config[:custom_post_bolt_command]}
212
- }
213
- trap custom_post_bolt_command EXIT
214
- TRAP
215
- end
216
- result = <<-RUN
217
- #{config[:custom_pre_bolt_command]}
218
- #{custom_post_bolt_trap}
219
- RUN
220
- bolt_commands_to_run.each do |a|
221
- result = <<-RUN
222
- #{result}
223
- #{a}
224
- RUN
225
- end
226
- info("Going to invoke bolt with: #{result}")
227
- result
228
- end
229
-
230
- protected
231
-
232
- def bolt_commands_to_run
233
- if config[:bolt_commands]
234
- config[:bolt_commands].is_a?(Array) ? config[:bolt_commands] : [config[:bolt_commands]]
235
- else
236
- []
237
- end
238
- end
239
-
240
- def bolt_platform
241
- config[:platform].gsub(/-.*/, '')
242
- end
243
-
244
- def remove_repo
245
- config[:remove_bolt_repo] ? "#{sudo('rm')} -rf /tmp/kitchen " : nil
246
- end
247
-
248
- def sudo_env(pm)
249
- s = https_proxy ? "https_proxy=#{https_proxy}" : nil
250
- p = http_proxy ? "http_proxy=#{http_proxy}" : nil
251
- n = no_proxy ? "no_proxy=#{no_proxy}" : nil
252
- p || s ? "#{sudo('env')} #{p} #{s} #{n} #{pm}" : sudo(pm).to_s
253
- end
254
-
255
- def proxy_parm
256
- http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
257
- end
258
-
259
- def gem_proxy_parm
260
- p = http_proxy ? "--http-proxy #{http_proxy}" : nil
261
- n = no_proxy ? "--no-http-proxy #{no_proxy}" : nil
262
- p || n ? "#{p} #{n}" : nil
263
- end
264
-
265
- def wget_proxy_parm
266
- p = http_proxy ? "-e http_proxy=#{http_proxy}" : nil
267
- s = https_proxy ? "-e https_proxy=#{https_proxy}" : nil
268
- n = no_proxy ? "-e no_proxy=#{no_proxy}" : nil
269
- p || s ? "-e use_proxy=yes #{p} #{s} #{n}" : nil
270
- end
271
-
272
- def posh_proxy_parm
273
- http_proxy ? "-Proxy #{http_proxy}" : nil
274
- end
275
-
276
- def powershell?
277
- return true if powershell_shell?
278
- return true if bolt_platform =~ /^windows.*/
279
- false
280
- end
281
-
282
- def export_http_proxy_parm
283
- http_proxy ? "export http_proxy=#{http_proxy}" : nil
284
- end
285
-
286
- def export_https_proxy_parm
287
- https_proxy ? "export https_proxy=#{https_proxy}" : nil
288
- end
289
-
290
- def export_no_proxy_parm
291
- no_proxy ? "export no_proxy=#{no_proxy}" : nil
292
- end
293
-
294
- def http_proxy
295
- config[:http_proxy]
296
- end
297
-
298
- def https_proxy
299
- config[:https_proxy]
300
- end
301
-
302
- def no_proxy
303
- config[:no_proxy]
304
- end
305
- end
306
- end
307
- end
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ #
4
+ # Author:: Neill Turner (<neillwturner@gmail.com>
5
+ #
6
+ # Copyright (C) 2017 Neill Turner
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ #
21
+
22
+ require 'uri'
23
+ require 'json'
24
+ require 'kitchen'
25
+
26
+ module Kitchen
27
+ module Configurable
28
+ def platform_name
29
+ instance.platform.name
30
+ end
31
+ end
32
+
33
+ module Provisioner
34
+ #
35
+ # Puppet Bolt provisioner.
36
+ #
37
+ class PuppetBolt < Base
38
+ attr_accessor :tmp_dir
39
+
40
+ default_config :bolt_version, nil
41
+ default_config :require_bolt_repo, true
42
+ default_config :remove_bolt_repo, false
43
+ default_config :custom_install_command, nil
44
+ default_config :custom_pre_install_command, nil
45
+ default_config :custom_pre_bolt_command, nil
46
+ default_config :custom_post_bolt_command, nil
47
+ default_config :require_bolt_omnibus, false
48
+ default_config :bolt_commands, []
49
+ default_config :platform, &:platform_name
50
+ default_config :http_proxy, nil
51
+ default_config :https_proxy, nil
52
+ default_config :no_proxy, nil
53
+ # for future use
54
+ # bolt command run <COMMAND>, bolt script run, bolt task run, bolt plan run, bolt file upload
55
+ default_config :bolt_cmd, nil
56
+ default_config :bolt_nodes, nil
57
+ # BOLT_USER env variable
58
+ default_config :bolt_user, nil
59
+ default_config :bolt_password, nil
60
+ # Required for tasks and plans. The path to the module containing the task. Separate multiple paths with a semicolon (;) on Windows or a colon (:) on all other platforms.
61
+ default_config :bolt_modulepath, []
62
+ default_config :bolt_params, nil
63
+ default_config :bolt_tty, false
64
+ default_config :bolt_insecure, true
65
+ default_config :bolt_transport, nil
66
+
67
+ # Install the dependencies for your platform.
68
+ # On CentOS 7 or Red Hat Enterprise Linux 7, run yum install -y make gcc ruby-devel
69
+ # On Fedora 25, run dnf install -y make gcc redhat-rpm-config ruby-devel rubygem-rdoc
70
+ # On Debian 9 or Ubuntu 16.04, run apt-get install -y make gcc ruby-dev
71
+ # On Mac OS X, run xcode-select --install
72
+ # Install Bolt as a gem by running gem install bolt
73
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
74
+ def install_command
75
+ return unless config[:require_bolt_repo] || config[:require_bolt_omnibus]
76
+ if config[:require_bolt_omnibus]
77
+ install_omnibus_command
78
+ else
79
+ case bolt_platform
80
+ when 'debian', 'ubuntu'
81
+ info("Installing puppet on #{config[:platform]}")
82
+ # need to add a CR to avoid trouble with proxy settings concatenation
83
+ <<-INSTALL
84
+
85
+ #{custom_pre_install_command}
86
+ if [ ! $(which bolt) ]; then
87
+ #{sudo('apt-get')} install -y make gcc ruby-dev
88
+ #{install_bolt}
89
+ fi
90
+ #{custom_install_command}
91
+ INSTALL
92
+ when 'redhat', 'centos', 'oracle', 'amazon'
93
+ info("Installing puppet from yum on #{bolt_platform}")
94
+ # need to add a CR to avoid trouble with proxy settings concatenation
95
+ <<-INSTALL
96
+
97
+ #{custom_pre_install_command}
98
+ if [ ! $(which bolt) ]; then
99
+ #{sudo('yum')} install -y make gcc ruby-devel
100
+ #{install_bolt}
101
+ fi
102
+ #{custom_install_command}
103
+ INSTALL
104
+ when 'fedora'
105
+ info("Installing bolt from dnf on #{bolt_platform}")
106
+ # need to add a CR to avoid trouble with proxy settings concatenation
107
+ <<-INSTALL
108
+
109
+ #{custom_pre_install_command}
110
+ if [ ! $(which bolt) ]; then
111
+ #{sudo('dnf')} install -y make gcc redhat-rpm-config ruby-devel rubygem-rdoc
112
+ #{install_bolt}
113
+ fi
114
+ #{custom_install_command}
115
+ INSTALL
116
+ when /^windows.*/
117
+ info("Installing puppet on #{bolt_platform}")
118
+ info('Powershell is not recognised by core test-kitchen assuming it is present') unless powershell_shell?
119
+ <<-INSTALL
120
+ if(Get-Command bolt -ErrorAction 0) { return; }
121
+ Write-Host "Disabling UAC..."
122
+ New-ItemProperty -Path HKLM:Software\\Microsoft\Windows\\CurrentVersion\\Policies\\System -Name EnableLUA -PropertyType DWord -Value 0 -Force
123
+ New-ItemProperty -Path HKLM:Software\\Microsoft\\Windows\\CurrentVersion\\Policies\System -Name ConsentPromptBehaviorAdmin -PropertyType DWord -Value 0 -Force
124
+ Write-Host "Install Chocolatey...."
125
+ iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
126
+ Write-Host "Install Ruby...."
127
+ choco install ruby
128
+ refreshenv
129
+ Write-Host "Install Bolt...."
130
+ gem install bolt
131
+ INSTALL
132
+ else
133
+ info('Installing bolt, will try to determine platform os')
134
+ # need to add a CR to avoid trouble with proxy settings concatenation
135
+ <<-INSTALL
136
+
137
+ #{custom_pre_install_command}
138
+ if [ ! $(which bolt) ]; then
139
+ if [ -f /etc/fedora-release ]; then
140
+ #{sudo('dnf')} install -y make gcc redhat-rpm-config ruby-devel rubygem-rdoc
141
+ else
142
+ if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
143
+ #{sudo('yum')} install -y make gcc ruby-devel
144
+ else
145
+ if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
146
+ #{sudo('yum')} install -y make gcc ruby-devel
147
+ else
148
+ #{sudo('apt-get')} install -y make gcc ruby-dev
149
+ fi
150
+ fi
151
+ fi
152
+ #{install_bolt}
153
+ fi
154
+ #{custom_install_command}
155
+ INSTALL
156
+ end
157
+ end
158
+ end
159
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
160
+
161
+ def install_omnibus_command
162
+ error('Installing bolt using an omnibus install script not currently supported')
163
+ end
164
+
165
+ def custom_pre_install_command
166
+ <<-INSTALL
167
+ #{config[:custom_pre_install_command]}
168
+ INSTALL
169
+ end
170
+
171
+ def custom_install_command
172
+ <<-INSTALL
173
+ #{config[:custom_install_command]}
174
+ INSTALL
175
+ end
176
+
177
+ def install_bolt
178
+ if config[:bolt_version]
179
+ <<-INSTALL
180
+ #{sudo('gem')} install --no-rdoc --no-ri bolt -v #{config[:bolt_version]}
181
+ INSTALL
182
+ else
183
+ <<-INSTALL
184
+ #{sudo('gem')} install --no-rdoc --no-ri bolt
185
+ INSTALL
186
+ end
187
+ end
188
+
189
+ def init_command
190
+ debug('Init Command')
191
+ end
192
+
193
+ def create_sandbox
194
+ super
195
+ debug("Creating local sandbox in #{sandbox_path}")
196
+ end
197
+
198
+ def cleanup_sandbox
199
+ return if sandbox_path.nil?
200
+ debug("Cleaning up local sandbox in #{sandbox_path}")
201
+ FileUtils.rmtree(sandbox_path)
202
+ return if remove_repo.nil?
203
+ debug("Cleaning up remote sandbox: #{remove_repo}")
204
+ instance.remote_exec remove_repo
205
+ end
206
+
207
+ def run_command
208
+ if config[:custom_post_bolt_command]
209
+ custom_post_bolt_trap = <<-TRAP
210
+ function custom_post_bolt_command {
211
+ #{config[:custom_post_bolt_command]}
212
+ }
213
+ trap custom_post_bolt_command EXIT
214
+ TRAP
215
+ end
216
+ result = <<-RUN
217
+ #{config[:custom_pre_bolt_command]}
218
+ #{custom_post_bolt_trap}
219
+ RUN
220
+ bolt_commands_to_run.each do |a|
221
+ result = <<-RUN
222
+ #{result}
223
+ #{a}
224
+ RUN
225
+ end
226
+ info("Going to invoke bolt with: #{result}")
227
+ result
228
+ end
229
+
230
+ protected
231
+
232
+ def bolt_commands_to_run
233
+ if config[:bolt_commands]
234
+ config[:bolt_commands].is_a?(Array) ? config[:bolt_commands] : [config[:bolt_commands]]
235
+ else
236
+ []
237
+ end
238
+ end
239
+
240
+ def bolt_platform
241
+ config[:platform].gsub(/-.*/, '')
242
+ end
243
+
244
+ def remove_repo
245
+ config[:remove_bolt_repo] ? "#{sudo('rm')} -rf /tmp/kitchen " : nil
246
+ end
247
+
248
+ def sudo_env(pm)
249
+ s = https_proxy ? "https_proxy=#{https_proxy}" : nil
250
+ p = http_proxy ? "http_proxy=#{http_proxy}" : nil
251
+ n = no_proxy ? "no_proxy=#{no_proxy}" : nil
252
+ p || s ? "#{sudo('env')} #{p} #{s} #{n} #{pm}" : sudo(pm).to_s
253
+ end
254
+
255
+ def proxy_parm
256
+ http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
257
+ end
258
+
259
+ def gem_proxy_parm
260
+ p = http_proxy ? "--http-proxy #{http_proxy}" : nil
261
+ n = no_proxy ? "--no-http-proxy #{no_proxy}" : nil
262
+ p || n ? "#{p} #{n}" : nil
263
+ end
264
+
265
+ def wget_proxy_parm
266
+ p = http_proxy ? "-e http_proxy=#{http_proxy}" : nil
267
+ s = https_proxy ? "-e https_proxy=#{https_proxy}" : nil
268
+ n = no_proxy ? "-e no_proxy=#{no_proxy}" : nil
269
+ p || s ? "-e use_proxy=yes #{p} #{s} #{n}" : nil
270
+ end
271
+
272
+ def posh_proxy_parm
273
+ http_proxy ? "-Proxy #{http_proxy}" : nil
274
+ end
275
+
276
+ def powershell?
277
+ return true if powershell_shell?
278
+ return true if bolt_platform =~ /^windows.*/
279
+ false
280
+ end
281
+
282
+ def export_http_proxy_parm
283
+ http_proxy ? "export http_proxy=#{http_proxy}" : nil
284
+ end
285
+
286
+ def export_https_proxy_parm
287
+ https_proxy ? "export https_proxy=#{https_proxy}" : nil
288
+ end
289
+
290
+ def export_no_proxy_parm
291
+ no_proxy ? "export no_proxy=#{no_proxy}" : nil
292
+ end
293
+
294
+ def http_proxy
295
+ config[:http_proxy]
296
+ end
297
+
298
+ def https_proxy
299
+ config[:https_proxy]
300
+ end
301
+
302
+ def no_proxy
303
+ config[:no_proxy]
304
+ end
305
+ end
306
+ end
307
+ end