kitchen-puppet 1.0.35 → 1.0.36

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,78 +1,78 @@
1
- # -*- encoding: utf-8 -*-
2
- #
3
- # Author:: Fletcher Nichol (<fnichol@nichol.ca>) Neill Turner (<neillwturner@gmail.com>)
4
- #
5
- # Copyright (C) 2013, Fletcher Nichol, 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
- require 'kitchen/errors'
20
- require 'kitchen/logging'
21
-
22
- module Kitchen
23
- module Provisioner
24
- module Puppet
25
- # Puppet module resolver that uses Librarian-Puppet and a Puppetfile to
26
- # calculate # dependencies.
27
- #
28
- class Librarian
29
- include Logging
30
-
31
- def initialize(puppetfile, path, logger = Kitchen.logger)
32
- @puppetfile = puppetfile
33
- @path = path
34
- @logger = logger
35
- end
36
-
37
- def self.load!(logger = Kitchen.logger)
38
- load_librarian!(logger)
39
- end
40
-
41
- def resolve
42
- version = ::Librarian::Puppet::VERSION
43
- info("Resolving module dependencies with Librarian-Puppet #{version}...")
44
- debug("Using Puppetfile from #{puppetfile}")
45
-
46
- env = ::Librarian::Puppet::Environment.new(
47
- project_path: File.dirname(puppetfile))
48
- env.config_db.local['path'] = path
49
- ::Librarian::Action::Resolve.new(env).run
50
- ::Librarian::Action::Install.new(env).run
51
- end
52
-
53
- attr_reader :puppetfile, :path, :logger
54
-
55
- def self.load_librarian!(logger)
56
- first_load = require 'librarian/puppet'
57
- require 'librarian/puppet/environment'
58
- require 'librarian/action/resolve'
59
- require 'librarian/action/install'
60
-
61
- version = ::Librarian::Puppet::VERSION
62
- if first_load
63
- logger.debug("Librarian-Puppet #{version} library loaded")
64
- else
65
- logger.debug("Librarian-Puppet #{version} previously loaded")
66
- end
67
- rescue LoadError => e
68
- logger.fatal("The `librarian-puppet' gem is missing and must be installed" \
69
- ' or cannot be properly activated. Run' \
70
- ' `gem install librarian-puppet` or add the following to your' \
71
- " Gemfile if you are using Bundler: `gem 'librarian-puppet'`.")
72
- raise UserError,
73
- "Could not load or activate Librarian-Puppet (#{e.message})"
74
- end
75
- end
76
- end
77
- end
78
- end
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ # Author:: Fletcher Nichol (<fnichol@nichol.ca>) Neill Turner (<neillwturner@gmail.com>)
4
+ #
5
+ # Copyright (C) 2013, Fletcher Nichol, 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
+ require 'kitchen/errors'
20
+ require 'kitchen/logging'
21
+
22
+ module Kitchen
23
+ module Provisioner
24
+ module Puppet
25
+ # Puppet module resolver that uses Librarian-Puppet and a Puppetfile to
26
+ # calculate # dependencies.
27
+ #
28
+ class Librarian
29
+ include Logging
30
+
31
+ def initialize(puppetfile, path, logger = Kitchen.logger)
32
+ @puppetfile = puppetfile
33
+ @path = path
34
+ @logger = logger
35
+ end
36
+
37
+ def self.load!(logger = Kitchen.logger)
38
+ load_librarian!(logger)
39
+ end
40
+
41
+ def resolve
42
+ version = ::Librarian::Puppet::VERSION
43
+ info("Resolving module dependencies with Librarian-Puppet #{version}...")
44
+ debug("Using Puppetfile from #{puppetfile}")
45
+
46
+ env = ::Librarian::Puppet::Environment.new(
47
+ project_path: File.dirname(puppetfile))
48
+ env.config_db.local['path'] = path
49
+ ::Librarian::Action::Resolve.new(env).run
50
+ ::Librarian::Action::Install.new(env).run
51
+ end
52
+
53
+ attr_reader :puppetfile, :path, :logger
54
+
55
+ def self.load_librarian!(logger)
56
+ first_load = require 'librarian/puppet'
57
+ require 'librarian/puppet/environment'
58
+ require 'librarian/action/resolve'
59
+ require 'librarian/action/install'
60
+
61
+ version = ::Librarian::Puppet::VERSION
62
+ if first_load
63
+ logger.debug("Librarian-Puppet #{version} library loaded")
64
+ else
65
+ logger.debug("Librarian-Puppet #{version} previously loaded")
66
+ end
67
+ rescue LoadError => e
68
+ logger.fatal("The `librarian-puppet' gem is missing and must be installed" \
69
+ ' or cannot be properly activated. Run' \
70
+ ' `gem install librarian-puppet` or add the following to your' \
71
+ " Gemfile if you are using Bundler: `gem 'librarian-puppet'`.")
72
+ raise UserError,
73
+ "Could not load or activate Librarian-Puppet (#{e.message})"
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -1,391 +1,388 @@
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
- class Busser
29
- def non_suite_dirs
30
- %w(data data_bags environments nodes roles puppet)
31
- end
32
- end
33
-
34
- module Provisioner
35
- #
36
- # Puppet Agent provisioner.
37
- #
38
- class PuppetAgent < Base
39
- attr_accessor :tmp_dir
40
-
41
- default_config :require_puppet_omnibus, false
42
- # TODO: use something like https://github.com/fnichol/omnibus-puppet
43
- default_config :puppet_omnibus_url, nil
44
- default_config :puppet_omnibus_remote_path, '/opt/puppet'
45
- default_config :puppet_version, nil
46
- default_config :facter_version, nil
47
- default_config :require_puppet_repo, true
48
- default_config :require_chef_for_busser, true
49
-
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'
53
-
54
- default_config :puppet_agent_command, nil
55
-
56
- default_config :http_proxy, nil
57
-
58
- default_config :puppet_config_path do |provisioner|
59
- provisioner.calculate_path('puppet.conf', :file)
60
- end
61
-
62
- default_config :puppet_debug, false
63
- default_config :puppet_verbose, false
64
- default_config :puppet_noop, false
65
- default_config :puppet_platform, ''
66
- default_config :update_package_repos, true
67
-
68
- default_config :custom_facts, {}
69
-
70
- default_config :puppet_detailed_exitcodes, nil
71
- default_config :puppet_logdest, nil
72
- default_config :puppet_masterport, nil
73
- default_config :puppet_test, false
74
- default_config :puppet_onetime, true
75
- default_config :puppet_no_daemonize, true
76
- default_config :puppet_server, nil # will default to 'puppet'
77
- default_config :puppet_waitforcert, '0'
78
- default_config :puppet_certname, nil
79
- default_config :puppet_digest, nil
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
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
95
- def install_command
96
- return unless config[:require_puppet_omnibus] || config[:require_puppet_repo]
97
- if config[:require_puppet_omnibus]
98
- info('Installing puppet using puppet omnibus')
99
- if !config[:puppet_version].nil?
100
- version = "-v #{config[:puppet_version]}"
101
- else
102
- version = ''
103
- end
104
- <<-INSTALL
105
- #{Util.shell_helpers}
106
-
107
- if [ ! -d "#{config[:puppet_omnibus_remote_path]}" ]; then
108
- echo "-----> Installing Puppet Omnibus"
109
- do_download #{config[:puppet_omnibus_url]} /tmp/puppet_install.sh
110
- #{sudo('sh')} /tmp/puppet_install.sh #{version}
111
- fi
112
- #{install_busser}
113
- INSTALL
114
- else
115
- case puppet_platform
116
- when 'debian', 'ubuntu'
117
- info("Installing puppet on #{puppet_platform}")
118
- <<-INSTALL
119
- if [ ! $(which puppet) ]; then
120
- #{sudo('apt-get')} -y install wget
121
- #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
122
- #{sudo('dpkg')} -i #{puppet_apt_repo_file}
123
- #{update_packages_debian_cmd}
124
- #{sudo_env('apt-get')} -y install facter#{facter_debian_version}
125
- #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
126
- #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
127
- fi
128
- #{install_busser}
129
- INSTALL
130
- when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
131
- info("Installing puppet on #{puppet_platform}")
132
- <<-INSTALL
133
- if [ ! $(which puppet) ]; then
134
- #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
135
- #{update_packages_redhat_cmd}
136
- #{sudo('yum')} -y install puppet#{puppet_redhat_version}
137
- fi
138
- #{install_busser}
139
- INSTALL
140
- else
141
- info('Installing puppet, will try to determine platform os')
142
- <<-INSTALL
143
- if [ ! $(which puppet) ]; then
144
- if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
145
- #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
146
- #{update_packages_redhat_cmd}
147
- #{sudo('yum')} -y install puppet#{puppet_redhat_version}
148
- else
149
- if [ -f /etc/system-release ] || grep -q 'Amazon Linux' /etc/system-release; then
150
- #{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
151
- #{update_packages_redhat_cmd}
152
- #{sudo('yum')} -y install puppet#{puppet_redhat_version}
153
- else
154
- #{sudo('apt-get')} -y install wget
155
- #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
156
- #{sudo('dpkg')} -i #{puppet_apt_repo_file}
157
- #{update_packages_debian_cmd}
158
- #{sudo('apt-get')} -y install facter#{facter_debian_version}
159
- #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
160
- #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
161
- fi
162
- fi
163
- fi
164
- #{install_busser}
165
- INSTALL
166
- end
167
- end
168
- end
169
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
170
-
171
- def install_busser
172
- return unless config[:require_chef_for_busser]
173
- <<-INSTALL
174
- #{Util.shell_helpers}
175
- # install chef omnibus so that busser works as this is needed to run tests :(
176
- # TODO: work out how to install enough ruby
177
- # and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
178
- # whole chef client
179
- if [ ! -d "/opt/chef" ]
180
- then
181
- echo "-----> Installing Chef Omnibus to install busser to run tests"
182
- do_download #{chef_url} /tmp/install.sh
183
- #{sudo('sh')} /tmp/install.sh
184
- fi
185
- INSTALL
186
- end
187
-
188
- def init_command
189
- end
190
-
191
- def create_sandbox
192
- super
193
- debug("Creating local sandbox in #{sandbox_path}")
194
-
195
- yield if block_given?
196
-
197
- prepare_puppet_config
198
- info('Finished Preparing files for transfer')
199
- end
200
-
201
- def cleanup_sandbox
202
- return if sandbox_path.nil?
203
- debug("Cleaning up local sandbox in #{sandbox_path}")
204
- FileUtils.rmtree(sandbox_path)
205
- end
206
-
207
- def prepare_command
208
- commands = []
209
-
210
- if puppet_config
211
- commands << [
212
- sudo('cp'),
213
- File.join(config[:root_path], 'puppet.conf'),
214
- '/etc/puppet'
215
- ].join(' ')
216
- end
217
-
218
- command = commands.join(' && ')
219
- debug(command)
220
- command
221
- end
222
-
223
- def run_command
224
- if !config[:puppet_agent_command].nil?
225
- return config[:puppet_agent_command]
226
- else
227
- [
228
- custom_facts,
229
- sudo_env('puppet'),
230
- 'agent',
231
- puppet_server_flag,
232
- "--waitforcert=#{config[:puppet_waitforcert]}",
233
- puppet_masterport_flag,
234
- puppet_certname_flag,
235
- puppet_digest_flag,
236
- puppet_detailed_exitcodes_flag,
237
- puppet_logdest_flag,
238
- puppet_test_flag,
239
- puppet_onetime_flag,
240
- puppet_no_daemonize_flag,
241
- puppet_noop_flag,
242
- puppet_verbose_flag,
243
- puppet_debug_flag
244
- ].join(' ')
245
- end
246
- end
247
-
248
- protected
249
-
250
- def load_needed_dependencies!
251
- end
252
-
253
- def puppet_config
254
- config[:puppet_config_path]
255
- end
256
-
257
- def puppet_debian_version
258
- config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
259
- end
260
-
261
- def facter_debian_version
262
- config[:facter_version] ? "=#{config[:facter_version]}" : nil
263
- end
264
-
265
- def puppet_redhat_version
266
- config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
267
- end
268
-
269
- def puppet_noop_flag
270
- config[:puppet_noop] ? '--noop' : nil
271
- end
272
-
273
- def puppet_debug_flag
274
- config[:puppet_debug] ? '-d' : nil
275
- end
276
-
277
- def puppet_verbose_flag
278
- config[:puppet_verbose] ? '-v' : nil
279
- end
280
-
281
- def puppet_platform
282
- config[:puppet_platform].to_s.downcase
283
- end
284
-
285
- def update_packages_debian_cmd
286
- config[:update_package_repos] ? "#{sudo_env('apt-get')} update" : nil
287
- end
288
-
289
- def update_packages_redhat_cmd
290
- config[:update_package_repos] ? "#{sudo_env('yum')} makecache" : nil
291
- end
292
-
293
- def sudo_env(pm)
294
- http_proxy ? "#{sudo('env')} http_proxy=#{http_proxy} #{pm}" : "#{sudo(pm)}"
295
- end
296
-
297
- def custom_facts
298
- return nil if config[:custom_facts].none?
299
- bash_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
300
- bash_vars = "export #{bash_vars};"
301
- debug(bash_vars)
302
- bash_vars
303
- end
304
-
305
- def puppet_server_flag
306
- config[:puppet_server] ? "--server=#{config[:puppet_server]}" : nil
307
- end
308
-
309
- def puppet_masterport_flag
310
- config[:puppet_masterport] ? '--masterport=#{config[:puppet_masterport]}' : nil
311
- end
312
-
313
- def puppet_detailed_exitcodes_flag
314
- config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
315
- end
316
-
317
- def puppet_logdest_flag
318
- config[:puppet_logdest] ? "--logdest=#{config[:puppet_logdest]}" : nil
319
- end
320
-
321
- def puppet_test_flag
322
- config[:puppet_test] ? '--test' : nil
323
- end
324
-
325
- def puppet_onetime_flag
326
- config[:puppet_onetime] ? '--onetime' : nil
327
- end
328
-
329
- def puppet_no_daemonize_flag
330
- config[:puppet_no_daemonize] ? '--no-daemonize' : nil
331
- end
332
-
333
- def puppet_no_daemonize
334
- config[:puppet_no_daemonize]
335
- end
336
-
337
- def puppet_server
338
- config[:puppet_server]
339
- end
340
-
341
- def puppet_certname_flag
342
- config[:puppet_certname] ? "--certname=#{config[:puppet_certname]}" : nil
343
- end
344
-
345
- def puppet_digest_flag
346
- config[:puppet_digest] ? "--digest=#{config[:puppet_digest]}" : nil
347
- end
348
-
349
- def puppet_apt_repo
350
- config[:puppet_apt_repo]
351
- end
352
-
353
- def puppet_apt_repo_file
354
- config[:puppet_apt_repo].split('/').last
355
- end
356
-
357
- def puppet_yum_repo
358
- config[:puppet_yum_repo]
359
- end
360
-
361
- def proxy_parm
362
- http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
363
- end
364
-
365
- def gem_proxy_parm
366
- http_proxy ? "--http-proxy #{http_proxy}" : nil
367
- end
368
-
369
- def wget_proxy_parm
370
- http_proxy ? "-e use_proxy=yes -e http_proxy=#{http_proxy}" : nil
371
- end
372
-
373
- def http_proxy
374
- config[:http_proxy]
375
- end
376
-
377
- def chef_url
378
- config[:chef_bootstrap_url]
379
- end
380
-
381
- def prepare_puppet_config
382
- return unless puppet_config
383
-
384
- info('Preparing puppet.conf')
385
- debug("Using puppet config from #{puppet_config}")
386
-
387
- FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
388
- end
389
- end
390
- end
391
- 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
+ class Busser
29
+ def non_suite_dirs
30
+ %w(data data_bags environments nodes roles puppet)
31
+ end
32
+ end
33
+
34
+ module Provisioner
35
+ #
36
+ # Puppet Agent provisioner.
37
+ #
38
+ class PuppetAgent < Base
39
+ attr_accessor :tmp_dir
40
+
41
+ default_config :require_puppet_omnibus, false
42
+ # TODO: use something like https://github.com/fnichol/omnibus-puppet
43
+ default_config :puppet_omnibus_url, nil
44
+ default_config :puppet_omnibus_remote_path, '/opt/puppet'
45
+ default_config :puppet_version, nil
46
+ default_config :facter_version, nil
47
+ default_config :require_puppet_repo, true
48
+ default_config :require_chef_for_busser, true
49
+
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'
53
+
54
+ default_config :puppet_agent_command, nil
55
+
56
+ default_config :http_proxy, nil
57
+
58
+ default_config :puppet_config_path do |provisioner|
59
+ provisioner.calculate_path('puppet.conf', :file)
60
+ end
61
+
62
+ default_config :puppet_debug, false
63
+ default_config :puppet_verbose, false
64
+ default_config :puppet_noop, false
65
+ default_config :puppet_platform, ''
66
+ default_config :update_package_repos, true
67
+
68
+ default_config :custom_facts, {}
69
+
70
+ default_config :puppet_detailed_exitcodes, nil
71
+ default_config :puppet_logdest, nil
72
+ default_config :puppet_masterport, nil
73
+ default_config :puppet_test, false
74
+ default_config :puppet_onetime, true
75
+ default_config :puppet_no_daemonize, true
76
+ default_config :puppet_server, nil # will default to 'puppet'
77
+ default_config :puppet_waitforcert, '0'
78
+ default_config :puppet_certname, nil
79
+ default_config :puppet_digest, nil
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
+ # rubocop:disable Metrics/CyclomaticComplexity
95
+ def install_command
96
+ return unless config[:require_puppet_omnibus] || config[:require_puppet_repo]
97
+ if config[:require_puppet_omnibus]
98
+ info('Installing puppet using puppet omnibus')
99
+ version = ''
100
+ version = "-v #{config[:puppet_version]}" if config[:puppet_version]
101
+ <<-INSTALL
102
+ #{Util.shell_helpers}
103
+
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}
110
+ INSTALL
111
+ else
112
+ case puppet_platform
113
+ when 'debian', 'ubuntu'
114
+ info("Installing puppet on #{puppet_platform}")
115
+ <<-INSTALL
116
+ if [ ! $(which puppet) ]; then
117
+ #{sudo('apt-get')} -y install wget
118
+ #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
119
+ #{sudo('dpkg')} -i #{puppet_apt_repo_file}
120
+ #{update_packages_debian_cmd}
121
+ #{sudo_env('apt-get')} -y install facter#{facter_debian_version}
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', 'oracle', 'amazon'
128
+ info("Installing puppet on #{puppet_platform}")
129
+ <<-INSTALL
130
+ if [ ! $(which puppet) ]; then
131
+ #{sudo('rpm')} -ivh #{proxy_parm} #{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 #{proxy_parm} #{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 #{proxy_parm} #{puppet_yum_repo}
148
+ #{update_packages_redhat_cmd}
149
+ #{sudo('yum')} -y install puppet#{puppet_redhat_version}
150
+ else
151
+ #{sudo('apt-get')} -y install wget
152
+ #{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
153
+ #{sudo('dpkg')} -i #{puppet_apt_repo_file}
154
+ #{update_packages_debian_cmd}
155
+ #{sudo('apt-get')} -y install facter#{facter_debian_version}
156
+ #{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
157
+ #{sudo('apt-get')} -y install puppet#{puppet_debian_version}
158
+ fi
159
+ fi
160
+ fi
161
+ #{install_busser}
162
+ INSTALL
163
+ end
164
+ end
165
+ end
166
+ # rubocop:enable Metrics/CyclomaticComplexity
167
+
168
+ def install_busser
169
+ return unless config[:require_chef_for_busser]
170
+ <<-INSTALL
171
+ #{Util.shell_helpers}
172
+ # install chef omnibus so that busser works as this is needed to run tests :(
173
+ # TODO: work out how to install enough ruby
174
+ # and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
175
+ # whole chef client
176
+ if [ ! -d "/opt/chef" ]
177
+ then
178
+ echo "-----> Installing Chef Omnibus to install busser to run tests"
179
+ do_download #{chef_url} /tmp/install.sh
180
+ #{sudo('sh')} /tmp/install.sh
181
+ fi
182
+ INSTALL
183
+ end
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
+ end
197
+
198
+ def cleanup_sandbox
199
+ return if sandbox_path.nil?
200
+ debug("Cleaning up local sandbox in #{sandbox_path}")
201
+ FileUtils.rmtree(sandbox_path)
202
+ end
203
+
204
+ def prepare_command
205
+ commands = []
206
+
207
+ if puppet_config
208
+ commands << [
209
+ sudo('cp'),
210
+ File.join(config[:root_path], 'puppet.conf'),
211
+ '/etc/puppet'
212
+ ].join(' ')
213
+ end
214
+
215
+ command = commands.join(' && ')
216
+ debug(command)
217
+ command
218
+ end
219
+
220
+ def run_command
221
+ if !config[:puppet_agent_command].nil?
222
+ return config[:puppet_agent_command]
223
+ else
224
+ [
225
+ custom_facts,
226
+ sudo_env('puppet'),
227
+ 'agent',
228
+ puppet_server_flag,
229
+ "--waitforcert=#{config[:puppet_waitforcert]}",
230
+ puppet_masterport_flag,
231
+ puppet_certname_flag,
232
+ puppet_digest_flag,
233
+ puppet_detailed_exitcodes_flag,
234
+ puppet_logdest_flag,
235
+ puppet_test_flag,
236
+ puppet_onetime_flag,
237
+ puppet_no_daemonize_flag,
238
+ puppet_noop_flag,
239
+ puppet_verbose_flag,
240
+ puppet_debug_flag
241
+ ].join(' ')
242
+ end
243
+ end
244
+
245
+ protected
246
+
247
+ def load_needed_dependencies!
248
+ end
249
+
250
+ def puppet_config
251
+ config[:puppet_config_path]
252
+ end
253
+
254
+ def puppet_debian_version
255
+ config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
256
+ end
257
+
258
+ def facter_debian_version
259
+ config[:facter_version] ? "=#{config[:facter_version]}" : nil
260
+ end
261
+
262
+ def puppet_redhat_version
263
+ config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
264
+ end
265
+
266
+ def puppet_noop_flag
267
+ config[:puppet_noop] ? '--noop' : nil
268
+ end
269
+
270
+ def puppet_debug_flag
271
+ config[:puppet_debug] ? '-d' : nil
272
+ end
273
+
274
+ def puppet_verbose_flag
275
+ config[:puppet_verbose] ? '-v' : nil
276
+ end
277
+
278
+ def puppet_platform
279
+ config[:puppet_platform].to_s.downcase
280
+ end
281
+
282
+ def update_packages_debian_cmd
283
+ config[:update_package_repos] ? "#{sudo_env('apt-get')} update" : nil
284
+ end
285
+
286
+ def update_packages_redhat_cmd
287
+ config[:update_package_repos] ? "#{sudo_env('yum')} makecache" : nil
288
+ end
289
+
290
+ def sudo_env(pm)
291
+ http_proxy ? "#{sudo('env')} http_proxy=#{http_proxy} #{pm}" : sudo(pm).to_s
292
+ end
293
+
294
+ def custom_facts
295
+ return nil if config[:custom_facts].none?
296
+ bash_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
297
+ bash_vars = "export #{bash_vars};"
298
+ debug(bash_vars)
299
+ bash_vars
300
+ end
301
+
302
+ def puppet_server_flag
303
+ config[:puppet_server] ? "--server=#{config[:puppet_server]}" : nil
304
+ end
305
+
306
+ def puppet_masterport_flag
307
+ config[:puppet_masterport] ? '--masterport=#{config[:puppet_masterport]}' : nil
308
+ end
309
+
310
+ def puppet_detailed_exitcodes_flag
311
+ config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
312
+ end
313
+
314
+ def puppet_logdest_flag
315
+ config[:puppet_logdest] ? "--logdest=#{config[:puppet_logdest]}" : nil
316
+ end
317
+
318
+ def puppet_test_flag
319
+ config[:puppet_test] ? '--test' : nil
320
+ end
321
+
322
+ def puppet_onetime_flag
323
+ config[:puppet_onetime] ? '--onetime' : nil
324
+ end
325
+
326
+ def puppet_no_daemonize_flag
327
+ config[:puppet_no_daemonize] ? '--no-daemonize' : nil
328
+ end
329
+
330
+ def puppet_no_daemonize
331
+ config[:puppet_no_daemonize]
332
+ end
333
+
334
+ def puppet_server
335
+ config[:puppet_server]
336
+ end
337
+
338
+ def puppet_certname_flag
339
+ config[:puppet_certname] ? "--certname=#{config[:puppet_certname]}" : nil
340
+ end
341
+
342
+ def puppet_digest_flag
343
+ config[:puppet_digest] ? "--digest=#{config[:puppet_digest]}" : nil
344
+ end
345
+
346
+ def puppet_apt_repo
347
+ config[:puppet_apt_repo]
348
+ end
349
+
350
+ def puppet_apt_repo_file
351
+ config[:puppet_apt_repo].split('/').last
352
+ end
353
+
354
+ def puppet_yum_repo
355
+ config[:puppet_yum_repo]
356
+ end
357
+
358
+ def proxy_parm
359
+ http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
360
+ end
361
+
362
+ def gem_proxy_parm
363
+ http_proxy ? "--http-proxy #{http_proxy}" : nil
364
+ end
365
+
366
+ def wget_proxy_parm
367
+ http_proxy ? "-e use_proxy=yes -e http_proxy=#{http_proxy}" : nil
368
+ end
369
+
370
+ def http_proxy
371
+ config[:http_proxy]
372
+ end
373
+
374
+ def chef_url
375
+ config[:chef_bootstrap_url]
376
+ end
377
+
378
+ def prepare_puppet_config
379
+ return unless puppet_config
380
+
381
+ info('Preparing puppet.conf')
382
+ debug("Using puppet config from #{puppet_config}")
383
+
384
+ FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
385
+ end
386
+ end
387
+ end
388
+ end