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.
@@ -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
 
@@ -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, "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"
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
- provisioner.calculate_path('puppet.conf', :file)
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] or config[:require_puppet_repo]
93
+ return unless config[:require_puppet_omnibus] || config[:require_puppet_repo]
96
94
  if config[:require_puppet_omnibus]
97
- info("Installing puppet using puppet omnibus")
98
- version = if !config[:puppet_version].nil?
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
- #{Util.shell_helpers}
102
+ #{Util.shell_helpers}
105
103
 
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}
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 "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
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
- 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
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
- if config[:require_chef_for_busser]
167
- <<-INSTALL
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
- INSTALL
180
- end
181
- end
182
-
183
-
178
+ INSTALL
179
+ end
184
180
 
185
- def init_command
186
- end
181
+ def init_command
182
+ end
187
183
 
188
- def create_sandbox
189
- super
190
- debug("Creating local sandbox in #{sandbox_path}")
184
+ def create_sandbox
185
+ super
186
+ debug("Creating local sandbox in #{sandbox_path}")
191
187
 
192
- yield if block_given?
188
+ yield if block_given?
193
189
 
194
- prepare_puppet_config
195
- info('Finished Preparing files for transfer')
190
+ prepare_puppet_config
191
+ info('Finished Preparing files for transfer')
192
+ end
196
193
 
197
- end
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
- 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
200
+ def prepare_command
201
+ commands = []
215
202
 
216
- command = commands.join(' && ')
217
- debug(command)
218
- command
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
- 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
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
- protected
241
+ protected
247
242
 
248
- def load_needed_dependencies!
249
- end
243
+ def load_needed_dependencies!
244
+ end
250
245
 
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
246
+ def puppet_config
247
+ config[:puppet_config_path]
248
+ end
258
249
 
259
- def puppet_redhat_version
260
- config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
261
- end
250
+ def puppet_debian_version
251
+ config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
252
+ end
262
253
 
263
- def puppet_noop_flag
264
- config[:puppet_noop] ? '--noop' : nil
265
- end
254
+ def puppet_redhat_version
255
+ config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
256
+ end
266
257
 
267
- def puppet_debug_flag
268
- config[:puppet_debug] ? '-d' : nil
269
- end
258
+ def puppet_noop_flag
259
+ config[:puppet_noop] ? '--noop' : nil
260
+ end
270
261
 
271
- def puppet_verbose_flag
272
- config[:puppet_verbose] ? '-v' : nil
273
- end
262
+ def puppet_debug_flag
263
+ config[:puppet_debug] ? '-d' : nil
264
+ end
274
265
 
275
- def puppet_platform
276
- config[:puppet_platform].to_s.downcase
277
- end
266
+ def puppet_verbose_flag
267
+ config[:puppet_verbose] ? '-v' : nil
268
+ end
278
269
 
279
- def update_packages_debian_cmd
280
- config[:update_package_repos] ? "#{sudo('apt-get')} update" : nil
281
- end
270
+ def puppet_platform
271
+ config[:puppet_platform].to_s.downcase
272
+ end
282
273
 
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
274
+ def update_packages_debian_cmd
275
+ config[:update_package_repos] ? "#{sudo('apt-get')} update" : nil
276
+ end
294
277
 
295
- def puppet_server_flag
296
- config[:puppet_server] ? "--server=#{config[:puppet_server]}" : nil
297
- end
278
+ def update_packages_redhat_cmd
279
+ config[:update_package_repos] ? "#{sudo('yum')} makecache" : nil
280
+ end
298
281
 
299
- def puppet_masterport_flag
300
- config[:puppet_masterport] ? '--masterport=#{config[:puppet_masterport]}' : nil
301
- end
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
- def puppet_detailed_exitcodes_flag
304
- config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
305
- end
290
+ def puppet_server_flag
291
+ config[:puppet_server] ? "--server=#{config[:puppet_server]}" : nil
292
+ end
306
293
 
307
- def puppet_logdest_flag
308
- config[:puppet_logdest] ? "--logdest=#{config[:puppet_logdest]}" : nil
309
- end
294
+ def puppet_masterport_flag
295
+ config[:puppet_masterport] ? '--masterport=#{config[:puppet_masterport]}' : nil
296
+ end
310
297
 
311
- def puppet_test_flag
312
- config[:puppet_test] ? '--test' : nil
313
- end
298
+ def puppet_detailed_exitcodes_flag
299
+ config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
300
+ end
314
301
 
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
302
+ def puppet_logdest_flag
303
+ config[:puppet_logdest] ? "--logdest=#{config[:puppet_logdest]}" : nil
304
+ end
322
305
 
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
306
+ def puppet_test_flag
307
+ config[:puppet_test] ? '--test' : nil
308
+ end
342
309
 
343
- def puppet_apt_repo_file
344
- config[:puppet_apt_repo].split('/').last
345
- end
310
+ def puppet_onetime_flag
311
+ config[:puppet_onetime] ? '--onetime' : nil
312
+ end
346
313
 
347
- def puppet_yum_repo
348
- config[:puppet_yum_repo]
349
- end
314
+ def puppet_no_daemonize_flag
315
+ config[:puppet_no_daemonize] ? '--no-daemonize' : nil
316
+ end
350
317
 
351
- def chef_url
352
- config[:chef_bootstrap_url]
353
- end
318
+ def puppet_no_daemonize
319
+ config[:puppet_no_daemonize]
320
+ end
354
321
 
355
- def prepare_puppet_config
356
- return unless puppet_config
322
+ def puppet_server
323
+ config[:puppet_server]
324
+ end
357
325
 
358
- info('Preparing puppet.conf')
359
- debug("Using puppet config from #{puppet_config}")
326
+ def puppet_certname_flag
327
+ config[:puppet_certname] ? "--certname=#{config[:puppet_certname]}" : nil
328
+ end
360
329
 
361
- FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
362
- end
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