kitchen-puppet 0.0.15 → 0.0.16

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.
@@ -22,7 +22,7 @@ Puppet Provisioner for Test Kitchen
22
22
 
23
23
  == FEATURES:
24
24
 
25
- Supports puppet apply, hiera and custom facts
25
+ Supports puppet apply, puppet agent, hiera, hiera-eyaml, custom facts, librarian-puppet
26
26
 
27
27
  EOF
28
28
 
@@ -1,5 +1,5 @@
1
1
  module Kitchen
2
2
  module Puppet
3
- VERSION = "0.0.15"
3
+ VERSION = "0.0.16"
4
4
  end
5
5
  end
@@ -1,359 +1,365 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Author:: Chris Lundquist (<chris.lundquist@github.com>) Neill Turner (<neillwturner@gmail.com>)
4
- #
5
- # Copyright (C) 2013,2014 Chris Lundquist, Neill Turner
6
- #
7
- # Licensed under the Apache License, Version 2.0 (the "License");
8
- # you may not use this file except in compliance with the License.
9
- # You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing, software
14
- # distributed under the License is distributed on an "AS IS" BASIS,
15
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
- # See https://github.com/neillturner/kitchen-puppet/blob/master/provisioner_options.md
20
- # for documentation configuration parameters with puppet_agent provisioner.
21
- #
22
-
23
- require 'json'
24
- require 'kitchen/provisioner/base'
25
- require 'kitchen/provisioner/puppet/librarian'
26
-
27
- module Kitchen
28
-
29
- class Busser
30
-
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_omnibus_remote_path, '/opt/puppet'
47
- default_config :puppet_version, nil
48
- default_config :require_puppet_repo, true
49
- default_config :require_chef_for_busser, true
50
-
51
- default_config :puppet_apt_repo, "http://apt.puppetlabs.com/puppetlabs-release-precise.deb"
52
- default_config :puppet_yum_repo, "https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm"
53
- default_config :chef_bootstrap_url, "https://www.getchef.com/chef/install.sh"
54
-
55
- default_config :puppet_agent_command, nil
56
-
57
- default_config :puppet_config_path do |provisioner|
58
- provisioner.calculate_path('puppet.conf', :file)
59
- end
60
-
61
- default_config :puppet_debug, false
62
- default_config :puppet_verbose, false
63
- default_config :puppet_noop, false
64
- default_config :puppet_platform, ''
65
- default_config :update_package_repos, true
66
-
67
- default_config :custom_facts, {}
68
-
69
- default_config :puppet_detailed_exitcodes, nil
70
- default_config :puppet_logdest, nil
71
- default_config :puppet_masterport, nil
72
- default_config :puppet_test, false
73
- default_config :puppet_onetime, true
74
- default_config :puppet_no_daemonize, true
75
- default_config :puppet_server, nil # will default to 'puppet'
76
- default_config :puppet_waitforcert, '0'
77
- default_config :puppet_certname, nil
78
- default_config :puppet_digest, nil
79
-
80
-
81
- def calculate_path(path, type = :directory)
82
- base = config[:test_base_path]
83
- candidates = []
84
- candidates << File.join(base, instance.suite.name, 'puppet', path)
85
- candidates << File.join(base, instance.suite.name, path)
86
- candidates << File.join(base, path)
87
- candidates << File.join(Dir.pwd, path)
88
-
89
- candidates.find do |c|
90
- type == :directory ? File.directory?(c) : File.file?(c)
91
- end
92
- end
93
-
94
- def install_command
95
- return unless config[:require_puppet_omnibus] or config[:require_puppet_repo]
96
- if config[:require_puppet_omnibus]
97
- info("Installing puppet using puppet omnibus")
98
- version = if !config[:puppet_version].nil?
99
- "-v #{config[:puppet_version]}"
100
- else
101
- ""
102
- end
103
- <<-INSTALL
104
- #{Util.shell_helpers}
105
-
106
- if [ ! -d "#{config[:puppet_omnibus_remote_path]}" ]; then
107
- echo "-----> Installing Puppet Omnibus"
108
- do_download #{config[:puppet_omnibus_url]} /tmp/puppet_install.sh
109
- #{sudo('sh')} /tmp/puppet_install.sh #{version}
110
- fi
111
- #{install_busser}
112
- INSTALL
113
- else
114
- case puppet_platform
115
- when "debian", "ubuntu"
116
- info("Installing puppet on #{puppet_platform}")
117
- <<-INSTALL
118
- if [ ! $(which puppet) ]; then
119
- #{sudo('wget')} #{puppet_apt_repo}
120
- #{sudo('dpkg')} -i #{puppet_apt_repo_file}
121
- #{update_packages_debian_cmd}
122
- #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
123
- #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
124
- fi
125
- #{install_busser}
126
- INSTALL
127
- when "redhat", "centos", "fedora"
128
- info("Installing puppet on #{puppet_platform}")
129
- <<-INSTALL
130
- if [ ! $(which puppet) ]; then
131
- #{sudo('rpm')} -ivh #{puppet_yum_repo}
132
- #{update_packages_redhat_cmd}
133
- #{sudo('yum')} -y install puppet#{puppet_redhat_version}
134
- fi
135
- #{install_busser}
136
- INSTALL
137
- else
138
- info("Installing puppet, will try to determine platform os")
139
- <<-INSTALL
140
- if [ ! $(which puppet) ]; then
141
- if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
142
- #{sudo('rpm')} -ivh #{puppet_yum_repo}
143
- #{update_packages_redhat_cmd}
144
- #{sudo('yum')} -y install puppet#{puppet_redhat_version}
145
- else
146
- #{sudo('wget')} #{puppet_apt_repo}
147
- #{sudo('dpkg')} -i #{puppet_apt_repo_file}
148
- #{update_packages_debian_cmd}
149
- #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
150
- #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
151
- fi
152
- fi
153
- #{install_busser}
154
- INSTALL
155
- end
156
- end
157
- end
158
-
159
- def install_busser
160
- if config[:require_chef_for_busser]
161
- <<-INSTALL
162
- #{Util.shell_helpers}
163
- # install chef omnibus so that busser works as this is needed to run tests :(
164
- # TODO: work out how to install enough ruby
165
- # and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
166
- # whole chef client
167
- if [ ! -d "/opt/chef" ]
168
- then
169
- echo "-----> Installing Chef Omnibus to install busser to run tests"
170
- do_download #{chef_url} /tmp/install.sh
171
- #{sudo('sh')} /tmp/install.sh
172
- fi
173
- INSTALL
174
- end
175
- end
176
-
177
-
178
-
179
- def init_command
180
- end
181
-
182
- def create_sandbox
183
- super
184
- debug("Creating local sandbox in #{sandbox_path}")
185
-
186
- yield if block_given?
187
-
188
- prepare_puppet_config
189
- info('Finished Preparing files for transfer')
190
-
191
- end
192
-
193
- def cleanup_sandbox
194
- return if sandbox_path.nil?
195
- debug("Cleaning up local sandbox in #{sandbox_path}")
196
- FileUtils.rmtree(sandbox_path)
197
- end
198
-
199
- def prepare_command
200
- commands = []
201
-
202
- if puppet_config
203
- commands << [
204
- sudo('cp'),
205
- File.join(config[:root_path], 'puppet.conf'),
206
- '/etc/puppet',
207
- ].join(' ')
208
- end
209
-
210
- command = commands.join(' && ')
211
- debug(command)
212
- command
213
- end
214
-
215
- def run_command
216
- if !config[:puppet_agent_command].nil?
217
- return config[:puppet_agent_command]
218
- else
219
- [
220
- custom_facts,
221
- sudo('puppet'),
222
- 'agent',
223
- puppet_server_flag,
224
- "--waitforcert=#{config[:puppet_waitforcert]}",
225
- puppet_masterport_flag,
226
- puppet_certname_flag,
227
- puppet_digest_flag,
228
- puppet_detailed_exitcodes_flag,
229
- puppet_logdest_flag,
230
- puppet_test_flag,
231
- puppet_onetime_flag,
232
- puppet_no_daemonize_flag,
233
- puppet_noop_flag,
234
- puppet_verbose_flag,
235
- puppet_debug_flag
236
- ].join(" ")
237
- end
238
- end
239
-
240
- protected
241
-
242
- def load_needed_dependencies!
243
- end
244
-
245
- def puppet_config
246
- config[:puppet_config_path]
247
- end
248
-
249
- def puppet_debian_version
250
- config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
251
- end
252
-
253
- def puppet_redhat_version
254
- config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
255
- end
256
-
257
- def puppet_noop_flag
258
- config[:puppet_noop] ? '--noop' : nil
259
- end
260
-
261
- def puppet_debug_flag
262
- config[:puppet_debug] ? '-d' : nil
263
- end
264
-
265
- def puppet_verbose_flag
266
- config[:puppet_verbose] ? '-v' : nil
267
- end
268
-
269
- def puppet_platform
270
- config[:puppet_platform].to_s.downcase
271
- end
272
-
273
- def update_packages_debian_cmd
274
- config[:update_package_repos] ? "#{sudo('apt-get')} update" : nil
275
- end
276
-
277
- def update_packages_redhat_cmd
278
- config[:update_package_repos] ? "#{sudo('yum')} makecache" : nil
279
- end
280
-
281
- def custom_facts
282
- return nil if config[:custom_facts].none?
283
- bash_vars = config[:custom_facts].map { |k,v| "FACTER_#{k}=#{v}" }.join(" ")
284
- bash_vars = "export #{bash_vars};"
285
- debug(bash_vars)
286
- bash_vars
287
- end
288
-
289
- def puppet_server_flag
290
- config[:puppet_server] ? "--server=#{config[:puppet_server]}" : nil
291
- end
292
-
293
- def puppet_masterport_flag
294
- config[:puppet_masterport] ? '--masterport=#{config[:puppet_masterport]}' : nil
295
- end
296
-
297
- def puppet_detailed_exitcodes_flag
298
- config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
299
- end
300
-
301
- def puppet_logdest_flag
302
- config[:puppet_logdest] ? "--logdest=#{config[:puppet_logdest]}" : nil
303
- end
304
-
305
- def puppet_test_flag
306
- config[:puppet_test] ? '--test' : nil
307
- end
308
-
309
- def puppet_onetime_flag
310
- config[:puppet_onetime] ? '--onetime' : nil
311
- end
312
-
313
- def puppet_no_daemonize_flag
314
- config[:puppet_no_daemonize] ? '--no-daemonize' : nil
315
- end
316
-
317
- def puppet_no_daemonize
318
- config[:puppet_no_daemonize]
319
- end
320
-
321
- def puppet_server
322
- config[:puppet_server]
323
- end
324
-
325
- def puppet_certname_flag
326
- config[:puppet_certname] ? "--certname=#{config[:puppet_certname]}" : nil
327
- end
328
-
329
- def puppet_digest_flag
330
- config[:puppet_digest] ? "--digest=#{config[:puppet_digest]}" : nil
331
- end
332
-
333
- def puppet_apt_repo
334
- config[:puppet_apt_repo]
335
- end
336
-
337
- def puppet_apt_repo_file
338
- config[:puppet_apt_repo].split('/').last
339
- end
340
-
341
- def puppet_yum_repo
342
- config[:puppet_yum_repo]
343
- end
344
-
345
- def chef_url
346
- config[:chef_bootstrap_url]
347
- end
348
-
349
- def prepare_puppet_config
350
- return unless puppet_config
351
-
352
- info('Preparing puppet.conf')
353
- debug("Using puppet config from #{puppet_config}")
354
-
355
- FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
356
- end
357
- end
358
- end
359
- end
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Chris Lundquist (<chris.lundquist@github.com>) Neill Turner (<neillwturner@gmail.com>)
4
+ #
5
+ # Copyright (C) 2013,2014 Chris Lundquist, Neill Turner
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ # See https://github.com/neillturner/kitchen-puppet/blob/master/provisioner_options.md
20
+ # for documentation configuration parameters with puppet_agent provisioner.
21
+ #
22
+
23
+ require 'json'
24
+ require 'kitchen/provisioner/base'
25
+ require 'kitchen/provisioner/puppet/librarian'
26
+
27
+ module Kitchen
28
+
29
+ class Busser
30
+
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_omnibus_remote_path, '/opt/puppet'
47
+ default_config :puppet_version, nil
48
+ default_config :require_puppet_repo, true
49
+ default_config :require_chef_for_busser, true
50
+
51
+ default_config :puppet_apt_repo, "http://apt.puppetlabs.com/puppetlabs-release-precise.deb"
52
+ default_config :puppet_yum_repo, "https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm"
53
+ default_config :chef_bootstrap_url, "https://www.getchef.com/chef/install.sh"
54
+
55
+ default_config :puppet_agent_command, nil
56
+
57
+ default_config :puppet_config_path do |provisioner|
58
+ provisioner.calculate_path('puppet.conf', :file)
59
+ end
60
+
61
+ default_config :puppet_debug, false
62
+ default_config :puppet_verbose, false
63
+ default_config :puppet_noop, false
64
+ default_config :puppet_platform, ''
65
+ default_config :update_package_repos, true
66
+
67
+ default_config :custom_facts, {}
68
+
69
+ default_config :puppet_detailed_exitcodes, nil
70
+ default_config :puppet_logdest, nil
71
+ default_config :puppet_masterport, nil
72
+ default_config :puppet_test, false
73
+ default_config :puppet_onetime, true
74
+ default_config :puppet_no_daemonize, true
75
+ default_config :puppet_server, nil # will default to 'puppet'
76
+ default_config :puppet_waitforcert, '0'
77
+ default_config :puppet_certname, nil
78
+ default_config :puppet_digest, nil
79
+
80
+
81
+ def calculate_path(path, type = :directory)
82
+ base = config[:test_base_path]
83
+ candidates = []
84
+ candidates << File.join(base, instance.suite.name, 'puppet', path)
85
+ candidates << File.join(base, instance.suite.name, path)
86
+ candidates << File.join(base, path)
87
+ candidates << File.join(Dir.pwd, path)
88
+
89
+ candidates.find do |c|
90
+ type == :directory ? File.directory?(c) : File.file?(c)
91
+ end
92
+ end
93
+
94
+ def install_command
95
+ return unless config[:require_puppet_omnibus] or config[:require_puppet_repo]
96
+ if config[:require_puppet_omnibus]
97
+ info("Installing puppet using puppet omnibus")
98
+ version = if !config[:puppet_version].nil?
99
+ "-v #{config[:puppet_version]}"
100
+ else
101
+ ""
102
+ end
103
+ <<-INSTALL
104
+ #{Util.shell_helpers}
105
+
106
+ if [ ! -d "#{config[:puppet_omnibus_remote_path]}" ]; then
107
+ echo "-----> Installing Puppet Omnibus"
108
+ do_download #{config[:puppet_omnibus_url]} /tmp/puppet_install.sh
109
+ #{sudo('sh')} /tmp/puppet_install.sh #{version}
110
+ fi
111
+ #{install_busser}
112
+ INSTALL
113
+ else
114
+ case puppet_platform
115
+ when "debian", "ubuntu"
116
+ info("Installing puppet on #{puppet_platform}")
117
+ <<-INSTALL
118
+ if [ ! $(which puppet) ]; then
119
+ #{sudo('wget')} #{puppet_apt_repo}
120
+ #{sudo('dpkg')} -i #{puppet_apt_repo_file}
121
+ #{update_packages_debian_cmd}
122
+ #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
123
+ #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
124
+ fi
125
+ #{install_busser}
126
+ INSTALL
127
+ when "redhat", "centos", "fedora"
128
+ info("Installing puppet on #{puppet_platform}")
129
+ <<-INSTALL
130
+ if [ ! $(which puppet) ]; then
131
+ #{sudo('rpm')} -ivh #{puppet_yum_repo}
132
+ #{update_packages_redhat_cmd}
133
+ #{sudo('yum')} -y install puppet#{puppet_redhat_version}
134
+ fi
135
+ #{install_busser}
136
+ INSTALL
137
+ else
138
+ info("Installing puppet, will try to determine platform os")
139
+ <<-INSTALL
140
+ if [ ! $(which puppet) ]; then
141
+ if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
142
+ #{sudo('rpm')} -ivh #{puppet_yum_repo}
143
+ #{update_packages_redhat_cmd}
144
+ #{sudo('yum')} -y install puppet#{puppet_redhat_version}
145
+ else
146
+ if [ -f /etc/system-release ] || grep -q 'Amazon Linux' /etc/system-release; then
147
+ #{sudo('rpm')} -ivh #{puppet_yum_repo}
148
+ #{update_packages_redhat_cmd}
149
+ #{sudo('yum')} -y install puppet#{puppet_redhat_version}
150
+ else
151
+ #{sudo('wget')} #{puppet_apt_repo}
152
+ #{sudo('dpkg')} -i #{puppet_apt_repo_file}
153
+ #{update_packages_debian_cmd}
154
+ #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
155
+ #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
156
+ fi
157
+ fi
158
+ fi
159
+ #{install_busser}
160
+ INSTALL
161
+ end
162
+ end
163
+ end
164
+
165
+ def install_busser
166
+ if config[:require_chef_for_busser]
167
+ <<-INSTALL
168
+ #{Util.shell_helpers}
169
+ # install chef omnibus so that busser works as this is needed to run tests :(
170
+ # TODO: work out how to install enough ruby
171
+ # and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
172
+ # whole chef client
173
+ if [ ! -d "/opt/chef" ]
174
+ then
175
+ echo "-----> Installing Chef Omnibus to install busser to run tests"
176
+ do_download #{chef_url} /tmp/install.sh
177
+ #{sudo('sh')} /tmp/install.sh
178
+ fi
179
+ INSTALL
180
+ end
181
+ end
182
+
183
+
184
+
185
+ def init_command
186
+ end
187
+
188
+ def create_sandbox
189
+ super
190
+ debug("Creating local sandbox in #{sandbox_path}")
191
+
192
+ yield if block_given?
193
+
194
+ prepare_puppet_config
195
+ info('Finished Preparing files for transfer')
196
+
197
+ end
198
+
199
+ def cleanup_sandbox
200
+ return if sandbox_path.nil?
201
+ debug("Cleaning up local sandbox in #{sandbox_path}")
202
+ FileUtils.rmtree(sandbox_path)
203
+ end
204
+
205
+ def prepare_command
206
+ commands = []
207
+
208
+ if puppet_config
209
+ commands << [
210
+ sudo('cp'),
211
+ File.join(config[:root_path], 'puppet.conf'),
212
+ '/etc/puppet',
213
+ ].join(' ')
214
+ end
215
+
216
+ command = commands.join(' && ')
217
+ debug(command)
218
+ command
219
+ end
220
+
221
+ def run_command
222
+ if !config[:puppet_agent_command].nil?
223
+ return config[:puppet_agent_command]
224
+ else
225
+ [
226
+ custom_facts,
227
+ sudo('puppet'),
228
+ 'agent',
229
+ puppet_server_flag,
230
+ "--waitforcert=#{config[:puppet_waitforcert]}",
231
+ puppet_masterport_flag,
232
+ puppet_certname_flag,
233
+ puppet_digest_flag,
234
+ puppet_detailed_exitcodes_flag,
235
+ puppet_logdest_flag,
236
+ puppet_test_flag,
237
+ puppet_onetime_flag,
238
+ puppet_no_daemonize_flag,
239
+ puppet_noop_flag,
240
+ puppet_verbose_flag,
241
+ puppet_debug_flag
242
+ ].join(" ")
243
+ end
244
+ end
245
+
246
+ protected
247
+
248
+ def load_needed_dependencies!
249
+ end
250
+
251
+ def puppet_config
252
+ config[:puppet_config_path]
253
+ end
254
+
255
+ def puppet_debian_version
256
+ config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
257
+ end
258
+
259
+ def puppet_redhat_version
260
+ config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
261
+ end
262
+
263
+ def puppet_noop_flag
264
+ config[:puppet_noop] ? '--noop' : nil
265
+ end
266
+
267
+ def puppet_debug_flag
268
+ config[:puppet_debug] ? '-d' : nil
269
+ end
270
+
271
+ def puppet_verbose_flag
272
+ config[:puppet_verbose] ? '-v' : nil
273
+ end
274
+
275
+ def puppet_platform
276
+ config[:puppet_platform].to_s.downcase
277
+ end
278
+
279
+ def update_packages_debian_cmd
280
+ config[:update_package_repos] ? "#{sudo('apt-get')} update" : nil
281
+ end
282
+
283
+ def update_packages_redhat_cmd
284
+ config[:update_package_repos] ? "#{sudo('yum')} makecache" : nil
285
+ end
286
+
287
+ def custom_facts
288
+ return nil if config[:custom_facts].none?
289
+ bash_vars = config[:custom_facts].map { |k,v| "FACTER_#{k}=#{v}" }.join(" ")
290
+ bash_vars = "export #{bash_vars};"
291
+ debug(bash_vars)
292
+ bash_vars
293
+ end
294
+
295
+ def puppet_server_flag
296
+ config[:puppet_server] ? "--server=#{config[:puppet_server]}" : nil
297
+ end
298
+
299
+ def puppet_masterport_flag
300
+ config[:puppet_masterport] ? '--masterport=#{config[:puppet_masterport]}' : nil
301
+ end
302
+
303
+ def puppet_detailed_exitcodes_flag
304
+ config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
305
+ end
306
+
307
+ def puppet_logdest_flag
308
+ config[:puppet_logdest] ? "--logdest=#{config[:puppet_logdest]}" : nil
309
+ end
310
+
311
+ def puppet_test_flag
312
+ config[:puppet_test] ? '--test' : nil
313
+ end
314
+
315
+ def puppet_onetime_flag
316
+ config[:puppet_onetime] ? '--onetime' : nil
317
+ end
318
+
319
+ def puppet_no_daemonize_flag
320
+ config[:puppet_no_daemonize] ? '--no-daemonize' : nil
321
+ end
322
+
323
+ def puppet_no_daemonize
324
+ config[:puppet_no_daemonize]
325
+ end
326
+
327
+ def puppet_server
328
+ config[:puppet_server]
329
+ end
330
+
331
+ def puppet_certname_flag
332
+ config[:puppet_certname] ? "--certname=#{config[:puppet_certname]}" : nil
333
+ end
334
+
335
+ def puppet_digest_flag
336
+ config[:puppet_digest] ? "--digest=#{config[:puppet_digest]}" : nil
337
+ end
338
+
339
+ def puppet_apt_repo
340
+ config[:puppet_apt_repo]
341
+ end
342
+
343
+ def puppet_apt_repo_file
344
+ config[:puppet_apt_repo].split('/').last
345
+ end
346
+
347
+ def puppet_yum_repo
348
+ config[:puppet_yum_repo]
349
+ end
350
+
351
+ def chef_url
352
+ config[:chef_bootstrap_url]
353
+ end
354
+
355
+ def prepare_puppet_config
356
+ return unless puppet_config
357
+
358
+ info('Preparing puppet.conf')
359
+ debug("Using puppet config from #{puppet_config}")
360
+
361
+ FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
362
+ end
363
+ end
364
+ end
365
+ end
@@ -78,7 +78,7 @@ module Kitchen
78
78
  default_config :hiera_data_path do |provisioner|
79
79
  provisioner.calculate_path('hiera')
80
80
  end
81
-
81
+
82
82
  default_config :puppet_config_path do |provisioner|
83
83
  provisioner.calculate_path('puppet.conf', :file)
84
84
  end
@@ -115,6 +115,14 @@ module Kitchen
115
115
  default_config :update_package_repos, true
116
116
  default_config :remove_puppet_repo, false
117
117
  default_config :custom_facts, {}
118
+ default_config :librarian_puppet_ssl_file, nil
119
+
120
+ default_config :hiera_eyaml, false
121
+ default_config :hiera_eyaml_key_remote_path, '/etc/puppet/secure/keys'
122
+
123
+ default_config :hiera_eyaml_key_path do |provisioner|
124
+ provisioner.calculate_path('hiera_keys')
125
+ end
118
126
 
119
127
  def calculate_path(path, type = :directory)
120
128
  base = config[:test_base_path]
@@ -181,18 +189,37 @@ module Kitchen
181
189
  #{update_packages_redhat_cmd}
182
190
  #{sudo('yum')} -y install puppet#{puppet_redhat_version}
183
191
  else
184
- #{sudo('wget')} #{puppet_apt_repo}
185
- #{sudo('dpkg')} -i #{puppet_apt_repo_file}
186
- #{update_packages_debian_cmd}
187
- #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
188
- #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
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
189
203
  fi
190
204
  fi
205
+ #{install_eyaml}
191
206
  #{install_busser}
192
207
  INSTALL
193
208
  end
194
209
  end
195
210
  end
211
+
212
+ def install_eyaml
213
+ if config[:hiera_eyaml]
214
+ <<-INSTALL
215
+ # A backend for Hiera that provides per-value asymmetric encryption of sensitive data
216
+ if [[ $(#{sudo('gem')} list hiera-eyaml -i) == 'false' ]]; then
217
+ echo "-----> Installing hiera-eyaml to provide encryption of hiera data"
218
+ #{sudo('gem')} install --no-ri --no-rdoc hiera-eyaml
219
+ fi
220
+ INSTALL
221
+ end
222
+ end
196
223
 
197
224
  def install_busser
198
225
  if config[:require_chef_for_busser]
@@ -216,7 +243,7 @@ module Kitchen
216
243
 
217
244
  def init_command
218
245
  dirs = %w{modules manifests files hiera hiera.yaml}.
219
- map { |dir| File.join(config[:root_path], dir) }.join(" ")
246
+ map { |dir| File.join(config[:root_path], dir) }.join(" ")
220
247
  cmd = "#{sudo('rm')} -rf #{dirs} #{hiera_data_remote_path} /etc/hiera.yaml /etc/puppet/hiera.yaml /etc/puppet/fileserver.conf;"
221
248
  cmd = cmd+" mkdir -p #{config[:root_path]}"
222
249
  debug(cmd)
@@ -285,11 +312,20 @@ module Kitchen
285
312
  commands << [
286
313
  sudo('mkdir -p'), hiera_data_remote_path
287
314
  ].join(' ')
288
- commands << [
315
+ commands << [
289
316
  sudo('cp -r'), File.join(config[:root_path], 'hiera/*'), hiera_data_remote_path
290
317
  ].join(' ')
291
318
  end
292
319
 
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
328
+
293
329
  command = commands.join(' && ')
294
330
  debug(command)
295
331
  command
@@ -380,6 +416,22 @@ module Kitchen
380
416
  def hiera_data_remote_path
381
417
  config[:hiera_data_remote_path]
382
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
383
435
 
384
436
  def puppet_debian_version
385
437
  config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
@@ -431,8 +483,8 @@ module Kitchen
431
483
 
432
484
  def remove_repo
433
485
  if remove_puppet_repo
434
- '; rm -rf /tmp/kitchen'
435
- else
486
+ "; #{sudo('rm')} -rf /tmp/kitchen #{hiera_data_remote_path} #{hiera_eyaml_key_remote_path} /etc/puppet/* "
487
+ else
436
488
  nil
437
489
  end
438
490
  end
@@ -482,7 +534,7 @@ module Kitchen
482
534
 
483
535
  FileUtils.mkdir_p(tmpmodules_dir)
484
536
 
485
- resolve_with_librarian if File.exists?(puppetfile) and config[:resolve_with_librarian_puppet]
537
+ resolve_with_librarian if File.exists?(puppetfile) and config[:resolve_with_librarian_puppet]
486
538
 
487
539
  if modules && File.directory?(modules)
488
540
  debug("Copying modules from #{modules} to #{tmpmodules_dir}")
@@ -549,16 +601,22 @@ module Kitchen
549
601
  def prepare_hiera_data
550
602
  return unless hiera_data
551
603
  info('Preparing hiera data')
552
-
553
- tmp_hiera_dir = File.join(sandbox_path, 'hiera')
554
- debug("Copying hiera data from #{hiera_data} to #{tmp_hiera_dir}")
604
+ tmp_hiera_dir = File.join(sandbox_path, 'hiera')
605
+ debug("Copying hiera data from #{hiera_data} to #{tmp_hiera_dir}")
555
606
  FileUtils.mkdir_p(tmp_hiera_dir)
556
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)
557
613
  end
558
614
 
559
615
  def resolve_with_librarian
560
616
  Kitchen.mutex.synchronize do
617
+ ENV["SSL_CERT_FILE"]=librarian_puppet_ssl_file if librarian_puppet_ssl_file
561
618
  Puppet::Librarian.new(puppetfile, tmpmodules_dir, logger).resolve
619
+ ENV["SSL_CERT_FILE"]='' if librarian_puppet_ssl_file
562
620
  end
563
621
  end
564
622
  end
@@ -29,9 +29,13 @@ puppetfile_path | | Path to Puppetfile
29
29
  puppet_apply_command | nil | Overwrite the puppet apply command. Needs "sudo -E puppet apply" as a prefix.
30
30
  require_chef_for_busser | true | Install chef as currently needed by busser to run tests
31
31
  resolve_with_librarian_puppet | true | Use librarian_puppet to resolve modules if a Puppetfile is found
32
+ librarian_puppet_ssl_file | nil | ssl certificate file for librarian-puppet
32
33
  puppet_config_path | | path of custom puppet.conf file
33
34
  puppet_environment | nil | puppet environment for running puppet apply
34
- remove_puppet_repo | false | remove copy of puppet repository on server after running puppet
35
+ remove_puppet_repo | false | remove copy of puppet repository and puppet configuration on server after running puppet
36
+ hiera_eyaml | false | use hiera-eyaml to encrypt hiera data
37
+ hiera_eyaml_key_remote_path | "/etc/puppet/secure/keys" | directory of hiera-eyaml keys on server
38
+ hiera_eyaml_key_path | "hiera_keys" | directory of hiera-eyaml keys on workstation
35
39
 
36
40
  ## Puppet Apply Configuring Provisioner Options
37
41
 
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.15
4
+ version: 0.0.16
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-10 00:00:00.000000000 Z
12
+ date: 2014-10-17 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! '== DESCRIPTION:
15
15
 
@@ -20,7 +20,7 @@ description: ! '== DESCRIPTION:
20
20
  == FEATURES:
21
21
 
22
22
 
23
- Supports puppet apply, hiera and custom facts
23
+ Supports puppet apply, puppet agent, hiera, hiera-eyaml, custom facts, librarian-puppet
24
24
 
25
25
 
26
26
  '