kitchen-puppet 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/kitchen-puppet.gemspec +29 -29
- data/lib/kitchen/provisioner/puppet/librarian.rb +78 -83
- data/lib/kitchen/provisioner/puppet_agent.rb +218 -223
- data/lib/kitchen/provisioner/puppet_apply.rb +393 -390
- data/lib/kitchen/provisioner/puppet_apply_spec.rb +33 -33
- data/lib/kitchen-puppet/version.rb +7 -5
- data/provisioner_options.md +160 -159
- metadata +2 -2
@@ -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
|
30
|
+
%w(data data_bags environments nodes roles puppet)
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
@@ -39,23 +37,23 @@ module Kitchen
|
|
39
37
|
#
|
40
38
|
class PuppetAgent < Base
|
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
|
48
46
|
default_config :require_puppet_repo, true
|
49
47
|
default_config :require_chef_for_busser, true
|
50
|
-
|
51
|
-
default_config :puppet_apt_repo,
|
52
|
-
default_config :puppet_yum_repo,
|
53
|
-
default_config :chef_bootstrap_url,
|
48
|
+
|
49
|
+
default_config :puppet_apt_repo, 'http://apt.puppetlabs.com/puppetlabs-release-precise.deb'
|
50
|
+
default_config :puppet_yum_repo, 'https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm'
|
51
|
+
default_config :chef_bootstrap_url, 'https://www.getchef.com/chef/install.sh'
|
54
52
|
|
55
53
|
default_config :puppet_agent_command, nil
|
56
54
|
|
57
55
|
default_config :puppet_config_path do |provisioner|
|
58
|
-
|
56
|
+
provisioner.calculate_path('puppet.conf', :file)
|
59
57
|
end
|
60
58
|
|
61
59
|
default_config :puppet_debug, false
|
@@ -65,7 +63,7 @@ module Kitchen
|
|
65
63
|
default_config :update_package_repos, true
|
66
64
|
|
67
65
|
default_config :custom_facts, {}
|
68
|
-
|
66
|
+
|
69
67
|
default_config :puppet_detailed_exitcodes, nil
|
70
68
|
default_config :puppet_logdest, nil
|
71
69
|
default_config :puppet_masterport, nil
|
@@ -76,8 +74,7 @@ module Kitchen
|
|
76
74
|
default_config :puppet_waitforcert, '0'
|
77
75
|
default_config :puppet_certname, nil
|
78
76
|
default_config :puppet_digest, nil
|
79
|
-
|
80
|
-
|
77
|
+
|
81
78
|
def calculate_path(path, type = :directory)
|
82
79
|
base = config[:test_base_path]
|
83
80
|
candidates = []
|
@@ -91,80 +88,82 @@ module Kitchen
|
|
91
88
|
end
|
92
89
|
end
|
93
90
|
|
91
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
94
92
|
def install_command
|
95
|
-
return unless config[:require_puppet_omnibus]
|
93
|
+
return unless config[:require_puppet_omnibus] || config[:require_puppet_repo]
|
96
94
|
if config[:require_puppet_omnibus]
|
97
|
-
info(
|
98
|
-
|
99
|
-
"-v #{config[:puppet_version]}"
|
95
|
+
info('Installing puppet using puppet omnibus')
|
96
|
+
if !config[:puppet_version].nil?
|
97
|
+
version = "-v #{config[:puppet_version]}"
|
100
98
|
else
|
101
|
-
|
99
|
+
version = ''
|
102
100
|
end
|
103
101
|
<<-INSTALL
|
104
|
-
|
102
|
+
#{Util.shell_helpers}
|
105
103
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
104
|
+
if [ ! -d "#{config[:puppet_omnibus_remote_path]}" ]; then
|
105
|
+
echo "-----> Installing Puppet Omnibus"
|
106
|
+
do_download #{config[:puppet_omnibus_url]} /tmp/puppet_install.sh
|
107
|
+
#{sudo('sh')} /tmp/puppet_install.sh #{version}
|
108
|
+
fi
|
109
|
+
#{install_busser}
|
112
110
|
INSTALL
|
113
111
|
else
|
114
112
|
case puppet_platform
|
115
|
-
when
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
113
|
+
when 'debian', 'ubuntu'
|
114
|
+
info("Installing puppet on #{puppet_platform}")
|
115
|
+
<<-INSTALL
|
116
|
+
if [ ! $(which puppet) ]; then
|
117
|
+
#{sudo('wget')} #{puppet_apt_repo}
|
118
|
+
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
119
|
+
#{update_packages_debian_cmd}
|
120
|
+
#{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
|
121
|
+
#{sudo('apt-get')} -y install puppet#{puppet_debian_version}
|
122
|
+
fi
|
123
|
+
#{install_busser}
|
124
|
+
INSTALL
|
125
|
+
when 'redhat', 'centos', 'fedora'
|
126
|
+
info("Installing puppet on #{puppet_platform}")
|
127
|
+
<<-INSTALL
|
128
|
+
if [ ! $(which puppet) ]; then
|
129
|
+
#{sudo('rpm')} -ivh #{puppet_yum_repo}
|
130
|
+
#{update_packages_redhat_cmd}
|
131
|
+
#{sudo('yum')} -y install puppet#{puppet_redhat_version}
|
132
|
+
fi
|
133
|
+
#{install_busser}
|
134
|
+
INSTALL
|
135
|
+
else
|
136
|
+
info('Installing puppet, will try to determine platform os')
|
137
|
+
<<-INSTALL
|
138
|
+
if [ ! $(which puppet) ]; then
|
139
|
+
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
|
147
140
|
#{sudo('rpm')} -ivh #{puppet_yum_repo}
|
148
141
|
#{update_packages_redhat_cmd}
|
149
|
-
#{sudo('yum')} -y install puppet#{puppet_redhat_version}
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
142
|
+
#{sudo('yum')} -y install puppet#{puppet_redhat_version}
|
143
|
+
else
|
144
|
+
if [ -f /etc/system-release ] || grep -q 'Amazon Linux' /etc/system-release; then
|
145
|
+
#{sudo('rpm')} -ivh #{puppet_yum_repo}
|
146
|
+
#{update_packages_redhat_cmd}
|
147
|
+
#{sudo('yum')} -y install puppet#{puppet_redhat_version}
|
148
|
+
else
|
149
|
+
#{sudo('wget')} #{puppet_apt_repo}
|
150
|
+
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
151
|
+
#{update_packages_debian_cmd}
|
152
|
+
#{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
|
153
|
+
#{sudo('apt-get')} -y install puppet#{puppet_debian_version}
|
154
|
+
fi
|
155
|
+
fi
|
156
|
+
fi
|
157
|
+
#{install_busser}
|
158
|
+
INSTALL
|
159
|
+
end
|
162
160
|
end
|
163
161
|
end
|
162
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
164
163
|
|
165
164
|
def install_busser
|
166
|
-
|
167
|
-
|
165
|
+
return unless config[:require_chef_for_busser]
|
166
|
+
<<-INSTALL
|
168
167
|
#{Util.shell_helpers}
|
169
168
|
# install chef omnibus so that busser works as this is needed to run tests :(
|
170
169
|
# TODO: work out how to install enough ruby
|
@@ -176,190 +175,186 @@ module Kitchen
|
|
176
175
|
do_download #{chef_url} /tmp/install.sh
|
177
176
|
#{sudo('sh')} /tmp/install.sh
|
178
177
|
fi
|
179
|
-
|
180
|
-
|
181
|
-
end
|
182
|
-
|
183
|
-
|
178
|
+
INSTALL
|
179
|
+
end
|
184
180
|
|
185
|
-
|
186
|
-
|
181
|
+
def init_command
|
182
|
+
end
|
187
183
|
|
188
|
-
|
189
|
-
|
190
|
-
|
184
|
+
def create_sandbox
|
185
|
+
super
|
186
|
+
debug("Creating local sandbox in #{sandbox_path}")
|
191
187
|
|
192
|
-
|
188
|
+
yield if block_given?
|
193
189
|
|
194
|
-
|
195
|
-
|
190
|
+
prepare_puppet_config
|
191
|
+
info('Finished Preparing files for transfer')
|
192
|
+
end
|
196
193
|
|
197
|
-
|
194
|
+
def cleanup_sandbox
|
195
|
+
return if sandbox_path.nil?
|
196
|
+
debug("Cleaning up local sandbox in #{sandbox_path}")
|
197
|
+
FileUtils.rmtree(sandbox_path)
|
198
|
+
end
|
198
199
|
|
199
|
-
|
200
|
-
|
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
|
200
|
+
def prepare_command
|
201
|
+
commands = []
|
215
202
|
|
216
|
-
|
217
|
-
|
218
|
-
|
203
|
+
if puppet_config
|
204
|
+
commands << [
|
205
|
+
sudo('cp'),
|
206
|
+
File.join(config[:root_path], 'puppet.conf'),
|
207
|
+
'/etc/puppet'
|
208
|
+
].join(' ')
|
219
209
|
end
|
220
210
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
211
|
+
command = commands.join(' && ')
|
212
|
+
debug(command)
|
213
|
+
command
|
214
|
+
end
|
215
|
+
|
216
|
+
def run_command
|
217
|
+
if !config[:puppet_agent_command].nil?
|
218
|
+
return config[:puppet_agent_command]
|
219
|
+
else
|
220
|
+
[
|
221
|
+
custom_facts,
|
222
|
+
sudo('puppet'),
|
223
|
+
'agent',
|
224
|
+
puppet_server_flag,
|
225
|
+
"--waitforcert=#{config[:puppet_waitforcert]}",
|
226
|
+
puppet_masterport_flag,
|
227
|
+
puppet_certname_flag,
|
228
|
+
puppet_digest_flag,
|
229
|
+
puppet_detailed_exitcodes_flag,
|
230
|
+
puppet_logdest_flag,
|
231
|
+
puppet_test_flag,
|
232
|
+
puppet_onetime_flag,
|
233
|
+
puppet_no_daemonize_flag,
|
234
|
+
puppet_noop_flag,
|
235
|
+
puppet_verbose_flag,
|
236
|
+
puppet_debug_flag
|
237
|
+
].join(' ')
|
244
238
|
end
|
239
|
+
end
|
245
240
|
|
246
|
-
|
241
|
+
protected
|
247
242
|
|
248
|
-
|
249
|
-
|
243
|
+
def load_needed_dependencies!
|
244
|
+
end
|
250
245
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
def puppet_debian_version
|
256
|
-
config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
|
257
|
-
end
|
246
|
+
def puppet_config
|
247
|
+
config[:puppet_config_path]
|
248
|
+
end
|
258
249
|
|
259
|
-
|
260
|
-
|
261
|
-
|
250
|
+
def puppet_debian_version
|
251
|
+
config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
|
252
|
+
end
|
262
253
|
|
263
|
-
|
264
|
-
|
265
|
-
|
254
|
+
def puppet_redhat_version
|
255
|
+
config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
|
256
|
+
end
|
266
257
|
|
267
|
-
|
268
|
-
|
269
|
-
|
258
|
+
def puppet_noop_flag
|
259
|
+
config[:puppet_noop] ? '--noop' : nil
|
260
|
+
end
|
270
261
|
|
271
|
-
|
272
|
-
|
273
|
-
|
262
|
+
def puppet_debug_flag
|
263
|
+
config[:puppet_debug] ? '-d' : nil
|
264
|
+
end
|
274
265
|
|
275
|
-
|
276
|
-
|
277
|
-
|
266
|
+
def puppet_verbose_flag
|
267
|
+
config[:puppet_verbose] ? '-v' : nil
|
268
|
+
end
|
278
269
|
|
279
|
-
|
280
|
-
|
281
|
-
|
270
|
+
def puppet_platform
|
271
|
+
config[:puppet_platform].to_s.downcase
|
272
|
+
end
|
282
273
|
|
283
|
-
|
284
|
-
|
285
|
-
|
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
|
274
|
+
def update_packages_debian_cmd
|
275
|
+
config[:update_package_repos] ? "#{sudo('apt-get')} update" : nil
|
276
|
+
end
|
294
277
|
|
295
|
-
|
296
|
-
|
297
|
-
|
278
|
+
def update_packages_redhat_cmd
|
279
|
+
config[:update_package_repos] ? "#{sudo('yum')} makecache" : nil
|
280
|
+
end
|
298
281
|
|
299
|
-
|
300
|
-
|
301
|
-
|
282
|
+
def custom_facts
|
283
|
+
return nil if config[:custom_facts].none?
|
284
|
+
bash_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
|
285
|
+
bash_vars = "export #{bash_vars};"
|
286
|
+
debug(bash_vars)
|
287
|
+
bash_vars
|
288
|
+
end
|
302
289
|
|
303
|
-
|
304
|
-
|
305
|
-
|
290
|
+
def puppet_server_flag
|
291
|
+
config[:puppet_server] ? "--server=#{config[:puppet_server]}" : nil
|
292
|
+
end
|
306
293
|
|
307
|
-
|
308
|
-
|
309
|
-
|
294
|
+
def puppet_masterport_flag
|
295
|
+
config[:puppet_masterport] ? '--masterport=#{config[:puppet_masterport]}' : nil
|
296
|
+
end
|
310
297
|
|
311
|
-
|
312
|
-
|
313
|
-
|
298
|
+
def puppet_detailed_exitcodes_flag
|
299
|
+
config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
|
300
|
+
end
|
314
301
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
def puppet_no_daemonize_flag
|
320
|
-
config[:puppet_no_daemonize] ? '--no-daemonize' : nil
|
321
|
-
end
|
302
|
+
def puppet_logdest_flag
|
303
|
+
config[:puppet_logdest] ? "--logdest=#{config[:puppet_logdest]}" : nil
|
304
|
+
end
|
322
305
|
|
323
|
-
|
324
|
-
|
325
|
-
|
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
|
306
|
+
def puppet_test_flag
|
307
|
+
config[:puppet_test] ? '--test' : nil
|
308
|
+
end
|
342
309
|
|
343
|
-
|
344
|
-
|
345
|
-
|
310
|
+
def puppet_onetime_flag
|
311
|
+
config[:puppet_onetime] ? '--onetime' : nil
|
312
|
+
end
|
346
313
|
|
347
|
-
|
348
|
-
|
349
|
-
|
314
|
+
def puppet_no_daemonize_flag
|
315
|
+
config[:puppet_no_daemonize] ? '--no-daemonize' : nil
|
316
|
+
end
|
350
317
|
|
351
|
-
|
352
|
-
|
353
|
-
|
318
|
+
def puppet_no_daemonize
|
319
|
+
config[:puppet_no_daemonize]
|
320
|
+
end
|
354
321
|
|
355
|
-
|
356
|
-
|
322
|
+
def puppet_server
|
323
|
+
config[:puppet_server]
|
324
|
+
end
|
357
325
|
|
358
|
-
|
359
|
-
|
326
|
+
def puppet_certname_flag
|
327
|
+
config[:puppet_certname] ? "--certname=#{config[:puppet_certname]}" : nil
|
328
|
+
end
|
360
329
|
|
361
|
-
|
362
|
-
|
330
|
+
def puppet_digest_flag
|
331
|
+
config[:puppet_digest] ? "--digest=#{config[:puppet_digest]}" : nil
|
332
|
+
end
|
333
|
+
|
334
|
+
def puppet_apt_repo
|
335
|
+
config[:puppet_apt_repo]
|
336
|
+
end
|
337
|
+
|
338
|
+
def puppet_apt_repo_file
|
339
|
+
config[:puppet_apt_repo].split('/').last
|
340
|
+
end
|
341
|
+
|
342
|
+
def puppet_yum_repo
|
343
|
+
config[:puppet_yum_repo]
|
344
|
+
end
|
345
|
+
|
346
|
+
def chef_url
|
347
|
+
config[:chef_bootstrap_url]
|
348
|
+
end
|
349
|
+
|
350
|
+
def prepare_puppet_config
|
351
|
+
return unless puppet_config
|
352
|
+
|
353
|
+
info('Preparing puppet.conf')
|
354
|
+
debug("Using puppet config from #{puppet_config}")
|
355
|
+
|
356
|
+
FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
|
357
|
+
end
|
363
358
|
end
|
364
359
|
end
|
365
360
|
end
|