kitchen-puppet 1.41.2 → 1.42.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
- # encoding: UTF-8
2
-
3
- module Kitchen
4
- module Puppet
5
- VERSION = '1.41.2'.freeze
6
- end
7
- end
1
+ # encoding: UTF-8
2
+
3
+ module Kitchen
4
+ module Puppet
5
+ VERSION = '1.42.0'.freeze
6
+ end
7
+ end
@@ -1,80 +1,80 @@
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
- )
49
-
50
- env.config_db.local['path'] = path
51
- ::Librarian::Action::Resolve.new(env).run
52
- ::Librarian::Action::Install.new(env).run
53
- end
54
-
55
- attr_reader :puppetfile, :path, :logger
56
-
57
- def self.load_librarian!(logger)
58
- first_load = require 'librarian/puppet'
59
- require 'librarian/puppet/environment'
60
- require 'librarian/action/resolve'
61
- require 'librarian/action/install'
62
-
63
- version = ::Librarian::Puppet::VERSION
64
- if first_load
65
- logger.debug("Librarian-Puppet #{version} library loaded")
66
- else
67
- logger.debug("Librarian-Puppet #{version} previously loaded")
68
- end
69
- rescue LoadError => e
70
- logger.fatal("The `librarian-puppet' gem is missing and must be installed" \
71
- ' or cannot be properly activated. Run' \
72
- ' `gem install librarian-puppet` or add the following to your' \
73
- " Gemfile if you are using Bundler: `gem 'librarian-puppet'`.")
74
- raise UserError,
75
- "Could not load or activate Librarian-Puppet (#{e.message})"
76
- end
77
- end
78
- end
79
- end
80
- 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
+ )
49
+
50
+ env.config_db.local['path'] = path
51
+ ::Librarian::Action::Resolve.new(env).run
52
+ ::Librarian::Action::Install.new(env).run
53
+ end
54
+
55
+ attr_reader :puppetfile, :path, :logger
56
+
57
+ def self.load_librarian!(logger)
58
+ first_load = require 'librarian/puppet'
59
+ require 'librarian/puppet/environment'
60
+ require 'librarian/action/resolve'
61
+ require 'librarian/action/install'
62
+
63
+ version = ::Librarian::Puppet::VERSION
64
+ if first_load
65
+ logger.debug("Librarian-Puppet #{version} library loaded")
66
+ else
67
+ logger.debug("Librarian-Puppet #{version} previously loaded")
68
+ end
69
+ rescue LoadError => e
70
+ logger.fatal("The `librarian-puppet' gem is missing and must be installed" \
71
+ ' or cannot be properly activated. Run' \
72
+ ' `gem install librarian-puppet` or add the following to your' \
73
+ " Gemfile if you are using Bundler: `gem 'librarian-puppet'`.")
74
+ raise UserError,
75
+ "Could not load or activate Librarian-Puppet (#{e.message})"
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,392 +1,392 @@
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
- if puppet_platform == 'amazon'
264
- config[:puppet_version]
265
- else
266
- config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
267
- end
268
- end
269
-
270
- def puppet_noop_flag
271
- config[:puppet_noop] ? '--noop' : nil
272
- end
273
-
274
- def puppet_debug_flag
275
- config[:puppet_debug] ? '-d' : nil
276
- end
277
-
278
- def puppet_verbose_flag
279
- config[:puppet_verbose] ? '-v' : nil
280
- end
281
-
282
- def puppet_platform
283
- config[:puppet_platform].to_s.downcase
284
- end
285
-
286
- def update_packages_debian_cmd
287
- config[:update_package_repos] ? "#{sudo_env('apt-get')} update" : nil
288
- end
289
-
290
- def update_packages_redhat_cmd
291
- config[:update_package_repos] ? "#{sudo_env('yum')} makecache" : nil
292
- end
293
-
294
- def sudo_env(pm)
295
- http_proxy ? "#{sudo('env')} http_proxy=#{http_proxy} #{pm}" : sudo(pm).to_s
296
- end
297
-
298
- def custom_facts
299
- return nil if config[:custom_facts].none?
300
- bash_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
301
- bash_vars = "export #{bash_vars};"
302
- debug(bash_vars)
303
- bash_vars
304
- end
305
-
306
- def puppet_server_flag
307
- config[:puppet_server] ? "--server=#{config[:puppet_server]}" : nil
308
- end
309
-
310
- def puppet_masterport_flag
311
- config[:puppet_masterport] ? '--masterport=#{config[:puppet_masterport]}' : nil
312
- end
313
-
314
- def puppet_detailed_exitcodes_flag
315
- config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
316
- end
317
-
318
- def puppet_logdest_flag
319
- config[:puppet_logdest] ? "--logdest=#{config[:puppet_logdest]}" : nil
320
- end
321
-
322
- def puppet_test_flag
323
- config[:puppet_test] ? '--test' : nil
324
- end
325
-
326
- def puppet_onetime_flag
327
- config[:puppet_onetime] ? '--onetime' : nil
328
- end
329
-
330
- def puppet_no_daemonize_flag
331
- config[:puppet_no_daemonize] ? '--no-daemonize' : nil
332
- end
333
-
334
- def puppet_no_daemonize
335
- config[:puppet_no_daemonize]
336
- end
337
-
338
- def puppet_server
339
- config[:puppet_server]
340
- end
341
-
342
- def puppet_certname_flag
343
- config[:puppet_certname] ? "--certname=#{config[:puppet_certname]}" : nil
344
- end
345
-
346
- def puppet_digest_flag
347
- config[:puppet_digest] ? "--digest=#{config[:puppet_digest]}" : nil
348
- end
349
-
350
- def puppet_apt_repo
351
- config[:puppet_apt_repo]
352
- end
353
-
354
- def puppet_apt_repo_file
355
- config[:puppet_apt_repo].split('/').last
356
- end
357
-
358
- def puppet_yum_repo
359
- config[:puppet_yum_repo]
360
- end
361
-
362
- def proxy_parm
363
- http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
364
- end
365
-
366
- def gem_proxy_parm
367
- http_proxy ? "--http-proxy #{http_proxy}" : nil
368
- end
369
-
370
- def wget_proxy_parm
371
- http_proxy ? "-e use_proxy=yes -e http_proxy=#{http_proxy}" : nil
372
- end
373
-
374
- def http_proxy
375
- config[:http_proxy]
376
- end
377
-
378
- def chef_url
379
- config[:chef_bootstrap_url]
380
- end
381
-
382
- def prepare_puppet_config
383
- return unless puppet_config
384
-
385
- info('Preparing puppet.conf')
386
- debug("Using puppet config from #{puppet_config}")
387
-
388
- FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
389
- end
390
- end
391
- end
392
- 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
+ if puppet_platform == 'amazon'
264
+ config[:puppet_version]
265
+ else
266
+ config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
267
+ end
268
+ end
269
+
270
+ def puppet_noop_flag
271
+ config[:puppet_noop] ? '--noop' : nil
272
+ end
273
+
274
+ def puppet_debug_flag
275
+ config[:puppet_debug] ? '-d' : nil
276
+ end
277
+
278
+ def puppet_verbose_flag
279
+ config[:puppet_verbose] ? '-v' : nil
280
+ end
281
+
282
+ def puppet_platform
283
+ config[:puppet_platform].to_s.downcase
284
+ end
285
+
286
+ def update_packages_debian_cmd
287
+ config[:update_package_repos] ? "#{sudo_env('apt-get')} update" : nil
288
+ end
289
+
290
+ def update_packages_redhat_cmd
291
+ config[:update_package_repos] ? "#{sudo_env('yum')} makecache" : nil
292
+ end
293
+
294
+ def sudo_env(pm)
295
+ http_proxy ? "#{sudo('env')} http_proxy=#{http_proxy} #{pm}" : sudo(pm).to_s
296
+ end
297
+
298
+ def custom_facts
299
+ return nil if config[:custom_facts].none?
300
+ bash_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
301
+ bash_vars = "export #{bash_vars};"
302
+ debug(bash_vars)
303
+ bash_vars
304
+ end
305
+
306
+ def puppet_server_flag
307
+ config[:puppet_server] ? "--server=#{config[:puppet_server]}" : nil
308
+ end
309
+
310
+ def puppet_masterport_flag
311
+ config[:puppet_masterport] ? '--masterport=#{config[:puppet_masterport]}' : nil
312
+ end
313
+
314
+ def puppet_detailed_exitcodes_flag
315
+ config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
316
+ end
317
+
318
+ def puppet_logdest_flag
319
+ config[:puppet_logdest] ? "--logdest=#{config[:puppet_logdest]}" : nil
320
+ end
321
+
322
+ def puppet_test_flag
323
+ config[:puppet_test] ? '--test' : nil
324
+ end
325
+
326
+ def puppet_onetime_flag
327
+ config[:puppet_onetime] ? '--onetime' : nil
328
+ end
329
+
330
+ def puppet_no_daemonize_flag
331
+ config[:puppet_no_daemonize] ? '--no-daemonize' : nil
332
+ end
333
+
334
+ def puppet_no_daemonize
335
+ config[:puppet_no_daemonize]
336
+ end
337
+
338
+ def puppet_server
339
+ config[:puppet_server]
340
+ end
341
+
342
+ def puppet_certname_flag
343
+ config[:puppet_certname] ? "--certname=#{config[:puppet_certname]}" : nil
344
+ end
345
+
346
+ def puppet_digest_flag
347
+ config[:puppet_digest] ? "--digest=#{config[:puppet_digest]}" : nil
348
+ end
349
+
350
+ def puppet_apt_repo
351
+ config[:puppet_apt_repo]
352
+ end
353
+
354
+ def puppet_apt_repo_file
355
+ config[:puppet_apt_repo].split('/').last
356
+ end
357
+
358
+ def puppet_yum_repo
359
+ config[:puppet_yum_repo]
360
+ end
361
+
362
+ def proxy_parm
363
+ http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
364
+ end
365
+
366
+ def gem_proxy_parm
367
+ http_proxy ? "--http-proxy #{http_proxy}" : nil
368
+ end
369
+
370
+ def wget_proxy_parm
371
+ http_proxy ? "-e use_proxy=yes -e http_proxy=#{http_proxy}" : nil
372
+ end
373
+
374
+ def http_proxy
375
+ config[:http_proxy]
376
+ end
377
+
378
+ def chef_url
379
+ config[:chef_bootstrap_url]
380
+ end
381
+
382
+ def prepare_puppet_config
383
+ return unless puppet_config
384
+
385
+ info('Preparing puppet.conf')
386
+ debug("Using puppet config from #{puppet_config}")
387
+
388
+ FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
389
+ end
390
+ end
391
+ end
392
+ end