kitchen-puppet 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,7 @@ Puppet Provisioner for Test Kitchen
22
22
 
23
23
  == FEATURES:
24
24
 
25
- Supports puppet apply, puppet agent, hiera, hiera-eyaml, custom facts, librarian-puppet
25
+ Supports puppet apply, puppet agent, hiera, hiera-eyaml, custom facts, librarian-puppet, puppet collections (v4)
26
26
 
27
27
  EOF
28
28
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kitchen
4
4
  module Puppet
5
- VERSION = '0.0.24'
5
+ VERSION = '0.0.25'
6
6
  end
7
7
  end
@@ -116,6 +116,7 @@ module Kitchen
116
116
  info("Installing puppet on #{puppet_platform}")
117
117
  <<-INSTALL
118
118
  if [ ! $(which puppet) ]; then
119
+ #{sudo('apt-get')} -y install wget
119
120
  #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
120
121
  #{sudo('dpkg')} -i #{puppet_apt_repo_file}
121
122
  #{update_packages_debian_cmd}
@@ -148,6 +149,7 @@ module Kitchen
148
149
  #{update_packages_redhat_cmd}
149
150
  #{sudo('yum')} -y install puppet#{puppet_redhat_version}
150
151
  else
152
+ #{sudo('apt-get')} -y install wget
151
153
  #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
152
154
  #{sudo('dpkg')} -i #{puppet_apt_repo_file}
153
155
  #{update_packages_debian_cmd}
@@ -39,10 +39,10 @@ module Kitchen
39
39
  class PuppetApply < Base
40
40
  attr_accessor :tmp_dir
41
41
 
42
- default_config :require_puppet_omnibus, false
43
- # TODO: use something like https://github.com/fnichol/omnibus-puppet
44
- default_config :puppet_omnibus_url, nil
45
- default_config :puppet_omnibus_remote_path, '/opt/puppet'
42
+ default_config :require_puppet_collections, false
43
+ default_config :puppet_yum_collections_repo, 'http://yum.puppetlabs.com/puppetlabs-release-pc1-el-6.noarch.rpm'
44
+ default_config :puppet_apt_collections_repo, 'http://apt.puppetlabs.com/puppetlabs-release-pc1-wheezy.deb'
45
+ default_config :puppet_coll_remote_path, '/opt/puppetlabs'
46
46
  default_config :puppet_version, nil
47
47
  default_config :require_puppet_repo, true
48
48
  default_config :require_chef_for_busser, true
@@ -57,6 +57,7 @@ module Kitchen
57
57
  default_config :puppet_apply_command, nil
58
58
 
59
59
  default_config :http_proxy, nil
60
+ default_config :https_proxy, nil
60
61
 
61
62
  default_config :hiera_data_remote_path, '/var/lib/hiera'
62
63
  default_config :manifest, 'site.pp'
@@ -141,35 +142,20 @@ module Kitchen
141
142
  type == :directory ? File.directory?(c) : File.file?(c)
142
143
  end
143
144
  end
144
-
145
+
145
146
  # TODO: refactor for smaller cyclomatic complexity and perceived complexity
146
147
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
147
148
  def install_command
148
- return unless config[:require_puppet_omnibus] || config[:require_puppet_repo]
149
- if config[:require_puppet_omnibus]
150
- info('Installing puppet using puppet omnibus')
151
- if !config[:puppet_version].nil?
152
- version = "-v #{config[:puppet_version]}"
153
- else
154
- version = ''
155
- end
156
- <<-INSTALL
157
- #{Util.shell_helpers}
158
-
159
- if [ ! -d "#{config[:puppet_omnibus_remote_path]}" ]; then
160
- echo "-----> Installing Puppet Omnibus"
161
- do_download #{config[:puppet_omnibus_url]} /tmp/puppet_install.sh
162
- #{sudo('sh')} /tmp/puppet_install.sh #{version}
163
- fi
164
- #{install_deep_merge}
165
- #{install_busser}
166
- INSTALL
149
+ return unless config[:require_puppet_collections] || config[:require_puppet_repo]
150
+ if config[:require_puppet_collections]
151
+ install_command_collections
167
152
  else
168
- case puppet_platform
169
- when 'debian', 'ubuntu'
153
+ case puppet_platform
154
+ when 'debian', 'ubuntu'
170
155
  info("Installing puppet on #{puppet_platform}")
171
156
  <<-INSTALL
172
157
  if [ ! $(which puppet) ]; then
158
+ #{sudo('apt-get')} -y install wget
173
159
  #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
174
160
  #{sudo('dpkg')} -i #{puppet_apt_repo_file}
175
161
  #{update_packages_debian_cmd}
@@ -181,31 +167,32 @@ module Kitchen
181
167
  #{install_busser}
182
168
  INSTALL
183
169
  when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
184
- info("Installing puppet on #{puppet_platform}")
185
- <<-INSTALL
186
- if [ ! $(which puppet) ]; then
187
- #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
188
- #{update_packages_redhat_cmd}
189
- #{sudo_env('yum')} -y install puppet#{puppet_redhat_version}
190
- fi
191
- #{install_eyaml}
192
- #{install_deep_merge}
193
- #{install_busser}
194
- INSTALL
170
+ info("Installing puppet from yum on #{puppet_platform}")
171
+ <<-INSTALL
172
+ if [ ! $(which puppet) ]; then
173
+ #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
174
+ #{update_packages_redhat_cmd}
175
+ #{sudo_env('yum')} -y install puppet#{puppet_redhat_version}
176
+ fi
177
+ #{install_eyaml}
178
+ #{install_deep_merge}
179
+ #{install_busser}
180
+ INSTALL
195
181
  else
196
182
  info('Installing puppet, will try to determine platform os')
197
183
  <<-INSTALL
198
184
  if [ ! $(which puppet) ]; then
199
185
  if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
200
- #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
201
- #{update_packages_redhat_cmd}
202
- #{sudo_env('yum')} -y install puppet#{puppet_redhat_version}
203
- else
204
- if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
205
186
  #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
206
187
  #{update_packages_redhat_cmd}
207
188
  #{sudo_env('yum')} -y install puppet#{puppet_redhat_version}
189
+ else
190
+ if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
191
+ #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
192
+ #{update_packages_redhat_cmd}
193
+ #{sudo_env('yum')} -y install puppet#{puppet_redhat_version}
208
194
  else
195
+ #{sudo('apt-get')} -y install wget
209
196
  #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
210
197
  #{sudo('dpkg')} -i #{puppet_apt_repo_file}
211
198
  #{update_packages_debian_cmd}
@@ -219,9 +206,62 @@ module Kitchen
219
206
  #{install_busser}
220
207
  INSTALL
221
208
  end
222
- end
223
- end
224
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
209
+ end
210
+ end
211
+
212
+ def install_command_collections
213
+ case puppet_platform
214
+ when 'debian', 'ubuntu'
215
+ info("Installing Puppet Collections on #{puppet_platform}")
216
+ #{sudo('apt-get')} -y install wget
217
+ #{sudo('wget')} #{wget_proxy_parm} #{config[:puppet_apt_collections_repo]}
218
+ #{sudo('dpkg')} -i #{puppet_apt_coll_repo_file}
219
+ when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
220
+ info("Installing Puppet Collections on #{puppet_platform}")
221
+ <<-INSTALL
222
+ #{Util.shell_helpers}
223
+ if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
224
+ echo "-----> #{sudo_env('yum')} -y localinstall #{config[:puppet_yum_collections_repo]}"
225
+ #{sudo_env('yum')} -y localinstall #{config[:puppet_yum_collections_repo]}
226
+ #{sudo_env('yum')} -y install puppet
227
+ fi
228
+ #{install_eyaml("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
229
+ #{install_deep_merge}
230
+ #{install_busser}
231
+ INSTALL
232
+ else
233
+ info('Installing Puppet Collections, will try to determine platform os')
234
+ <<-INSTALL
235
+ if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
236
+ if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
237
+ #{Util.shell_helpers}
238
+ if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
239
+ echo "-----> #{sudo_env('yum')} -y localinstall #{config[:puppet_yum_collections_repo]}"
240
+ #{sudo_env('yum')} -y localinstall #{config[:puppet_yum_collections_repo]}
241
+ #{sudo_env('yum')} -y install puppet
242
+ fi
243
+ else
244
+ if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
245
+ #{Util.shell_helpers}
246
+ if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
247
+ echo "-----> #{sudo_env('yum')} -y localinstall #{config[:puppet_yum_collections_repo]}"
248
+ #{sudo_env('yum')} -y localinstall #{config[:puppet_yum_collections_repo]}
249
+ #{sudo_env('yum')} -y install puppet
250
+ fi
251
+ else
252
+ #{sudo('apt-get')} -y install wget
253
+ #{sudo('wget')} #{wget_proxy_parm} #{config[:puppet_apt_collections_repo]}
254
+ #{sudo('dpkg')} -i #{puppet_apt_coll_repo_file}
255
+ fi
256
+ fi
257
+ fi
258
+ #{install_eyaml("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
259
+ #{install_deep_merge}
260
+ #{install_busser}
261
+ INSTALL
262
+ end
263
+ end
264
+
225
265
  def install_deep_merge
226
266
  return unless config[:hiera_deep_merge]
227
267
  <<-INSTALL
@@ -233,14 +273,14 @@ module Kitchen
233
273
  INSTALL
234
274
  end
235
275
 
236
- def install_eyaml
276
+ def install_eyaml(gem_cmd='gem')
237
277
  return unless config[:hiera_eyaml]
238
278
  <<-INSTALL
239
279
  # A backend for Hiera that provides per-value asymmetric encryption of sensitive data
240
- if [[ $(#{sudo('gem')} list hiera-eyaml -i) == 'false' ]]; then
280
+ if [[ $(#{sudo(gem_cmd)} list hiera-eyaml -i) == 'false' ]]; then
241
281
  echo '-----> Installing hiera-eyaml to provide encryption of hiera data'
242
- #{sudo('gem')} install #{gem_proxy_parm} --no-ri --no-rdoc highline -v 1.6.21
243
- #{sudo('gem')} install #{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml
282
+ #{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc highline -v 1.6.21
283
+ #{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml
244
284
  fi
245
285
  INSTALL
246
286
  end
@@ -265,8 +305,9 @@ module Kitchen
265
305
  def init_command
266
306
  dirs = %w(modules manifests files hiera hiera.yaml)
267
307
  .map { |dir| File.join(config[:root_path], dir) }.join(' ')
268
- cmd = "#{sudo('rm')} -rf #{dirs} #{hiera_data_remote_path} /etc/hiera.yaml /etc/puppet/hiera.yaml /etc/puppet/fileserver.conf;"
269
- cmd += " mkdir -p #{config[:root_path]}"
308
+ cmd = "#{sudo('rm')} -rf #{dirs} #{hiera_data_remote_path} /etc/hiera.yaml #{puppet_dir}/hiera.yaml #{puppet_dir}/fileserver.conf;"
309
+ cmd += config[:puppet_environment] ? "#{sudo('rm')} -f #{File.join(puppet_dir, config[:puppet_environment])};" : ''
310
+ cmd += " mkdir -p #{config[:root_path]} #{puppet_dir}"
270
311
  debug(cmd)
271
312
  cmd
272
313
  end
@@ -299,7 +340,7 @@ module Kitchen
299
340
  commands << [
300
341
  sudo('cp'),
301
342
  File.join(config[:root_path], 'puppet.conf'),
302
- '/etc/puppet'
343
+ puppet_dir
303
344
  ].join(' ')
304
345
  end
305
346
 
@@ -309,7 +350,7 @@ module Kitchen
309
350
  ].join(' ')
310
351
 
311
352
  commands << [
312
- sudo('cp'), File.join(config[:root_path], 'hiera.yaml'), '/etc/puppet/'
353
+ sudo('cp'), File.join(config[:root_path], 'hiera.yaml'), puppet_dir
313
354
  ].join(' ')
314
355
  end
315
356
 
@@ -317,7 +358,7 @@ module Kitchen
317
358
  commands << [
318
359
  sudo('cp'),
319
360
  File.join(config[:root_path], 'fileserver.conf'),
320
- '/etc/puppet'
361
+ puppet_dir
321
362
  ].join(' ')
322
363
  end
323
364
 
@@ -345,6 +386,12 @@ module Kitchen
345
386
  ].join(' ')
346
387
  end
347
388
 
389
+ if puppet_environment
390
+ commands << [
391
+ sudo('ln -s '), config[:root_path], File.join(puppet_dir, config[:puppet_environment])
392
+ ].join(' ')
393
+ end
394
+
348
395
  command = commands.join(' && ')
349
396
  debug(command)
350
397
  command
@@ -358,11 +405,11 @@ module Kitchen
358
405
  [
359
406
  custom_facts,
360
407
  facter_facts,
361
- sudo_env('puppet'),
408
+ puppet_cmd,
362
409
  'apply',
363
410
  File.join(config[:root_path], 'manifests', manifest),
364
411
  "--modulepath=#{File.join(config[:root_path], 'modules')}",
365
- "--manifestdir=#{File.join(config[:root_path], 'manifests')}",
412
+ puppet_manifestdir,
366
413
  "--fileserverconfig=#{File.join(config[:root_path], 'fileserver.conf')}",
367
414
  puppet_environment_flag,
368
415
  puppet_noop_flag,
@@ -460,6 +507,22 @@ module Kitchen
460
507
  config[:librarian_puppet_ssl_file]
461
508
  end
462
509
 
510
+ def puppet_cmd
511
+ if config[:require_puppet_collections]
512
+ sudo_env("#{config[:puppet_coll_remote_path]}/bin/puppet")
513
+ else
514
+ sudo_env('puppet')
515
+ end
516
+ end
517
+
518
+ def puppet_dir
519
+ if config[:require_puppet_collections]
520
+ '/etc/puppetlabs/puppet'
521
+ else
522
+ '/etc/puppet'
523
+ end
524
+ end
525
+
463
526
  def puppet_debian_version
464
527
  config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
465
528
  end
@@ -468,8 +531,12 @@ module Kitchen
468
531
  config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
469
532
  end
470
533
 
471
- def puppet_environment_flag
472
- config[:puppet_environment] ? "--environment=#{config[:puppet_environment]}" : nil
534
+ def puppet_environment_flag
535
+ config[:puppet_environment] ? "--environment=#{config[:puppet_environment]} --environmentpath=#{puppet_dir}" : nil
536
+ end
537
+
538
+ def puppet_manifestdir
539
+ config[:puppet_environment] ? nil : "--manifestdir=#{File.join(config[:root_path], 'manifests')}"
473
540
  end
474
541
 
475
542
  def puppet_noop_flag
@@ -518,7 +585,9 @@ module Kitchen
518
585
  end
519
586
 
520
587
  def sudo_env(pm)
521
- http_proxy ? "#{sudo('env')} http_proxy=#{http_proxy} #{pm}" : "#{sudo(pm)}"
588
+ s = https_proxy ? "https_proxy=#{https_proxy}" : nil
589
+ p = http_proxy ? "http_proxy=#{http_proxy}" : nil
590
+ p || s ? "#{sudo('env')} #{p} #{s} #{pm}" : "#{sudo(pm)}"
522
591
  end
523
592
 
524
593
  def remove_puppet_repo
@@ -538,7 +607,7 @@ module Kitchen
538
607
  end
539
608
 
540
609
  def remove_repo
541
- remove_puppet_repo ? "; #{sudo('rm')} -rf /tmp/kitchen #{hiera_data_remote_path} #{hiera_eyaml_key_remote_path} /etc/puppet/* " : nil
610
+ remove_puppet_repo ? "; #{sudo('rm')} -rf /tmp/kitchen #{hiera_data_remote_path} #{hiera_eyaml_key_remote_path} #{puppet_dir}/* " : nil
542
611
  end
543
612
 
544
613
  def puppet_apt_repo
@@ -548,6 +617,10 @@ module Kitchen
548
617
  def puppet_apt_repo_file
549
618
  config[:puppet_apt_repo].split('/').last
550
619
  end
620
+
621
+ def puppet_apt_coll_repo_file
622
+ config[:puppet_apt_collections_repo].split('/').last
623
+ end
551
624
 
552
625
  def puppet_yum_repo
553
626
  config[:puppet_yum_repo]
@@ -562,12 +635,18 @@ module Kitchen
562
635
  end
563
636
 
564
637
  def wget_proxy_parm
565
- http_proxy ? "-e use_proxy=yes -e http_proxy=#{http_proxy}" : nil
638
+ p = http_proxy ? "-e http_proxy=#{http_proxy}" : nil
639
+ s = https_proxy ? "-e http_proxy=#{http_proxy}" : nil
640
+ p || s ? "-e use_proxy=yes #{p} #{s}" : nil
566
641
  end
567
642
 
568
643
  def http_proxy
569
644
  config[:http_proxy]
570
645
  end
646
+
647
+ def https_proxy
648
+ config[:https_proxy]
649
+ end
571
650
 
572
651
  def chef_url
573
652
  config[:chef_bootstrap_url]
@@ -8,9 +8,10 @@ puppet_platform | naively tries to determine | OS platform of server
8
8
  require_puppet_repo | true | Set if using a puppet install from yum or apt repo
9
9
  puppet_apt_repo | "http://apt.puppetlabs.com/puppetlabs-release-precise.deb"| apt repo
10
10
  puppet_yum_repo | "https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm"| yum repo
11
- require_puppet_omnibus | false | Set if using omnibus puppet install
12
- puppet_omnibus_url | | omnibus puppet install location.
13
- puppet_omnibus_remote_path | "/opt/puppet" | Server Installation location of an omnibus puppet install.
11
+ require_puppet_collections | false | Set if using puppet collections install (Puppet v4)
12
+ puppet_yum_collections_repo | "http://yum.puppetlabs.com/puppetlabs-release-pc1-el-6.noarch.rpm" | yum collections repo
13
+ puppet_apt_collections_repo | "http://apt.puppetlabs.com/puppetlabs-release-pc1-wheezy.deb" | apt collections repo
14
+ puppet_coll_remote_path | "/opt/puppetlabs" | Server Installation location of a puppet collections install.
14
15
  puppet_detailed_exitcodes | nil | Provide transaction information via exit codes.
15
16
  manifests_path | | puppet repo manifests directory
16
17
  manifest | 'site.pp' | manifest for puppet apply to run
@@ -33,16 +34,18 @@ require_chef_for_busser | true | Install chef as currently needed by busser to r
33
34
  resolve_with_librarian_puppet | true | Use librarian_puppet to resolve modules if a Puppetfile is found
34
35
  librarian_puppet_ssl_file | nil | ssl certificate file for librarian-puppet
35
36
  puppet_config_path | | path of custom puppet.conf file
36
- puppet_environment | nil | puppet environment for running puppet apply
37
+ puppet_environment | nil | puppet environment for running puppet apply (Must set if using Puppet v4)
37
38
  remove_puppet_repo | false | remove copy of puppet repository and puppet configuration on server after running puppet
38
39
  hiera_eyaml | false | use hiera-eyaml to encrypt hiera data
39
40
  hiera_eyaml_key_remote_path | "/etc/puppet/secure/keys" | directory of hiera-eyaml keys on server
40
41
  hiera_eyaml_key_path | "hiera_keys" | directory of hiera-eyaml keys on workstation
41
42
  hiera_deep_merge | false | install the deep_merge gem to support hiera deep merge mode
42
43
  facter_file | nil | yaml file of custom facter_files to be provided to the puppet-apply command
43
- http_proxy | nil | use http proxy when installing puppet and packages
44
+ http_proxy | nil | use http proxy when installing puppet, packages and running puppet
45
+ https_proxy | nil | use https proxy when installing puppet, packages and running puppet
44
46
  puppet_logdest | nil | _Array_ of log destinations. Include 'console' if wanted
45
47
 
48
+
46
49
  ## Puppet Apply Configuring Provisioner Options
47
50
 
48
51
  The provisioner can be configured globally or per suite, global settings act as defaults for all suites, you can then customise per suite, for example:
@@ -126,6 +129,8 @@ puppet_config_path | | path of custom puppet.conf file
126
129
  http_proxy | nil | use http proxy when installing puppet and packages
127
130
 
128
131
 
132
+ NOTE: Puppet Collections Support not in puppet agent yet
133
+
129
134
  ## Puppet Agent Configuring Provisioner Options
130
135
 
131
136
  The provisioner can be configured globally or per suite, global settings act as defaults for all suites, you can then customise per suite, for example:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.25
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,21 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-25 00:00:00.000000000 Z
12
+ date: 2015-04-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
- description: ! '== DESCRIPTION:
15
-
16
-
17
- Puppet Provisioner for Test Kitchen
18
-
19
-
20
- == FEATURES:
21
-
22
-
23
- Supports puppet apply, puppet agent, hiera, hiera-eyaml, custom facts, librarian-puppet
24
-
25
-
26
- '
14
+ description: ! "== DESCRIPTION:\n\nPuppet Provisioner for Test Kitchen\n\n== FEATURES:\n\nSupports
15
+ puppet apply, puppet agent, hiera, hiera-eyaml, custom facts, librarian-puppet,
16
+ puppet collections (v4) \n\n"
27
17
  email:
28
18
  - neillwturner@gmail.com
29
19
  executables: []