kitchen-puppet 3.4.2 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,430 +1,430 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- #
4
- # Author:: Chris Lundquist (<chris.lundquist@github.com>) Neill Turner (<neillwturner@gmail.com>)
5
- #
6
- # Copyright (C) 2013,2014 Chris Lundquist, 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
- # See https://github.com/neillturner/kitchen-puppet/blob/master/provisioner_options.md
21
- # for documentation configuration parameters with puppet_agent provisioner.
22
- #
23
-
24
- require 'json'
25
- require 'kitchen'
26
- require 'kitchen/provisioner/base'
27
- require 'kitchen/provisioner/puppet/librarian'
28
-
29
- module Kitchen
30
- class Busser
31
- def non_suite_dirs
32
- %w[data data_bags environments nodes roles puppet]
33
- end
34
- end
35
-
36
- module Provisioner
37
- #
38
- # Puppet Agent provisioner.
39
- #
40
- class PuppetAgent < Base
41
- attr_accessor :tmp_dir
42
-
43
- default_config :require_puppet_omnibus, false
44
- # TODO: use something like https://github.com/fnichol/omnibus-puppet
45
- default_config :puppet_omnibus_url, nil
46
- default_config :puppet_environment, nil
47
- default_config :puppet_omnibus_remote_path, '/opt/puppet'
48
- default_config :puppet_version, nil
49
- default_config :facter_version, nil
50
- default_config :require_puppet_repo, true
51
- default_config :require_chef_for_busser, true
52
-
53
- default_config :puppet_apt_repo, 'http://apt.puppetlabs.com/puppetlabs-release-precise.deb'
54
- default_config :puppet_yum_repo, 'https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm'
55
- default_config :chef_bootstrap_url, 'https://www.chef.io/chef/install.sh'
56
-
57
- default_config :puppet_agent_command, nil
58
-
59
- default_config :http_proxy, nil
60
- default_config :https_proxy, nil
61
- default_config :no_proxy, nil
62
- default_config :puppet_whitelist_exit_code, nil
63
-
64
- default_config :puppet_config_path do |provisioner|
65
- provisioner.calculate_path('puppet.conf', :file)
66
- end
67
-
68
- default_config :puppet_debug, false
69
- default_config :puppet_verbose, false
70
- default_config :puppet_noop, false
71
- default_config :puppet_platform, ''
72
- default_config :update_package_repos, true
73
-
74
- default_config :custom_facts, {}
75
-
76
- default_config :puppet_detailed_exitcodes, nil
77
- default_config :puppet_logdest, nil
78
- default_config :puppet_masterport, nil
79
- default_config :puppet_test, false
80
- default_config :puppet_onetime, true
81
- default_config :puppet_no_daemonize, true
82
- # will default to 'puppet'
83
- default_config :puppet_server, nil
84
- default_config :puppet_waitforcert, '0'
85
- default_config :puppet_certname, nil
86
- default_config :puppet_digest, nil
87
-
88
- def calculate_path(path, type = :directory)
89
- base = config[:test_base_path]
90
- candidates = []
91
- candidates << File.join(base, instance.suite.name, 'puppet', path)
92
- candidates << File.join(base, instance.suite.name, path)
93
- candidates << File.join(base, path)
94
- candidates << File.join(Dir.pwd, path)
95
-
96
- candidates.find do |c|
97
- type == :directory ? File.directory?(c) : File.file?(c)
98
- end
99
- end
100
-
101
- # rubocop:disable Metrics/CyclomaticComplexity
102
- def install_command
103
- return unless config[:require_puppet_omnibus] || config[:require_puppet_repo]
104
- if config[:require_puppet_omnibus]
105
- info('Installing puppet using puppet omnibus')
106
- version = ''
107
- version = "-v #{config[:puppet_version]}" if config[:puppet_version]
108
- <<-INSTALL
109
- #{Util.shell_helpers}
110
-
111
- if [ ! -d "#{config[:puppet_omnibus_remote_path]}" ]; then
112
- echo "-----> Installing Puppet Omnibus"
113
- do_download #{config[:puppet_omnibus_url]} /tmp/puppet_install.sh
114
- #{sudo('sh')} /tmp/puppet_install.sh #{version}
115
- fi
116
- #{install_busser}
117
- INSTALL
118
- else
119
- case puppet_platform
120
- when 'debian', 'ubuntu'
121
- info("Installing puppet on #{puppet_platform}")
122
- <<-INSTALL
123
- if [ ! $(which puppet) ]; then
124
- #{sudo('apt-get')} -y install wget
125
- #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
126
- #{sudo('dpkg')} -i #{puppet_apt_repo_file}
127
- #{update_packages_debian_cmd}
128
- #{sudo_env('apt-get')} -y install facter#{facter_debian_version}
129
- #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
130
- #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
131
- fi
132
- #{install_busser}
133
- INSTALL
134
- when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
135
- info("Installing puppet on #{puppet_platform}")
136
- <<-INSTALL
137
- if [ ! $(which puppet) ]; then
138
- #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
139
- #{update_packages_redhat_cmd}
140
- #{sudo('yum')} -y install puppet#{puppet_redhat_version}
141
- fi
142
- #{install_busser}
143
- INSTALL
144
- else
145
- info('Installing puppet, will try to determine platform os')
146
- <<-INSTALL
147
- if [ ! $(which puppet) ]; then
148
- if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
149
- #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
150
- #{update_packages_redhat_cmd}
151
- #{sudo('yum')} -y install puppet#{puppet_redhat_version}
152
- else
153
- if [ -f /etc/system-release ] || grep -q 'Amazon Linux' /etc/system-release; then
154
- #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
155
- #{update_packages_redhat_cmd}
156
- #{sudo('yum')} -y install puppet#{puppet_redhat_version}
157
- else
158
- #{sudo('apt-get')} -y install wget
159
- #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
160
- #{sudo('dpkg')} -i #{puppet_apt_repo_file}
161
- #{update_packages_debian_cmd}
162
- #{sudo('apt-get')} -y install facter#{facter_debian_version}
163
- #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
164
- #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
165
- fi
166
- fi
167
- fi
168
- #{install_busser}
169
- INSTALL
170
- end
171
- end
172
- end
173
- # rubocop:enable Metrics/CyclomaticComplexity
174
-
175
- def install_busser
176
- return unless config[:require_chef_for_busser]
177
- <<-INSTALL
178
- #{Util.shell_helpers}
179
- # install chef omnibus so that busser works as this is needed to run tests :(
180
- # TODO: work out how to install enough ruby
181
- # and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
182
- # whole chef client
183
- if [ ! -d "/opt/chef" ]
184
- then
185
- echo "-----> Installing Chef Omnibus to install busser to run tests"
186
- do_download #{chef_url} /tmp/install.sh
187
- #{sudo('sh')} /tmp/install.sh
188
- fi
189
- INSTALL
190
- end
191
-
192
- def init_command; end
193
-
194
- def create_sandbox
195
- super
196
- debug("Creating local sandbox in #{sandbox_path}")
197
-
198
- yield if block_given?
199
-
200
- prepare_puppet_config
201
- info('Finished Preparing files for transfer')
202
- end
203
-
204
- def cleanup_sandbox
205
- return if sandbox_path.nil?
206
- debug("Cleaning up local sandbox in #{sandbox_path}")
207
- FileUtils.rmtree(sandbox_path)
208
- end
209
-
210
- def prepare_command
211
- commands = []
212
-
213
- if puppet_config
214
- commands << [
215
- sudo('cp'),
216
- File.join(config[:root_path], 'puppet.conf'),
217
- '/etc/puppet'
218
- ].join(' ')
219
- end
220
-
221
- command = commands.join(' && ')
222
- debug(command)
223
- command
224
- end
225
-
226
- def run_command
227
- return config[:puppet_agent_command] unless config[:puppet_agent_command].nil?
228
- [
229
- custom_facts,
230
- sudo_env('puppet'),
231
- 'agent',
232
- puppet_server_flag,
233
- "--waitforcert=#{config[:puppet_waitforcert]}",
234
- puppet_masterport_flag,
235
- puppet_certname_flag,
236
- puppet_digest_flag,
237
- puppet_detailed_exitcodes_flag,
238
- puppet_logdest_flag,
239
- puppet_test_flag,
240
- puppet_onetime_flag,
241
- puppet_no_daemonize_flag,
242
- puppet_noop_flag,
243
- puppet_environment_flag,
244
- puppet_verbose_flag,
245
- puppet_debug_flag,
246
- puppet_whitelist_exit_code
247
- ].compact.join(' ')
248
- end
249
-
250
- protected
251
-
252
- def load_needed_dependencies!; end
253
-
254
- def puppet_environment_flag
255
- config[:puppet_environment] ? "--environment=\"#{config[:puppet_environment]}\"" : nil
256
- end
257
-
258
- def puppet_config
259
- config[:puppet_config_path]
260
- end
261
-
262
- def puppet_debian_version
263
- config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
264
- end
265
-
266
- def facter_debian_version
267
- config[:facter_version] ? "=#{config[:facter_version]}" : nil
268
- end
269
-
270
- def puppet_redhat_version
271
- if puppet_platform == 'amazon'
272
- config[:puppet_version]
273
- else
274
- config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
275
- end
276
- end
277
-
278
- def puppet_noop_flag
279
- config[:puppet_noop] ? '--noop' : nil
280
- end
281
-
282
- def puppet_debug_flag
283
- config[:puppet_debug] ? '-d' : nil
284
- end
285
-
286
- def puppet_verbose_flag
287
- config[:puppet_verbose] ? '-v' : nil
288
- end
289
-
290
- def puppet_platform
291
- config[:puppet_platform].to_s.downcase
292
- end
293
-
294
- def update_packages_debian_cmd
295
- config[:update_package_repos] ? "#{sudo_env('apt-get')} update" : nil
296
- end
297
-
298
- def update_packages_redhat_cmd
299
- config[:update_package_repos] ? "#{sudo_env('yum')} makecache" : nil
300
- end
301
-
302
- def sudo_env(pm)
303
- s = https_proxy ? "https_proxy=#{https_proxy}" : nil
304
- p = http_proxy ? "http_proxy=#{http_proxy}" : nil
305
- n = no_proxy ? "no_proxy=#{no_proxy}" : nil
306
- p || s ? "#{sudo('env')} #{p} #{s} #{n} #{pm}" : sudo(pm).to_s
307
- end
308
-
309
- def custom_facts
310
- return nil if config[:custom_facts].none?
311
- bash_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
312
- bash_vars = "export #{bash_vars};"
313
- debug(bash_vars)
314
- bash_vars
315
- end
316
-
317
- def puppet_server_flag
318
- config[:puppet_server] ? "--server=#{config[:puppet_server]}" : nil
319
- end
320
-
321
- def puppet_masterport_flag
322
- config[:puppet_masterport] ? "--masterport=#{config[:puppet_masterport]}" : nil
323
- end
324
-
325
- def puppet_detailed_exitcodes_flag
326
- config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
327
- end
328
-
329
- def puppet_logdest_flag
330
- config[:puppet_logdest] ? "--logdest=#{config[:puppet_logdest]}" : nil
331
- end
332
-
333
- def puppet_test_flag
334
- config[:puppet_test] ? '--test' : nil
335
- end
336
-
337
- def puppet_onetime_flag
338
- config[:puppet_onetime] ? '--onetime' : nil
339
- end
340
-
341
- def puppet_no_daemonize_flag
342
- config[:puppet_no_daemonize] ? '--no-daemonize' : nil
343
- end
344
-
345
- def puppet_no_daemonize
346
- config[:puppet_no_daemonize]
347
- end
348
-
349
- def puppet_server
350
- config[:puppet_server]
351
- end
352
-
353
- def puppet_certname_flag
354
- config[:puppet_certname] ? "--certname=#{config[:puppet_certname]}" : nil
355
- end
356
-
357
- def puppet_digest_flag
358
- config[:puppet_digest] ? "--digest=#{config[:puppet_digest]}" : nil
359
- end
360
-
361
- def puppet_apt_repo
362
- config[:puppet_apt_repo]
363
- end
364
-
365
- def puppet_apt_repo_file
366
- config[:puppet_apt_repo].split('/').last
367
- end
368
-
369
- def puppet_yum_repo
370
- config[:puppet_yum_repo]
371
- end
372
-
373
- def proxy_parm
374
- http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
375
- end
376
-
377
- def gem_proxy_parm
378
- p = http_proxy ? "--http-proxy #{http_proxy}" : nil
379
- n = no_proxy ? "--no-http-proxy #{no_proxy}" : nil
380
- p ? "#{p} #{n}" : nil
381
- end
382
-
383
- def wget_proxy_parm
384
- s = https_proxy ? "-e https_proxy=#{https_proxy}" : nil
385
- p = http_proxy ? "-e http_proxy=#{http_proxy}" : nil
386
- n = no_proxy ? "-e no_proxy=#{no_proxy}" : nil
387
- p || s ? "-e use_proxy=yes #{p} #{s} #{n}" : nil
388
- end
389
-
390
- def http_proxy
391
- config[:http_proxy]
392
- end
393
-
394
- def https_proxy
395
- config[:https_proxy]
396
- end
397
-
398
- def no_proxy
399
- config[:no_proxy]
400
- end
401
-
402
- def powershell?
403
- powershell_shell? || !(puppet_platform =~ /^windows.*/).nil?
404
- end
405
-
406
- def puppet_whitelist_exit_code
407
- if config[:puppet_whitelist_exit_code].nil?
408
- powershell? ? '; exit $LASTEXITCODE' : nil
409
- elsif powershell?
410
- "; if(@(#{[config[:puppet_whitelist_exit_code]].join(', ')}) -contains $LASTEXITCODE) {exit 0} else {exit $LASTEXITCODE}"
411
- else
412
- '; RC=$?; [ ' + [config[:puppet_whitelist_exit_code]].flatten.map { |x| "\$RC -eq #{x}" }.join(' -o ') + ' ] && exit 0; exit $RC'
413
- end
414
- end
415
-
416
- def chef_url
417
- config[:chef_bootstrap_url]
418
- end
419
-
420
- def prepare_puppet_config
421
- return unless puppet_config
422
-
423
- info('Preparing puppet.conf')
424
- debug("Using puppet config from #{puppet_config}")
425
-
426
- FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
427
- end
428
- end
429
- end
430
- end
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ #
4
+ # Author:: Chris Lundquist (<chris.lundquist@github.com>) Neill Turner (<neillwturner@gmail.com>)
5
+ #
6
+ # Copyright (C) 2013,2014 Chris Lundquist, 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
+ # See https://github.com/neillturner/kitchen-puppet/blob/master/provisioner_options.md
21
+ # for documentation configuration parameters with puppet_agent provisioner.
22
+ #
23
+
24
+ require 'json'
25
+ require 'kitchen'
26
+ require 'kitchen/provisioner/base'
27
+ require 'kitchen/provisioner/puppet/librarian'
28
+
29
+ module Kitchen
30
+ class Busser
31
+ def non_suite_dirs
32
+ %w[data data_bags environments nodes roles puppet]
33
+ end
34
+ end
35
+
36
+ module Provisioner
37
+ #
38
+ # Puppet Agent provisioner.
39
+ #
40
+ class PuppetAgent < Base
41
+ attr_accessor :tmp_dir
42
+
43
+ default_config :require_puppet_omnibus, false
44
+ # TODO: use something like https://github.com/fnichol/omnibus-puppet
45
+ default_config :puppet_omnibus_url, nil
46
+ default_config :puppet_environment, nil
47
+ default_config :puppet_omnibus_remote_path, '/opt/puppet'
48
+ default_config :puppet_version, nil
49
+ default_config :facter_version, nil
50
+ default_config :require_puppet_repo, true
51
+ default_config :require_chef_for_busser, true
52
+
53
+ default_config :puppet_apt_repo, 'http://apt.puppetlabs.com/puppetlabs-release-precise.deb'
54
+ default_config :puppet_yum_repo, 'https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm'
55
+ default_config :chef_bootstrap_url, 'https://www.chef.io/chef/install.sh'
56
+
57
+ default_config :puppet_agent_command, nil
58
+
59
+ default_config :http_proxy, nil
60
+ default_config :https_proxy, nil
61
+ default_config :no_proxy, nil
62
+ default_config :puppet_whitelist_exit_code, nil
63
+
64
+ default_config :puppet_config_path do |provisioner|
65
+ provisioner.calculate_path('puppet.conf', :file)
66
+ end
67
+
68
+ default_config :puppet_debug, false
69
+ default_config :puppet_verbose, false
70
+ default_config :puppet_noop, false
71
+ default_config :puppet_platform, ''
72
+ default_config :update_package_repos, true
73
+
74
+ default_config :custom_facts, {}
75
+
76
+ default_config :puppet_detailed_exitcodes, nil
77
+ default_config :puppet_logdest, nil
78
+ default_config :puppet_masterport, nil
79
+ default_config :puppet_test, false
80
+ default_config :puppet_onetime, true
81
+ default_config :puppet_no_daemonize, true
82
+ # will default to 'puppet'
83
+ default_config :puppet_server, nil
84
+ default_config :puppet_waitforcert, '0'
85
+ default_config :puppet_certname, nil
86
+ default_config :puppet_digest, nil
87
+
88
+ def calculate_path(path, type = :directory)
89
+ base = config[:test_base_path]
90
+ candidates = []
91
+ candidates << File.join(base, instance.suite.name, 'puppet', path)
92
+ candidates << File.join(base, instance.suite.name, path)
93
+ candidates << File.join(base, path)
94
+ candidates << File.join(Dir.pwd, path)
95
+
96
+ candidates.find do |c|
97
+ type == :directory ? File.directory?(c) : File.file?(c)
98
+ end
99
+ end
100
+
101
+ # rubocop:disable Metrics/CyclomaticComplexity
102
+ def install_command
103
+ return unless config[:require_puppet_omnibus] || config[:require_puppet_repo]
104
+ if config[:require_puppet_omnibus]
105
+ info('Installing puppet using puppet omnibus')
106
+ version = ''
107
+ version = "-v #{config[:puppet_version]}" if config[:puppet_version]
108
+ <<-INSTALL
109
+ #{Util.shell_helpers}
110
+
111
+ if [ ! -d "#{config[:puppet_omnibus_remote_path]}" ]; then
112
+ echo "-----> Installing Puppet Omnibus"
113
+ do_download #{config[:puppet_omnibus_url]} /tmp/puppet_install.sh
114
+ #{sudo('sh')} /tmp/puppet_install.sh #{version}
115
+ fi
116
+ #{install_busser}
117
+ INSTALL
118
+ else
119
+ case puppet_platform
120
+ when 'debian', 'ubuntu'
121
+ info("Installing puppet on #{puppet_platform}")
122
+ <<-INSTALL
123
+ if [ ! $(which puppet) ]; then
124
+ #{sudo('apt-get')} -y install wget
125
+ #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
126
+ #{sudo('dpkg')} -i #{puppet_apt_repo_file}
127
+ #{update_packages_debian_cmd}
128
+ #{sudo_env('apt-get')} -y install facter#{facter_debian_version}
129
+ #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
130
+ #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
131
+ fi
132
+ #{install_busser}
133
+ INSTALL
134
+ when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
135
+ info("Installing puppet on #{puppet_platform}")
136
+ <<-INSTALL
137
+ if [ ! $(which puppet) ]; then
138
+ #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
139
+ #{update_packages_redhat_cmd}
140
+ #{sudo('yum')} -y install puppet#{puppet_redhat_version}
141
+ fi
142
+ #{install_busser}
143
+ INSTALL
144
+ else
145
+ info('Installing puppet, will try to determine platform os')
146
+ <<-INSTALL
147
+ if [ ! $(which puppet) ]; then
148
+ if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
149
+ #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
150
+ #{update_packages_redhat_cmd}
151
+ #{sudo('yum')} -y install puppet#{puppet_redhat_version}
152
+ else
153
+ if [ -f /etc/system-release ] || grep -q 'Amazon Linux' /etc/system-release; then
154
+ #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
155
+ #{update_packages_redhat_cmd}
156
+ #{sudo('yum')} -y install puppet#{puppet_redhat_version}
157
+ else
158
+ #{sudo('apt-get')} -y install wget
159
+ #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
160
+ #{sudo('dpkg')} -i #{puppet_apt_repo_file}
161
+ #{update_packages_debian_cmd}
162
+ #{sudo('apt-get')} -y install facter#{facter_debian_version}
163
+ #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
164
+ #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
165
+ fi
166
+ fi
167
+ fi
168
+ #{install_busser}
169
+ INSTALL
170
+ end
171
+ end
172
+ end
173
+ # rubocop:enable Metrics/CyclomaticComplexity
174
+
175
+ def install_busser
176
+ return unless config[:require_chef_for_busser]
177
+ <<-INSTALL
178
+ #{Util.shell_helpers}
179
+ # install chef omnibus so that busser works as this is needed to run tests :(
180
+ # TODO: work out how to install enough ruby
181
+ # and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
182
+ # whole chef client
183
+ if [ ! -d "/opt/chef" ]
184
+ then
185
+ echo "-----> Installing Chef Omnibus to install busser to run tests"
186
+ do_download #{chef_url} /tmp/install.sh
187
+ #{sudo('sh')} /tmp/install.sh
188
+ fi
189
+ INSTALL
190
+ end
191
+
192
+ def init_command; end
193
+
194
+ def create_sandbox
195
+ super
196
+ debug("Creating local sandbox in #{sandbox_path}")
197
+
198
+ yield if block_given?
199
+
200
+ prepare_puppet_config
201
+ info('Finished Preparing files for transfer')
202
+ end
203
+
204
+ def cleanup_sandbox
205
+ return if sandbox_path.nil?
206
+ debug("Cleaning up local sandbox in #{sandbox_path}")
207
+ FileUtils.rmtree(sandbox_path)
208
+ end
209
+
210
+ def prepare_command
211
+ commands = []
212
+
213
+ if puppet_config
214
+ commands << [
215
+ sudo('cp'),
216
+ File.join(config[:root_path], 'puppet.conf'),
217
+ '/etc/puppet'
218
+ ].join(' ')
219
+ end
220
+
221
+ command = commands.join(' && ')
222
+ debug(command)
223
+ command
224
+ end
225
+
226
+ def run_command
227
+ return config[:puppet_agent_command] unless config[:puppet_agent_command].nil?
228
+ [
229
+ custom_facts,
230
+ sudo_env('puppet'),
231
+ 'agent',
232
+ puppet_server_flag,
233
+ "--waitforcert=#{config[:puppet_waitforcert]}",
234
+ puppet_masterport_flag,
235
+ puppet_certname_flag,
236
+ puppet_digest_flag,
237
+ puppet_detailed_exitcodes_flag,
238
+ puppet_logdest_flag,
239
+ puppet_test_flag,
240
+ puppet_onetime_flag,
241
+ puppet_no_daemonize_flag,
242
+ puppet_noop_flag,
243
+ puppet_environment_flag,
244
+ puppet_verbose_flag,
245
+ puppet_debug_flag,
246
+ puppet_whitelist_exit_code
247
+ ].compact.join(' ')
248
+ end
249
+
250
+ protected
251
+
252
+ def load_needed_dependencies!; end
253
+
254
+ def puppet_environment_flag
255
+ config[:puppet_environment] ? "--environment=\"#{config[:puppet_environment]}\"" : nil
256
+ end
257
+
258
+ def puppet_config
259
+ config[:puppet_config_path]
260
+ end
261
+
262
+ def puppet_debian_version
263
+ config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
264
+ end
265
+
266
+ def facter_debian_version
267
+ config[:facter_version] ? "=#{config[:facter_version]}" : nil
268
+ end
269
+
270
+ def puppet_redhat_version
271
+ if puppet_platform == 'amazon'
272
+ config[:puppet_version]
273
+ else
274
+ config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
275
+ end
276
+ end
277
+
278
+ def puppet_noop_flag
279
+ config[:puppet_noop] ? '--noop' : nil
280
+ end
281
+
282
+ def puppet_debug_flag
283
+ config[:puppet_debug] ? '-d' : nil
284
+ end
285
+
286
+ def puppet_verbose_flag
287
+ config[:puppet_verbose] ? '-v' : nil
288
+ end
289
+
290
+ def puppet_platform
291
+ config[:puppet_platform].to_s.downcase
292
+ end
293
+
294
+ def update_packages_debian_cmd
295
+ config[:update_package_repos] ? "#{sudo_env('apt-get')} update" : nil
296
+ end
297
+
298
+ def update_packages_redhat_cmd
299
+ config[:update_package_repos] ? "#{sudo_env('yum')} makecache" : nil
300
+ end
301
+
302
+ def sudo_env(pm)
303
+ s = https_proxy ? "https_proxy=#{https_proxy}" : nil
304
+ p = http_proxy ? "http_proxy=#{http_proxy}" : nil
305
+ n = no_proxy ? "no_proxy=#{no_proxy}" : nil
306
+ p || s ? "#{sudo('env')} #{p} #{s} #{n} #{pm}" : sudo(pm).to_s
307
+ end
308
+
309
+ def custom_facts
310
+ return nil if config[:custom_facts].none?
311
+ bash_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
312
+ bash_vars = "export #{bash_vars};"
313
+ debug(bash_vars)
314
+ bash_vars
315
+ end
316
+
317
+ def puppet_server_flag
318
+ config[:puppet_server] ? "--server=#{config[:puppet_server]}" : nil
319
+ end
320
+
321
+ def puppet_masterport_flag
322
+ config[:puppet_masterport] ? "--masterport=#{config[:puppet_masterport]}" : nil
323
+ end
324
+
325
+ def puppet_detailed_exitcodes_flag
326
+ config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
327
+ end
328
+
329
+ def puppet_logdest_flag
330
+ config[:puppet_logdest] ? "--logdest=#{config[:puppet_logdest]}" : nil
331
+ end
332
+
333
+ def puppet_test_flag
334
+ config[:puppet_test] ? '--test' : nil
335
+ end
336
+
337
+ def puppet_onetime_flag
338
+ config[:puppet_onetime] ? '--onetime' : nil
339
+ end
340
+
341
+ def puppet_no_daemonize_flag
342
+ config[:puppet_no_daemonize] ? '--no-daemonize' : nil
343
+ end
344
+
345
+ def puppet_no_daemonize
346
+ config[:puppet_no_daemonize]
347
+ end
348
+
349
+ def puppet_server
350
+ config[:puppet_server]
351
+ end
352
+
353
+ def puppet_certname_flag
354
+ config[:puppet_certname] ? "--certname=#{config[:puppet_certname]}" : nil
355
+ end
356
+
357
+ def puppet_digest_flag
358
+ config[:puppet_digest] ? "--digest=#{config[:puppet_digest]}" : nil
359
+ end
360
+
361
+ def puppet_apt_repo
362
+ config[:puppet_apt_repo]
363
+ end
364
+
365
+ def puppet_apt_repo_file
366
+ config[:puppet_apt_repo].split('/').last
367
+ end
368
+
369
+ def puppet_yum_repo
370
+ config[:puppet_yum_repo]
371
+ end
372
+
373
+ def proxy_parm
374
+ http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
375
+ end
376
+
377
+ def gem_proxy_parm
378
+ p = http_proxy ? "--http-proxy #{http_proxy}" : nil
379
+ n = no_proxy ? "--no-http-proxy #{no_proxy}" : nil
380
+ p ? "#{p} #{n}" : nil
381
+ end
382
+
383
+ def wget_proxy_parm
384
+ s = https_proxy ? "-e https_proxy=#{https_proxy}" : nil
385
+ p = http_proxy ? "-e http_proxy=#{http_proxy}" : nil
386
+ n = no_proxy ? "-e no_proxy=#{no_proxy}" : nil
387
+ p || s ? "-e use_proxy=yes #{p} #{s} #{n}" : nil
388
+ end
389
+
390
+ def http_proxy
391
+ config[:http_proxy]
392
+ end
393
+
394
+ def https_proxy
395
+ config[:https_proxy]
396
+ end
397
+
398
+ def no_proxy
399
+ config[:no_proxy]
400
+ end
401
+
402
+ def powershell?
403
+ powershell_shell? || !(puppet_platform =~ /^windows.*/).nil?
404
+ end
405
+
406
+ def puppet_whitelist_exit_code
407
+ if config[:puppet_whitelist_exit_code].nil?
408
+ powershell? ? '; exit $LASTEXITCODE' : nil
409
+ elsif powershell?
410
+ "; if(@(#{[config[:puppet_whitelist_exit_code]].join(', ')}) -contains $LASTEXITCODE) {exit 0} else {exit $LASTEXITCODE}"
411
+ else
412
+ '; RC=$?; [ ' + [config[:puppet_whitelist_exit_code]].flatten.map { |x| "\$RC -eq #{x}" }.join(' -o ') + ' ] && exit 0; exit $RC'
413
+ end
414
+ end
415
+
416
+ def chef_url
417
+ config[:chef_bootstrap_url]
418
+ end
419
+
420
+ def prepare_puppet_config
421
+ return unless puppet_config
422
+
423
+ info('Preparing puppet.conf')
424
+ debug("Using puppet config from #{puppet_config}")
425
+
426
+ FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
427
+ end
428
+ end
429
+ end
430
+ end