kitchen-puppet 0.0.16 → 0.0.17

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.
@@ -25,11 +25,9 @@ require 'kitchen/provisioner/base'
25
25
  require 'kitchen/provisioner/puppet/librarian'
26
26
 
27
27
  module Kitchen
28
-
29
28
  class Busser
30
-
31
29
  def non_suite_dirs
32
- %w{data data_bags environments nodes roles puppet}
30
+ %w(data data_bags environments nodes roles puppet)
33
31
  end
34
32
  end
35
33
 
@@ -41,7 +39,7 @@ module Kitchen
41
39
  attr_accessor :tmp_dir
42
40
 
43
41
  default_config :require_puppet_omnibus, false
44
- # TODO use something like https://github.com/fnichol/omnibus-puppet
42
+ # TODO: use something like https://github.com/fnichol/omnibus-puppet
45
43
  default_config :puppet_omnibus_url, nil
46
44
  default_config :puppet_omnibus_remote_path, '/opt/puppet'
47
45
  default_config :puppet_version, nil
@@ -49,9 +47,9 @@ module Kitchen
49
47
  default_config :require_chef_for_busser, true
50
48
  default_config :resolve_with_librarian_puppet, true
51
49
  default_config :puppet_environment, nil
52
- default_config :puppet_apt_repo, "http://apt.puppetlabs.com/puppetlabs-release-precise.deb"
53
- default_config :puppet_yum_repo, "https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm"
54
- default_config :chef_bootstrap_url, "https://www.getchef.com/chef/install.sh"
50
+ default_config :puppet_apt_repo, 'http://apt.puppetlabs.com/puppetlabs-release-precise.deb'
51
+ default_config :puppet_yum_repo, 'https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm'
52
+ default_config :chef_bootstrap_url, 'https://www.getchef.com/chef/install.sh'
55
53
 
56
54
  default_config :puppet_apply_command, nil
57
55
 
@@ -59,14 +57,14 @@ module Kitchen
59
57
  default_config :manifest, 'site.pp'
60
58
 
61
59
  default_config :manifests_path do |provisioner|
62
- provisioner.calculate_path('manifests') or
63
- raise 'No manifests_path detected. Please specify one in .kitchen.yml'
60
+ provisioner.calculate_path('manifests') ||
61
+ fail('No manifests_path detected. Please specify one in .kitchen.yml')
64
62
  end
65
63
 
66
64
  default_config :modules_path do |provisioner|
67
65
  modules_path = provisioner.calculate_path('modules')
68
66
  if modules_path.nil? && provisioner.calculate_path('Puppetfile', :file).nil?
69
- raise 'No modules_path detected. Please specify one in .kitchen.yml'
67
+ fail 'No modules_path detected. Please specify one in .kitchen.yml'
70
68
  end
71
69
  modules_path
72
70
  end
@@ -78,7 +76,7 @@ module Kitchen
78
76
  default_config :hiera_data_path do |provisioner|
79
77
  provisioner.calculate_path('hiera')
80
78
  end
81
-
79
+
82
80
  default_config :puppet_config_path do |provisioner|
83
81
  provisioner.calculate_path('puppet.conf', :file)
84
82
  end
@@ -107,7 +105,6 @@ module Kitchen
107
105
  provisioner.calculate_path('manifests', :directory)
108
106
  end
109
107
 
110
-
111
108
  default_config :puppet_debug, false
112
109
  default_config :puppet_verbose, false
113
110
  default_config :puppet_noop, false
@@ -115,14 +112,15 @@ module Kitchen
115
112
  default_config :update_package_repos, true
116
113
  default_config :remove_puppet_repo, false
117
114
  default_config :custom_facts, {}
115
+ default_config :facter_file, nil
118
116
  default_config :librarian_puppet_ssl_file, nil
119
-
117
+
120
118
  default_config :hiera_eyaml, false
121
119
  default_config :hiera_eyaml_key_remote_path, '/etc/puppet/secure/keys'
122
-
120
+
123
121
  default_config :hiera_eyaml_key_path do |provisioner|
124
- provisioner.calculate_path('hiera_keys')
125
- end
122
+ provisioner.calculate_path('hiera_keys')
123
+ end
126
124
 
127
125
  def calculate_path(path, type = :directory)
128
126
  base = config[:test_base_path]
@@ -137,14 +135,16 @@ module Kitchen
137
135
  end
138
136
  end
139
137
 
138
+ # TODO: refactor for smaller cyclomatic complexity and perceived complexity
139
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
140
140
  def install_command
141
- return unless config[:require_puppet_omnibus] or config[:require_puppet_repo]
141
+ return unless config[:require_puppet_omnibus] || config[:require_puppet_repo]
142
142
  if config[:require_puppet_omnibus]
143
- info("Installing puppet using puppet omnibus")
144
- version = if !config[:puppet_version].nil?
145
- "-v #{config[:puppet_version]}"
143
+ info('Installing puppet using puppet omnibus')
144
+ if !config[:puppet_version].nil?
145
+ version = "-v #{config[:puppet_version]}"
146
146
  else
147
- ""
147
+ version = ''
148
148
  end
149
149
  <<-INSTALL
150
150
  #{Util.shell_helpers}
@@ -158,72 +158,72 @@ module Kitchen
158
158
  INSTALL
159
159
  else
160
160
  case puppet_platform
161
- when "debian", "ubuntu"
162
- info("Installing puppet on #{puppet_platform}")
163
- <<-INSTALL
164
- if [ ! $(which puppet) ]; then
165
- #{sudo('wget')} #{puppet_apt_repo}
166
- #{sudo('dpkg')} -i #{puppet_apt_repo_file}
167
- #{update_packages_debian_cmd}
168
- #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
169
- #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
170
- fi
171
- #{install_busser}
172
- INSTALL
173
- when "redhat", "centos", "fedora"
174
- info("Installing puppet on #{puppet_platform}")
175
- <<-INSTALL
176
- if [ ! $(which puppet) ]; then
177
- #{sudo('rpm')} -ivh #{puppet_yum_repo}
178
- #{update_packages_redhat_cmd}
179
- #{sudo('yum')} -y install puppet#{puppet_redhat_version}
180
- fi
181
- #{install_busser}
182
- INSTALL
183
- else
184
- info("Installing puppet, will try to determine platform os")
185
- <<-INSTALL
186
- if [ ! $(which puppet) ]; then
187
- if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
188
- #{sudo('rpm')} -ivh #{puppet_yum_repo}
189
- #{update_packages_redhat_cmd}
190
- #{sudo('yum')} -y install puppet#{puppet_redhat_version}
191
- else
192
- if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
161
+ when 'debian', 'ubuntu'
162
+ info("Installing puppet on #{puppet_platform}")
163
+ <<-INSTALL
164
+ if [ ! $(which puppet) ]; then
165
+ #{sudo('wget')} #{puppet_apt_repo}
166
+ #{sudo('dpkg')} -i #{puppet_apt_repo_file}
167
+ #{update_packages_debian_cmd}
168
+ #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
169
+ #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
170
+ fi
171
+ #{install_busser}
172
+ INSTALL
173
+ when 'redhat', 'centos', 'fedora'
174
+ info("Installing puppet on #{puppet_platform}")
175
+ <<-INSTALL
176
+ if [ ! $(which puppet) ]; then
177
+ #{sudo('rpm')} -ivh #{puppet_yum_repo}
178
+ #{update_packages_redhat_cmd}
179
+ #{sudo('yum')} -y install puppet#{puppet_redhat_version}
180
+ fi
181
+ #{install_busser}
182
+ INSTALL
183
+ else
184
+ info('Installing puppet, will try to determine platform os')
185
+ <<-INSTALL
186
+ if [ ! $(which puppet) ]; then
187
+ if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
193
188
  #{sudo('rpm')} -ivh #{puppet_yum_repo}
194
189
  #{update_packages_redhat_cmd}
195
- #{sudo('yum')} -y install puppet#{puppet_redhat_version}
196
- else
197
- #{sudo('wget')} #{puppet_apt_repo}
198
- #{sudo('dpkg')} -i #{puppet_apt_repo_file}
199
- #{update_packages_debian_cmd}
200
- #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
201
- #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
202
- fi
203
- fi
204
- fi
205
- #{install_eyaml}
206
- #{install_busser}
207
- INSTALL
208
- end
190
+ #{sudo('yum')} -y install puppet#{puppet_redhat_version}
191
+ else
192
+ if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
193
+ #{sudo('rpm')} -ivh #{puppet_yum_repo}
194
+ #{update_packages_redhat_cmd}
195
+ #{sudo('yum')} -y install puppet#{puppet_redhat_version}
196
+ else
197
+ #{sudo('wget')} #{puppet_apt_repo}
198
+ #{sudo('dpkg')} -i #{puppet_apt_repo_file}
199
+ #{update_packages_debian_cmd}
200
+ #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
201
+ #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
202
+ fi
203
+ fi
204
+ fi
205
+ #{install_eyaml}
206
+ #{install_busser}
207
+ INSTALL
208
+ end
209
209
  end
210
210
  end
211
-
212
- def install_eyaml
213
- if config[:hiera_eyaml]
214
- <<-INSTALL
211
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
212
+
213
+ def install_eyaml
214
+ return unless config[:hiera_eyaml]
215
+ <<-INSTALL
215
216
  # A backend for Hiera that provides per-value asymmetric encryption of sensitive data
216
- if [[ $(#{sudo('gem')} list hiera-eyaml -i) == 'false' ]]; then
217
+ if [[ $(#{sudo('gem')} list hiera-eyaml -i) == 'false' ]]; then
217
218
  echo "-----> Installing hiera-eyaml to provide encryption of hiera data"
218
219
  #{sudo('gem')} install --no-ri --no-rdoc hiera-eyaml
219
- fi
220
- INSTALL
221
- end
222
- end
220
+ fi
221
+ INSTALL
222
+ end
223
223
 
224
224
  def install_busser
225
- if config[:require_chef_for_busser]
226
- <<-INSTALL
225
+ return unless config[:require_chef_for_busser]
226
+ <<-INSTALL
227
227
  #{Util.shell_helpers}
228
228
  # install chef omnibus so that busser works as this is needed to run tests :(
229
229
  # TODO: work out how to install enough ruby
@@ -235,390 +235,393 @@ module Kitchen
235
235
  do_download #{chef_url} /tmp/install.sh
236
236
  #{sudo('sh')} /tmp/install.sh
237
237
  fi
238
- INSTALL
238
+ INSTALL
239
+ end
240
+
241
+ def init_command
242
+ dirs = %w(modules manifests files hiera hiera.yaml)
243
+ .map { |dir| File.join(config[:root_path], dir) }.join(' ')
244
+ cmd = "#{sudo('rm')} -rf #{dirs} #{hiera_data_remote_path} /etc/hiera.yaml /etc/puppet/hiera.yaml /etc/puppet/fileserver.conf;"
245
+ cmd += " mkdir -p #{config[:root_path]}"
246
+ debug(cmd)
247
+ cmd
248
+ end
249
+
250
+ def create_sandbox
251
+ super
252
+ debug("Creating local sandbox in #{sandbox_path}")
253
+ yield if block_given?
254
+ prepare_modules
255
+ prepare_manifests
256
+ prepare_files
257
+ prepare_puppet_config
258
+ prepare_hiera_config
259
+ prepare_fileserver_config
260
+ prepare_hiera_data
261
+ info('Finished Preparing files for transfer')
262
+ end
263
+
264
+ def cleanup_sandbox
265
+ return if sandbox_path.nil?
266
+ debug("Cleaning up local sandbox in #{sandbox_path}")
267
+ FileUtils.rmtree(sandbox_path)
268
+ end
269
+
270
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
271
+ def prepare_command
272
+ commands = []
273
+ if puppet_config
274
+ commands << [
275
+ sudo('cp'),
276
+ File.join(config[:root_path], 'puppet.conf'),
277
+ '/etc/puppet'
278
+ ].join(' ')
239
279
  end
240
- end
241
-
242
-
243
-
244
- def init_command
245
- dirs = %w{modules manifests files hiera hiera.yaml}.
246
- map { |dir| File.join(config[:root_path], dir) }.join(" ")
247
- cmd = "#{sudo('rm')} -rf #{dirs} #{hiera_data_remote_path} /etc/hiera.yaml /etc/puppet/hiera.yaml /etc/puppet/fileserver.conf;"
248
- cmd = cmd+" mkdir -p #{config[:root_path]}"
249
- debug(cmd)
250
- cmd
280
+
281
+ if hiera_config
282
+ commands << [
283
+ sudo('cp'), File.join(config[:root_path], 'hiera.yaml'), '/etc/'
284
+ ].join(' ')
285
+
286
+ commands << [
287
+ sudo('cp'), File.join(config[:root_path], 'hiera.yaml'), '/etc/puppet/'
288
+ ].join(' ')
251
289
  end
252
290
 
253
- def create_sandbox
254
- super
255
- debug("Creating local sandbox in #{sandbox_path}")
291
+ if fileserver_config
292
+ commands << [
293
+ sudo('cp'),
294
+ File.join(config[:root_path], 'fileserver.conf'),
295
+ '/etc/puppet'
296
+ ].join(' ')
297
+ end
256
298
 
257
- yield if block_given?
299
+ if hiera_data && hiera_data_remote_path == '/var/lib/hiera'
300
+ commands << [
301
+ sudo('cp -r'), File.join(config[:root_path], 'hiera'), '/var/lib/'
302
+ ].join(' ')
303
+ end
258
304
 
259
- prepare_modules
260
- prepare_manifests
261
- prepare_files
262
- prepare_puppet_config
263
- prepare_hiera_config
264
- prepare_fileserver_config
265
- prepare_hiera_data
266
- info('Finished Preparing files for transfer')
305
+ if hiera_data && hiera_data_remote_path != '/var/lib/hiera'
306
+ commands << [
307
+ sudo('mkdir -p'), hiera_data_remote_path
308
+ ].join(' ')
309
+ commands << [
310
+ sudo('cp -r'), File.join(config[:root_path], 'hiera/*'), hiera_data_remote_path
311
+ ].join(' ')
312
+ end
267
313
 
314
+ if hiera_eyaml
315
+ commands << [
316
+ sudo('mkdir -p'), hiera_eyaml_key_remote_path
317
+ ].join(' ')
318
+ commands << [
319
+ sudo('cp -r'), File.join(config[:root_path], 'hiera_keys/*'), hiera_eyaml_key_remote_path
320
+ ].join(' ')
268
321
  end
269
322
 
270
- def cleanup_sandbox
271
- return if sandbox_path.nil?
272
- debug("Cleaning up local sandbox in #{sandbox_path}")
273
- FileUtils.rmtree(sandbox_path)
323
+ command = commands.join(' && ')
324
+ debug(command)
325
+ command
326
+ end
327
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
328
+
329
+ def run_command
330
+ if !config[:puppet_apply_command].nil?
331
+ return config[:puppet_apply_command]
332
+ else
333
+ [
334
+ custom_facts,
335
+ facter_facts,
336
+ sudo('puppet'),
337
+ 'apply',
338
+ File.join(config[:root_path], 'manifests', manifest),
339
+ "--modulepath=#{File.join(config[:root_path], 'modules')}",
340
+ "--manifestdir=#{File.join(config[:root_path], 'manifests')}",
341
+ "--fileserverconfig=#{File.join(config[:root_path], 'fileserver.conf')}",
342
+ puppet_environment_flag,
343
+ puppet_noop_flag,
344
+ puppet_verbose_flag,
345
+ puppet_debug_flag,
346
+ remove_repo
347
+ ].join(' ')
274
348
  end
275
-
276
- def prepare_command
277
- commands = []
278
-
279
- if puppet_config
280
- commands << [
281
- sudo('cp'),
282
- File.join(config[:root_path], 'puppet.conf'),
283
- '/etc/puppet',
284
- ].join(' ')
285
- end
349
+ end
286
350
 
287
- if hiera_config
288
- commands << [
289
- sudo('cp'), File.join(config[:root_path],'hiera.yaml'), '/etc/',
290
- ].join(' ')
351
+ protected
291
352
 
292
- commands << [
293
- sudo('cp'), File.join(config[:root_path],'hiera.yaml'), '/etc/puppet/',
294
- ].join(' ')
295
- end
353
+ def load_needed_dependencies!
354
+ return unless File.exist?(puppetfile)
355
+ return unless config[:resolve_with_librarian_puppet]
356
+ debug("Puppetfile found at #{puppetfile}, loading Librarian-Puppet")
357
+ Puppet::Librarian.load!(logger)
358
+ end
296
359
 
297
- if fileserver_config
298
- commands << [
299
- sudo('cp'),
300
- File.join(config[:root_path], 'fileserver.conf'),
301
- '/etc/puppet',
302
- ].join(' ')
303
- end
360
+ def tmpmodules_dir
361
+ File.join(sandbox_path, 'modules')
362
+ end
304
363
 
305
- if hiera_data and hiera_data_remote_path == '/var/lib/hiera'
306
- commands << [
307
- sudo('cp -r'), File.join(config[:root_path], 'hiera'), '/var/lib/'
308
- ].join(' ')
309
- end
364
+ def puppetfile
365
+ config[:puppetfile_path] || ''
366
+ end
310
367
 
311
- if hiera_data and hiera_data_remote_path != '/var/lib/hiera'
312
- commands << [
313
- sudo('mkdir -p'), hiera_data_remote_path
314
- ].join(' ')
315
- commands << [
316
- sudo('cp -r'), File.join(config[:root_path], 'hiera/*'), hiera_data_remote_path
317
- ].join(' ')
318
- end
368
+ def modulefile
369
+ config[:modulefile_path] || ''
370
+ end
319
371
 
320
- if hiera_eyaml
321
- commands << [
322
- sudo('mkdir -p'), hiera_eyaml_key_remote_path
323
- ].join(' ')
324
- commands << [
325
- sudo('cp -r'), File.join(config[:root_path], 'hiera_keys/*'), hiera_eyaml_key_remote_path
326
- ].join(' ')
327
- end
372
+ def metadata_json
373
+ config[:metadata_json_path] || ''
374
+ end
328
375
 
329
- command = commands.join(' && ')
330
- debug(command)
331
- command
332
- end
376
+ def manifest
377
+ config[:manifest]
378
+ end
333
379
 
334
- def run_command
335
- if !config[:puppet_apply_command].nil?
336
- return config[:puppet_apply_command]
337
- else
338
- [
339
- custom_facts,
340
- sudo('puppet'),
341
- 'apply',
342
- File.join(config[:root_path], 'manifests', manifest),
343
- "--modulepath=#{File.join(config[:root_path], 'modules')}",
344
- "--manifestdir=#{File.join(config[:root_path], 'manifests')}",
345
- "--fileserverconfig=#{File.join(config[:root_path], 'fileserver.conf')}",
346
- puppet_environment_flag,
347
- puppet_noop_flag,
348
- puppet_verbose_flag,
349
- puppet_debug_flag,
350
- remove_repo
351
- ].join(" ")
352
- end
353
- end
380
+ def manifests
381
+ config[:manifests_path]
382
+ end
354
383
 
355
- protected
384
+ def modules
385
+ config[:modules_path]
386
+ end
356
387
 
357
- def load_needed_dependencies!
358
- if File.exists?(puppetfile) and config[:resolve_with_librarian_puppet]
359
- debug("Puppetfile found at #{puppetfile}, loading Librarian-Puppet")
360
- Puppet::Librarian.load!(logger)
361
- end
362
- end
388
+ def files
389
+ config[:files_path] || 'files'
390
+ end
363
391
 
364
- def tmpmodules_dir
365
- File.join(sandbox_path, 'modules')
366
- end
392
+ def puppet_config
393
+ config[:puppet_config_path]
394
+ end
367
395
 
368
- def puppetfile
369
- config[:puppetfile_path] or ''
370
- end
396
+ def puppet_environment
397
+ config[:puppet_environment]
398
+ end
371
399
 
372
- def modulefile
373
- config[:modulefile_path] or ''
374
- end
400
+ def hiera_config
401
+ config[:hiera_config_path]
402
+ end
375
403
 
376
- def metadata_json
377
- config[:metadata_json_path] or ''
378
- end
404
+ def fileserver_config
405
+ config[:fileserver_config_path]
406
+ end
379
407
 
380
- def manifest
381
- config[:manifest]
382
- end
408
+ def hiera_data
409
+ config[:hiera_data_path]
410
+ end
383
411
 
384
- def manifests
385
- config[:manifests_path]
386
- end
412
+ def hiera_data_remote_path
413
+ config[:hiera_data_remote_path]
414
+ end
387
415
 
388
- def modules
389
- config[:modules_path]
390
- end
416
+ def hiera_eyaml
417
+ config[:hiera_eyaml]
418
+ end
391
419
 
392
- def files
393
- config[:files_path] || 'files'
394
- end
420
+ def hiera_eyaml_key_path
421
+ config[:hiera_eyaml_key_path]
422
+ end
395
423
 
396
- def puppet_config
397
- config[:puppet_config_path]
398
- end
399
-
400
- def puppet_environment
401
- config[:puppet_environment]
402
- end
403
-
404
- def hiera_config
405
- config[:hiera_config_path]
406
- end
424
+ def hiera_eyaml_key_remote_path
425
+ config[:hiera_eyaml_key_remote_path]
426
+ end
407
427
 
408
- def fileserver_config
409
- config[:fileserver_config_path]
410
- end
428
+ def librarian_puppet_ssl_file
429
+ config[:librarian_puppet_ssl_file]
430
+ end
411
431
 
412
- def hiera_data
413
- config[:hiera_data_path]
414
- end
432
+ def puppet_debian_version
433
+ config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
434
+ end
415
435
 
416
- def hiera_data_remote_path
417
- config[:hiera_data_remote_path]
418
- end
419
-
420
- def hiera_eyaml
421
- config[:hiera_eyaml]
422
- end
423
-
424
- def hiera_eyaml_key_path
425
- config[:hiera_eyaml_key_path]
426
- end
427
-
428
- def hiera_eyaml_key_remote_path
429
- config[:hiera_eyaml_key_remote_path]
430
- end
431
-
432
- def librarian_puppet_ssl_file
433
- config[:librarian_puppet_ssl_file]
434
- end
435
-
436
- def puppet_debian_version
437
- config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
438
- end
436
+ def puppet_redhat_version
437
+ config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
438
+ end
439
439
 
440
- def puppet_redhat_version
441
- config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
442
- end
440
+ def puppet_environment_flag
441
+ config[:puppet_environment] ? "--environment=#{config[:puppet_environment]}" : nil
442
+ end
443
443
 
444
- def puppet_environment_flag
445
- config[:puppet_environment] ? "--environment=#{config[:puppet_environment]}" : nil
446
- end
444
+ def puppet_noop_flag
445
+ config[:puppet_noop] ? '--noop' : nil
446
+ end
447
447
 
448
- def puppet_noop_flag
449
- config[:puppet_noop] ? '--noop' : nil
450
- end
448
+ def puppet_debug_flag
449
+ config[:puppet_debug] ? '-d' : nil
450
+ end
451
451
 
452
- def puppet_debug_flag
453
- config[:puppet_debug] ? '-d' : nil
454
- end
452
+ def puppet_verbose_flag
453
+ config[:puppet_verbose] ? '-v' : nil
454
+ end
455
455
 
456
- def puppet_verbose_flag
457
- config[:puppet_verbose] ? '-v' : nil
458
- end
456
+ def puppet_platform
457
+ config[:puppet_platform].to_s.downcase
458
+ end
459
459
 
460
- def puppet_platform
461
- config[:puppet_platform].to_s.downcase
460
+ def facter_facts
461
+ return nil unless config[:facter_file]
462
+ fact_vars = "export "
463
+ fact_hash = YAML.load_file(config[:facter_file])
464
+ fact_hash.each do |key, value|
465
+ fact_vars << "FACTER_#{key}=#{value} "
462
466
  end
467
+ fact_vars << ";"
468
+ fact_vars
469
+ end
463
470
 
464
- def update_packages_debian_cmd
465
- config[:update_package_repos] ? "#{sudo('apt-get')} update" : nil
466
- end
471
+ def update_packages_debian_cmd
472
+ config[:update_package_repos] ? "#{sudo('apt-get')} update" : nil
473
+ end
467
474
 
468
- def update_packages_redhat_cmd
469
- config[:update_package_repos] ? "#{sudo('yum')} makecache" : nil
470
- end
471
-
472
- def remove_puppet_repo
473
- config[:remove_puppet_repo]
474
- end
475
-
476
- def custom_facts
477
- return nil if config[:custom_facts].none?
478
- bash_vars = config[:custom_facts].map { |k,v| "FACTER_#{k}=#{v}" }.join(" ")
479
- bash_vars = "export #{bash_vars};"
480
- debug(bash_vars)
481
- bash_vars
482
- end
475
+ def update_packages_redhat_cmd
476
+ config[:update_package_repos] ? "#{sudo('yum')} makecache" : nil
477
+ end
483
478
 
484
- def remove_repo
485
- if remove_puppet_repo
486
- "; #{sudo('rm')} -rf /tmp/kitchen #{hiera_data_remote_path} #{hiera_eyaml_key_remote_path} /etc/puppet/* "
487
- else
488
- nil
489
- end
490
- end
491
-
492
- def puppet_apt_repo
493
- config[:puppet_apt_repo]
494
- end
479
+ def remove_puppet_repo
480
+ config[:remove_puppet_repo]
481
+ end
495
482
 
496
- def puppet_apt_repo_file
497
- config[:puppet_apt_repo].split('/').last
498
- end
483
+ def custom_facts
484
+ return nil if config[:custom_facts].none?
485
+ bash_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
486
+ bash_vars = "export #{bash_vars};"
487
+ debug(bash_vars)
488
+ bash_vars
489
+ end
499
490
 
500
- def puppet_yum_repo
501
- config[:puppet_yum_repo]
491
+ def remove_repo
492
+ if remove_puppet_repo
493
+ "; #{sudo('rm')} -rf /tmp/kitchen #{hiera_data_remote_path} #{hiera_eyaml_key_remote_path} /etc/puppet/* "
494
+ else
495
+ nil
502
496
  end
497
+ end
503
498
 
504
- def chef_url
505
- config[:chef_bootstrap_url]
506
- end
499
+ def puppet_apt_repo
500
+ config[:puppet_apt_repo]
501
+ end
507
502
 
508
- def prepare_manifests
509
- info('Preparing manifests')
510
- debug("Using manifests from #{manifests}")
503
+ def puppet_apt_repo_file
504
+ config[:puppet_apt_repo].split('/').last
505
+ end
511
506
 
512
- tmp_manifests_dir = File.join(sandbox_path, 'manifests')
513
- FileUtils.mkdir_p(tmp_manifests_dir)
514
- FileUtils.cp_r(Dir.glob("#{manifests}/*"), tmp_manifests_dir)
515
- end
507
+ def puppet_yum_repo
508
+ config[:puppet_yum_repo]
509
+ end
516
510
 
517
- def prepare_files
518
- info('Preparing files')
511
+ def chef_url
512
+ config[:chef_bootstrap_url]
513
+ end
519
514
 
520
- unless File.directory?(files)
521
- info 'nothing to do for files'
522
- return
523
- end
515
+ def prepare_manifests
516
+ info('Preparing manifests')
517
+ debug("Using manifests from #{manifests}")
524
518
 
525
- debug("Using files from #{files}")
519
+ tmp_manifests_dir = File.join(sandbox_path, 'manifests')
520
+ FileUtils.mkdir_p(tmp_manifests_dir)
521
+ FileUtils.cp_r(Dir.glob("#{manifests}/*"), tmp_manifests_dir)
522
+ end
526
523
 
527
- tmp_files_dir = File.join(sandbox_path, 'files')
528
- FileUtils.mkdir_p(tmp_files_dir)
529
- FileUtils.cp_r(Dir.glob("#{files}/*"), tmp_files_dir)
524
+ def prepare_files
525
+ info('Preparing files')
526
+ unless File.directory?(files)
527
+ info 'nothing to do for files'
528
+ return
530
529
  end
531
530
 
532
- def prepare_modules
533
- info('Preparing modules')
531
+ debug("Using files from #{files}")
534
532
 
535
- FileUtils.mkdir_p(tmpmodules_dir)
536
-
537
- resolve_with_librarian if File.exists?(puppetfile) and config[:resolve_with_librarian_puppet]
533
+ tmp_files_dir = File.join(sandbox_path, 'files')
534
+ FileUtils.mkdir_p(tmp_files_dir)
535
+ FileUtils.cp_r(Dir.glob("#{files}/*"), tmp_files_dir)
536
+ end
538
537
 
539
- if modules && File.directory?(modules)
540
- debug("Copying modules from #{modules} to #{tmpmodules_dir}")
541
- FileUtils.cp_r(Dir.glob("#{modules}/*"), tmpmodules_dir, remove_destination: true)
542
- else
543
- info 'nothing to do for modules'
544
- end
538
+ def prepare_modules
539
+ info('Preparing modules')
540
+
541
+ FileUtils.mkdir_p(tmpmodules_dir)
542
+ resolve_with_librarian if File.exist?(puppetfile) && config[:resolve_with_librarian_puppet]
545
543
 
546
- copy_self_as_module
544
+ if modules && File.directory?(modules)
545
+ debug("Copying modules from #{modules} to #{tmpmodules_dir}")
546
+ FileUtils.cp_r(Dir.glob("#{modules}/*"), tmpmodules_dir, remove_destination: true)
547
+ else
548
+ info 'nothing to do for modules'
547
549
  end
548
550
 
549
- def copy_self_as_module
550
- if File.exists?(modulefile)
551
- warn('Modulefile found but this is depricated, ignoring it, see https://tickets.puppetlabs.com/browse/PUP-1188')
552
- end
551
+ copy_self_as_module
552
+ end
553
553
 
554
- if File.exists?(metadata_json)
555
- module_name = nil
556
- begin
557
- module_name = JSON.parse(IO.read(metadata_json))['name'].split('-').last
558
- rescue
559
- error("not able to load or parse #{metadata_json_path} for the name of the module")
560
- end
561
-
562
- if module_name
563
- module_target_path = File.join(sandbox_path, 'modules', module_name)
564
- FileUtils.mkdir_p(module_target_path)
565
- FileUtils.cp_r(
566
- Dir.glob(File.join(config[:kitchen_root], '*')).reject { |entry| entry =~ /modules/ },
567
- module_target_path,
568
- remove_destination: true
569
- )
570
- end
571
- end
554
+ def copy_self_as_module
555
+ if File.exist?(modulefile)
556
+ warn('Modulefile found but this is depricated, ignoring it, see https://tickets.puppetlabs.com/browse/PUP-1188')
572
557
  end
573
558
 
574
- def prepare_puppet_config
575
- return unless puppet_config
559
+ return unless File.exist?(metadata_json)
560
+ module_name = nil
561
+ begin
562
+ module_name = JSON.parse(IO.read(metadata_json))['name'].split('-').last
563
+ rescue
564
+ error("not able to load or parse #{metadata_json_path} for the name of the module")
565
+ end
576
566
 
577
- info('Preparing puppet.conf')
578
- debug("Using puppet config from #{puppet_config}")
567
+ return unless module_name
568
+ module_target_path = File.join(sandbox_path, 'modules', module_name)
569
+ FileUtils.mkdir_p(module_target_path)
570
+ FileUtils.cp_r(
571
+ Dir.glob(File.join(config[:kitchen_root], '*')).reject { |entry| entry =~ /modules$/ },
572
+ module_target_path,
573
+ remove_destination: true
574
+ )
575
+ end
579
576
 
580
- FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
581
- end
577
+ def prepare_puppet_config
578
+ return unless puppet_config
582
579
 
583
- def prepare_hiera_config
584
- return unless hiera_config
580
+ info('Preparing puppet.conf')
581
+ debug("Using puppet config from #{puppet_config}")
585
582
 
586
- info('Preparing hiera')
587
- debug("Using hiera from #{hiera_config}")
583
+ FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
584
+ end
588
585
 
589
- FileUtils.cp_r(hiera_config, File.join(sandbox_path, 'hiera.yaml'))
590
- end
586
+ def prepare_hiera_config
587
+ return unless hiera_config
591
588
 
592
- def prepare_fileserver_config
593
- return unless fileserver_config
589
+ info('Preparing hiera')
590
+ debug("Using hiera from #{hiera_config}")
594
591
 
595
- info('Preparing fileserver')
596
- debug("Using fileserver config from #{fileserver_config}")
592
+ FileUtils.cp_r(hiera_config, File.join(sandbox_path, 'hiera.yaml'))
593
+ end
597
594
 
598
- FileUtils.cp_r(fileserver_config, File.join(sandbox_path, 'fileserver.conf'))
599
- end
595
+ def prepare_fileserver_config
596
+ return unless fileserver_config
600
597
 
601
- def prepare_hiera_data
602
- return unless hiera_data
603
- info('Preparing hiera data')
604
- tmp_hiera_dir = File.join(sandbox_path, 'hiera')
605
- debug("Copying hiera data from #{hiera_data} to #{tmp_hiera_dir}")
606
- FileUtils.mkdir_p(tmp_hiera_dir)
607
- FileUtils.cp_r(Dir.glob("#{hiera_data}/*"), tmp_hiera_dir)
608
- return unless hiera_eyaml_key_path
609
- tmp_hiera_key_dir = File.join(sandbox_path, 'hiera_keys')
610
- debug("Copying hiera eyaml keys from #{hiera_eyaml_key_path} to #{tmp_hiera_key_dir}")
611
- FileUtils.mkdir_p(tmp_hiera_key_dir)
612
- FileUtils.cp_r(Dir.glob("#{hiera_eyaml_key_path}/*"), tmp_hiera_key_dir)
613
- end
598
+ info('Preparing fileserver')
599
+ debug("Using fileserver config from #{fileserver_config}")
614
600
 
615
- def resolve_with_librarian
616
- Kitchen.mutex.synchronize do
617
- ENV["SSL_CERT_FILE"]=librarian_puppet_ssl_file if librarian_puppet_ssl_file
618
- Puppet::Librarian.new(puppetfile, tmpmodules_dir, logger).resolve
619
- ENV["SSL_CERT_FILE"]='' if librarian_puppet_ssl_file
620
- end
601
+ FileUtils.cp_r(fileserver_config, File.join(sandbox_path, 'fileserver.conf'))
602
+ end
603
+
604
+ def prepare_hiera_data
605
+ return unless hiera_data
606
+ info('Preparing hiera data')
607
+ tmp_hiera_dir = File.join(sandbox_path, 'hiera')
608
+ debug("Copying hiera data from #{hiera_data} to #{tmp_hiera_dir}")
609
+ FileUtils.mkdir_p(tmp_hiera_dir)
610
+ FileUtils.cp_r(Dir.glob("#{hiera_data}/*"), tmp_hiera_dir)
611
+ return unless hiera_eyaml_key_path
612
+ tmp_hiera_key_dir = File.join(sandbox_path, 'hiera_keys')
613
+ debug("Copying hiera eyaml keys from #{hiera_eyaml_key_path} to #{tmp_hiera_key_dir}")
614
+ FileUtils.mkdir_p(tmp_hiera_key_dir)
615
+ FileUtils.cp_r(Dir.glob("#{hiera_eyaml_key_path}/*"), tmp_hiera_key_dir)
616
+ end
617
+
618
+ def resolve_with_librarian
619
+ Kitchen.mutex.synchronize do
620
+ ENV['SSL_CERT_FILE'] = librarian_puppet_ssl_file if librarian_puppet_ssl_file
621
+ Puppet::Librarian.new(puppetfile, tmpmodules_dir, logger).resolve
622
+ ENV['SSL_CERT_FILE'] = '' if librarian_puppet_ssl_file
621
623
  end
624
+ end
622
625
  end
623
626
  end
624
627
  end