kitchen-puppet 0.0.14 → 0.0.15
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.
- data/README.md +7 -1
- data/lib/kitchen-puppet/version.rb +1 -1
- data/lib/kitchen/provisioner/puppet_agent.rb +359 -0
- data/lib/kitchen/provisioner/puppet_apply.rb +566 -552
- data/provisioner_options.md +77 -2
- metadata +3 -2
data/README.md
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
# kitchen-puppet
|
2
2
|
A Test Kitchen Provisioner for Puppet
|
3
3
|
|
4
|
-
The
|
4
|
+
The providers supports both puppet apply and puppet agent clients
|
5
|
+
|
6
|
+
The PuppetApply provider works by passing the puppet repository based on attributes in .kitchen.yml & calling puppet apply.
|
7
|
+
|
8
|
+
The PuppetAgent provider works by passing the puppetmaster and other attributes in .kitchen.yml & calling puppet agent.
|
9
|
+
|
5
10
|
|
6
11
|
This provider has been tested against the Ubuntu 1204 and Centos 6.5 boxes running in vagrant/virtualbox.
|
7
12
|
|
8
13
|
## Requirements
|
9
14
|
You'll need a driver box without a chef installation so puppet can be installed. Puppet have one at http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box or http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box.
|
10
15
|
|
16
|
+
For PuppetAgent a server with a puppet master is required that can resolve the hostname ip address of the server. The server must also be able to resolve the hostname ip address of the puppet master.
|
11
17
|
|
12
18
|
## Installation & Setup
|
13
19
|
You'll need the test-kitchen & kitchen-puppet gem's installed in your system, along with kitchen-vagrant or some ther suitable driver for test-kitchen.
|
@@ -0,0 +1,359 @@
|
|
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,552 +1,566 @@
|
|
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_apply 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 Apply provisioner.
|
39
|
-
#
|
40
|
-
class PuppetApply < 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
|
-
default_config :resolve_with_librarian_puppet, true
|
51
|
-
default_config :puppet_environment, nil
|
52
|
-
default_config :puppet_apt_repo, "http://apt.puppetlabs.com/puppetlabs-release-precise.deb"
|
53
|
-
default_config :puppet_yum_repo, "https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm"
|
54
|
-
default_config :chef_bootstrap_url, "https://www.getchef.com/chef/install.sh"
|
55
|
-
|
56
|
-
default_config :puppet_apply_command, nil
|
57
|
-
|
58
|
-
default_config :hiera_data_remote_path, '/var/lib/hiera'
|
59
|
-
default_config :manifest, 'site.pp'
|
60
|
-
|
61
|
-
default_config :manifests_path do |provisioner|
|
62
|
-
provisioner.calculate_path('manifests') or
|
63
|
-
raise 'No manifests_path detected. Please specify one in .kitchen.yml'
|
64
|
-
end
|
65
|
-
|
66
|
-
default_config :modules_path do |provisioner|
|
67
|
-
modules_path = provisioner.calculate_path('modules')
|
68
|
-
if modules_path.nil? && provisioner.calculate_path('Puppetfile', :file).nil?
|
69
|
-
raise 'No modules_path detected. Please specify one in .kitchen.yml'
|
70
|
-
end
|
71
|
-
modules_path
|
72
|
-
end
|
73
|
-
|
74
|
-
default_config :files_path do |provisioner|
|
75
|
-
provisioner.calculate_path('files') || 'files'
|
76
|
-
end
|
77
|
-
|
78
|
-
default_config :hiera_data_path do |provisioner|
|
79
|
-
provisioner.calculate_path('hiera')
|
80
|
-
end
|
81
|
-
|
82
|
-
default_config :puppet_config_path do |provisioner|
|
83
|
-
provisioner.calculate_path('puppet.conf', :file)
|
84
|
-
end
|
85
|
-
|
86
|
-
default_config :hiera_config_path do |provisioner|
|
87
|
-
provisioner.calculate_path('hiera.yaml', :file)
|
88
|
-
end
|
89
|
-
|
90
|
-
default_config :fileserver_config_path do |provisioner|
|
91
|
-
provisioner.calculate_path('fileserver.conf', :file)
|
92
|
-
end
|
93
|
-
|
94
|
-
default_config :puppetfile_path do |provisioner|
|
95
|
-
provisioner.calculate_path('Puppetfile', :file)
|
96
|
-
end
|
97
|
-
|
98
|
-
default_config :modulefile_path do |provisioner|
|
99
|
-
provisioner.calculate_path('Modulefile', :file)
|
100
|
-
end
|
101
|
-
|
102
|
-
default_config :metadata_json_path do |provisioner|
|
103
|
-
provisioner.calculate_path('metadata.json', :file)
|
104
|
-
end
|
105
|
-
|
106
|
-
default_config :manifests_path do |provisioner|
|
107
|
-
provisioner.calculate_path('manifests', :directory)
|
108
|
-
end
|
109
|
-
|
110
|
-
|
111
|
-
default_config :puppet_debug, false
|
112
|
-
default_config :puppet_verbose, false
|
113
|
-
default_config :puppet_noop, false
|
114
|
-
default_config :puppet_platform, ''
|
115
|
-
default_config :update_package_repos, true
|
116
|
-
default_config :
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
candidates
|
122
|
-
candidates << File.join(base, instance.suite.name, path)
|
123
|
-
candidates << File.join(base, path)
|
124
|
-
candidates << File.join(
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
#{
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
#{sudo('
|
158
|
-
#{
|
159
|
-
#{
|
160
|
-
#{sudo('apt-get')} -y install puppet#{puppet_debian_version}
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
#{
|
181
|
-
#{
|
182
|
-
|
183
|
-
|
184
|
-
#{sudo('
|
185
|
-
#{
|
186
|
-
#{
|
187
|
-
#{sudo('apt-get')} -y install puppet#{puppet_debian_version}
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
#
|
201
|
-
#
|
202
|
-
#
|
203
|
-
#
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
#{
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
cmd =
|
221
|
-
|
222
|
-
cmd
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
'
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
'
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
command
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
'
|
305
|
-
|
306
|
-
|
307
|
-
"--
|
308
|
-
"--
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
FileUtils.
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
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_apply 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 Apply provisioner.
|
39
|
+
#
|
40
|
+
class PuppetApply < 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
|
+
default_config :resolve_with_librarian_puppet, true
|
51
|
+
default_config :puppet_environment, nil
|
52
|
+
default_config :puppet_apt_repo, "http://apt.puppetlabs.com/puppetlabs-release-precise.deb"
|
53
|
+
default_config :puppet_yum_repo, "https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm"
|
54
|
+
default_config :chef_bootstrap_url, "https://www.getchef.com/chef/install.sh"
|
55
|
+
|
56
|
+
default_config :puppet_apply_command, nil
|
57
|
+
|
58
|
+
default_config :hiera_data_remote_path, '/var/lib/hiera'
|
59
|
+
default_config :manifest, 'site.pp'
|
60
|
+
|
61
|
+
default_config :manifests_path do |provisioner|
|
62
|
+
provisioner.calculate_path('manifests') or
|
63
|
+
raise 'No manifests_path detected. Please specify one in .kitchen.yml'
|
64
|
+
end
|
65
|
+
|
66
|
+
default_config :modules_path do |provisioner|
|
67
|
+
modules_path = provisioner.calculate_path('modules')
|
68
|
+
if modules_path.nil? && provisioner.calculate_path('Puppetfile', :file).nil?
|
69
|
+
raise 'No modules_path detected. Please specify one in .kitchen.yml'
|
70
|
+
end
|
71
|
+
modules_path
|
72
|
+
end
|
73
|
+
|
74
|
+
default_config :files_path do |provisioner|
|
75
|
+
provisioner.calculate_path('files') || 'files'
|
76
|
+
end
|
77
|
+
|
78
|
+
default_config :hiera_data_path do |provisioner|
|
79
|
+
provisioner.calculate_path('hiera')
|
80
|
+
end
|
81
|
+
|
82
|
+
default_config :puppet_config_path do |provisioner|
|
83
|
+
provisioner.calculate_path('puppet.conf', :file)
|
84
|
+
end
|
85
|
+
|
86
|
+
default_config :hiera_config_path do |provisioner|
|
87
|
+
provisioner.calculate_path('hiera.yaml', :file)
|
88
|
+
end
|
89
|
+
|
90
|
+
default_config :fileserver_config_path do |provisioner|
|
91
|
+
provisioner.calculate_path('fileserver.conf', :file)
|
92
|
+
end
|
93
|
+
|
94
|
+
default_config :puppetfile_path do |provisioner|
|
95
|
+
provisioner.calculate_path('Puppetfile', :file)
|
96
|
+
end
|
97
|
+
|
98
|
+
default_config :modulefile_path do |provisioner|
|
99
|
+
provisioner.calculate_path('Modulefile', :file)
|
100
|
+
end
|
101
|
+
|
102
|
+
default_config :metadata_json_path do |provisioner|
|
103
|
+
provisioner.calculate_path('metadata.json', :file)
|
104
|
+
end
|
105
|
+
|
106
|
+
default_config :manifests_path do |provisioner|
|
107
|
+
provisioner.calculate_path('manifests', :directory)
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
default_config :puppet_debug, false
|
112
|
+
default_config :puppet_verbose, false
|
113
|
+
default_config :puppet_noop, false
|
114
|
+
default_config :puppet_platform, ''
|
115
|
+
default_config :update_package_repos, true
|
116
|
+
default_config :remove_puppet_repo, false
|
117
|
+
default_config :custom_facts, {}
|
118
|
+
|
119
|
+
def calculate_path(path, type = :directory)
|
120
|
+
base = config[:test_base_path]
|
121
|
+
candidates = []
|
122
|
+
candidates << File.join(base, instance.suite.name, 'puppet', path)
|
123
|
+
candidates << File.join(base, instance.suite.name, path)
|
124
|
+
candidates << File.join(base, path)
|
125
|
+
candidates << File.join(Dir.pwd, path)
|
126
|
+
|
127
|
+
candidates.find do |c|
|
128
|
+
type == :directory ? File.directory?(c) : File.file?(c)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def install_command
|
133
|
+
return unless config[:require_puppet_omnibus] or config[:require_puppet_repo]
|
134
|
+
if config[:require_puppet_omnibus]
|
135
|
+
info("Installing puppet using puppet omnibus")
|
136
|
+
version = if !config[:puppet_version].nil?
|
137
|
+
"-v #{config[:puppet_version]}"
|
138
|
+
else
|
139
|
+
""
|
140
|
+
end
|
141
|
+
<<-INSTALL
|
142
|
+
#{Util.shell_helpers}
|
143
|
+
|
144
|
+
if [ ! -d "#{config[:puppet_omnibus_remote_path]}" ]; then
|
145
|
+
echo "-----> Installing Puppet Omnibus"
|
146
|
+
do_download #{config[:puppet_omnibus_url]} /tmp/puppet_install.sh
|
147
|
+
#{sudo('sh')} /tmp/puppet_install.sh #{version}
|
148
|
+
fi
|
149
|
+
#{install_busser}
|
150
|
+
INSTALL
|
151
|
+
else
|
152
|
+
case puppet_platform
|
153
|
+
when "debian", "ubuntu"
|
154
|
+
info("Installing puppet on #{puppet_platform}")
|
155
|
+
<<-INSTALL
|
156
|
+
if [ ! $(which puppet) ]; then
|
157
|
+
#{sudo('wget')} #{puppet_apt_repo}
|
158
|
+
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
159
|
+
#{update_packages_debian_cmd}
|
160
|
+
#{sudo('apt-get')} -y install puppet-common#{puppet_debian_version}
|
161
|
+
#{sudo('apt-get')} -y install puppet#{puppet_debian_version}
|
162
|
+
fi
|
163
|
+
#{install_busser}
|
164
|
+
INSTALL
|
165
|
+
when "redhat", "centos", "fedora"
|
166
|
+
info("Installing puppet on #{puppet_platform}")
|
167
|
+
<<-INSTALL
|
168
|
+
if [ ! $(which puppet) ]; then
|
169
|
+
#{sudo('rpm')} -ivh #{puppet_yum_repo}
|
170
|
+
#{update_packages_redhat_cmd}
|
171
|
+
#{sudo('yum')} -y install puppet#{puppet_redhat_version}
|
172
|
+
fi
|
173
|
+
#{install_busser}
|
174
|
+
INSTALL
|
175
|
+
else
|
176
|
+
info("Installing puppet, will try to determine platform os")
|
177
|
+
<<-INSTALL
|
178
|
+
if [ ! $(which puppet) ]; then
|
179
|
+
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
|
180
|
+
#{sudo('rpm')} -ivh #{puppet_yum_repo}
|
181
|
+
#{update_packages_redhat_cmd}
|
182
|
+
#{sudo('yum')} -y install puppet#{puppet_redhat_version}
|
183
|
+
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}
|
189
|
+
fi
|
190
|
+
fi
|
191
|
+
#{install_busser}
|
192
|
+
INSTALL
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def install_busser
|
198
|
+
if config[:require_chef_for_busser]
|
199
|
+
<<-INSTALL
|
200
|
+
#{Util.shell_helpers}
|
201
|
+
# install chef omnibus so that busser works as this is needed to run tests :(
|
202
|
+
# TODO: work out how to install enough ruby
|
203
|
+
# and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
|
204
|
+
# whole chef client
|
205
|
+
if [ ! -d "/opt/chef" ]
|
206
|
+
then
|
207
|
+
echo "-----> Installing Chef Omnibus to install busser to run tests"
|
208
|
+
do_download #{chef_url} /tmp/install.sh
|
209
|
+
#{sudo('sh')} /tmp/install.sh
|
210
|
+
fi
|
211
|
+
INSTALL
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
def init_command
|
218
|
+
dirs = %w{modules manifests files hiera hiera.yaml}.
|
219
|
+
map { |dir| File.join(config[:root_path], dir) }.join(" ")
|
220
|
+
cmd = "#{sudo('rm')} -rf #{dirs} #{hiera_data_remote_path} /etc/hiera.yaml /etc/puppet/hiera.yaml /etc/puppet/fileserver.conf;"
|
221
|
+
cmd = cmd+" mkdir -p #{config[:root_path]}"
|
222
|
+
debug(cmd)
|
223
|
+
cmd
|
224
|
+
end
|
225
|
+
|
226
|
+
def create_sandbox
|
227
|
+
super
|
228
|
+
debug("Creating local sandbox in #{sandbox_path}")
|
229
|
+
|
230
|
+
yield if block_given?
|
231
|
+
|
232
|
+
prepare_modules
|
233
|
+
prepare_manifests
|
234
|
+
prepare_files
|
235
|
+
prepare_puppet_config
|
236
|
+
prepare_hiera_config
|
237
|
+
prepare_fileserver_config
|
238
|
+
prepare_hiera_data
|
239
|
+
info('Finished Preparing files for transfer')
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
def cleanup_sandbox
|
244
|
+
return if sandbox_path.nil?
|
245
|
+
debug("Cleaning up local sandbox in #{sandbox_path}")
|
246
|
+
FileUtils.rmtree(sandbox_path)
|
247
|
+
end
|
248
|
+
|
249
|
+
def prepare_command
|
250
|
+
commands = []
|
251
|
+
|
252
|
+
if puppet_config
|
253
|
+
commands << [
|
254
|
+
sudo('cp'),
|
255
|
+
File.join(config[:root_path], 'puppet.conf'),
|
256
|
+
'/etc/puppet',
|
257
|
+
].join(' ')
|
258
|
+
end
|
259
|
+
|
260
|
+
if hiera_config
|
261
|
+
commands << [
|
262
|
+
sudo('cp'), File.join(config[:root_path],'hiera.yaml'), '/etc/',
|
263
|
+
].join(' ')
|
264
|
+
|
265
|
+
commands << [
|
266
|
+
sudo('cp'), File.join(config[:root_path],'hiera.yaml'), '/etc/puppet/',
|
267
|
+
].join(' ')
|
268
|
+
end
|
269
|
+
|
270
|
+
if fileserver_config
|
271
|
+
commands << [
|
272
|
+
sudo('cp'),
|
273
|
+
File.join(config[:root_path], 'fileserver.conf'),
|
274
|
+
'/etc/puppet',
|
275
|
+
].join(' ')
|
276
|
+
end
|
277
|
+
|
278
|
+
if hiera_data and hiera_data_remote_path == '/var/lib/hiera'
|
279
|
+
commands << [
|
280
|
+
sudo('cp -r'), File.join(config[:root_path], 'hiera'), '/var/lib/'
|
281
|
+
].join(' ')
|
282
|
+
end
|
283
|
+
|
284
|
+
if hiera_data and hiera_data_remote_path != '/var/lib/hiera'
|
285
|
+
commands << [
|
286
|
+
sudo('mkdir -p'), hiera_data_remote_path
|
287
|
+
].join(' ')
|
288
|
+
commands << [
|
289
|
+
sudo('cp -r'), File.join(config[:root_path], 'hiera/*'), hiera_data_remote_path
|
290
|
+
].join(' ')
|
291
|
+
end
|
292
|
+
|
293
|
+
command = commands.join(' && ')
|
294
|
+
debug(command)
|
295
|
+
command
|
296
|
+
end
|
297
|
+
|
298
|
+
def run_command
|
299
|
+
if !config[:puppet_apply_command].nil?
|
300
|
+
return config[:puppet_apply_command]
|
301
|
+
else
|
302
|
+
[
|
303
|
+
custom_facts,
|
304
|
+
sudo('puppet'),
|
305
|
+
'apply',
|
306
|
+
File.join(config[:root_path], 'manifests', manifest),
|
307
|
+
"--modulepath=#{File.join(config[:root_path], 'modules')}",
|
308
|
+
"--manifestdir=#{File.join(config[:root_path], 'manifests')}",
|
309
|
+
"--fileserverconfig=#{File.join(config[:root_path], 'fileserver.conf')}",
|
310
|
+
puppet_environment_flag,
|
311
|
+
puppet_noop_flag,
|
312
|
+
puppet_verbose_flag,
|
313
|
+
puppet_debug_flag,
|
314
|
+
remove_repo
|
315
|
+
].join(" ")
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
protected
|
320
|
+
|
321
|
+
def load_needed_dependencies!
|
322
|
+
if File.exists?(puppetfile) and config[:resolve_with_librarian_puppet]
|
323
|
+
debug("Puppetfile found at #{puppetfile}, loading Librarian-Puppet")
|
324
|
+
Puppet::Librarian.load!(logger)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
def tmpmodules_dir
|
329
|
+
File.join(sandbox_path, 'modules')
|
330
|
+
end
|
331
|
+
|
332
|
+
def puppetfile
|
333
|
+
config[:puppetfile_path] or ''
|
334
|
+
end
|
335
|
+
|
336
|
+
def modulefile
|
337
|
+
config[:modulefile_path] or ''
|
338
|
+
end
|
339
|
+
|
340
|
+
def metadata_json
|
341
|
+
config[:metadata_json_path] or ''
|
342
|
+
end
|
343
|
+
|
344
|
+
def manifest
|
345
|
+
config[:manifest]
|
346
|
+
end
|
347
|
+
|
348
|
+
def manifests
|
349
|
+
config[:manifests_path]
|
350
|
+
end
|
351
|
+
|
352
|
+
def modules
|
353
|
+
config[:modules_path]
|
354
|
+
end
|
355
|
+
|
356
|
+
def files
|
357
|
+
config[:files_path] || 'files'
|
358
|
+
end
|
359
|
+
|
360
|
+
def puppet_config
|
361
|
+
config[:puppet_config_path]
|
362
|
+
end
|
363
|
+
|
364
|
+
def puppet_environment
|
365
|
+
config[:puppet_environment]
|
366
|
+
end
|
367
|
+
|
368
|
+
def hiera_config
|
369
|
+
config[:hiera_config_path]
|
370
|
+
end
|
371
|
+
|
372
|
+
def fileserver_config
|
373
|
+
config[:fileserver_config_path]
|
374
|
+
end
|
375
|
+
|
376
|
+
def hiera_data
|
377
|
+
config[:hiera_data_path]
|
378
|
+
end
|
379
|
+
|
380
|
+
def hiera_data_remote_path
|
381
|
+
config[:hiera_data_remote_path]
|
382
|
+
end
|
383
|
+
|
384
|
+
def puppet_debian_version
|
385
|
+
config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
|
386
|
+
end
|
387
|
+
|
388
|
+
def puppet_redhat_version
|
389
|
+
config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
|
390
|
+
end
|
391
|
+
|
392
|
+
def puppet_environment_flag
|
393
|
+
config[:puppet_environment] ? "--environment=#{config[:puppet_environment]}" : nil
|
394
|
+
end
|
395
|
+
|
396
|
+
def puppet_noop_flag
|
397
|
+
config[:puppet_noop] ? '--noop' : nil
|
398
|
+
end
|
399
|
+
|
400
|
+
def puppet_debug_flag
|
401
|
+
config[:puppet_debug] ? '-d' : nil
|
402
|
+
end
|
403
|
+
|
404
|
+
def puppet_verbose_flag
|
405
|
+
config[:puppet_verbose] ? '-v' : nil
|
406
|
+
end
|
407
|
+
|
408
|
+
def puppet_platform
|
409
|
+
config[:puppet_platform].to_s.downcase
|
410
|
+
end
|
411
|
+
|
412
|
+
def update_packages_debian_cmd
|
413
|
+
config[:update_package_repos] ? "#{sudo('apt-get')} update" : nil
|
414
|
+
end
|
415
|
+
|
416
|
+
def update_packages_redhat_cmd
|
417
|
+
config[:update_package_repos] ? "#{sudo('yum')} makecache" : nil
|
418
|
+
end
|
419
|
+
|
420
|
+
def remove_puppet_repo
|
421
|
+
config[:remove_puppet_repo]
|
422
|
+
end
|
423
|
+
|
424
|
+
def custom_facts
|
425
|
+
return nil if config[:custom_facts].none?
|
426
|
+
bash_vars = config[:custom_facts].map { |k,v| "FACTER_#{k}=#{v}" }.join(" ")
|
427
|
+
bash_vars = "export #{bash_vars};"
|
428
|
+
debug(bash_vars)
|
429
|
+
bash_vars
|
430
|
+
end
|
431
|
+
|
432
|
+
def remove_repo
|
433
|
+
if remove_puppet_repo
|
434
|
+
'; rm -rf /tmp/kitchen'
|
435
|
+
else
|
436
|
+
nil
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
def puppet_apt_repo
|
441
|
+
config[:puppet_apt_repo]
|
442
|
+
end
|
443
|
+
|
444
|
+
def puppet_apt_repo_file
|
445
|
+
config[:puppet_apt_repo].split('/').last
|
446
|
+
end
|
447
|
+
|
448
|
+
def puppet_yum_repo
|
449
|
+
config[:puppet_yum_repo]
|
450
|
+
end
|
451
|
+
|
452
|
+
def chef_url
|
453
|
+
config[:chef_bootstrap_url]
|
454
|
+
end
|
455
|
+
|
456
|
+
def prepare_manifests
|
457
|
+
info('Preparing manifests')
|
458
|
+
debug("Using manifests from #{manifests}")
|
459
|
+
|
460
|
+
tmp_manifests_dir = File.join(sandbox_path, 'manifests')
|
461
|
+
FileUtils.mkdir_p(tmp_manifests_dir)
|
462
|
+
FileUtils.cp_r(Dir.glob("#{manifests}/*"), tmp_manifests_dir)
|
463
|
+
end
|
464
|
+
|
465
|
+
def prepare_files
|
466
|
+
info('Preparing files')
|
467
|
+
|
468
|
+
unless File.directory?(files)
|
469
|
+
info 'nothing to do for files'
|
470
|
+
return
|
471
|
+
end
|
472
|
+
|
473
|
+
debug("Using files from #{files}")
|
474
|
+
|
475
|
+
tmp_files_dir = File.join(sandbox_path, 'files')
|
476
|
+
FileUtils.mkdir_p(tmp_files_dir)
|
477
|
+
FileUtils.cp_r(Dir.glob("#{files}/*"), tmp_files_dir)
|
478
|
+
end
|
479
|
+
|
480
|
+
def prepare_modules
|
481
|
+
info('Preparing modules')
|
482
|
+
|
483
|
+
FileUtils.mkdir_p(tmpmodules_dir)
|
484
|
+
|
485
|
+
resolve_with_librarian if File.exists?(puppetfile) and config[:resolve_with_librarian_puppet]
|
486
|
+
|
487
|
+
if modules && File.directory?(modules)
|
488
|
+
debug("Copying modules from #{modules} to #{tmpmodules_dir}")
|
489
|
+
FileUtils.cp_r(Dir.glob("#{modules}/*"), tmpmodules_dir, remove_destination: true)
|
490
|
+
else
|
491
|
+
info 'nothing to do for modules'
|
492
|
+
end
|
493
|
+
|
494
|
+
copy_self_as_module
|
495
|
+
end
|
496
|
+
|
497
|
+
def copy_self_as_module
|
498
|
+
if File.exists?(modulefile)
|
499
|
+
warn('Modulefile found but this is depricated, ignoring it, see https://tickets.puppetlabs.com/browse/PUP-1188')
|
500
|
+
end
|
501
|
+
|
502
|
+
if File.exists?(metadata_json)
|
503
|
+
module_name = nil
|
504
|
+
begin
|
505
|
+
module_name = JSON.parse(IO.read(metadata_json))['name'].split('-').last
|
506
|
+
rescue
|
507
|
+
error("not able to load or parse #{metadata_json_path} for the name of the module")
|
508
|
+
end
|
509
|
+
|
510
|
+
if module_name
|
511
|
+
module_target_path = File.join(sandbox_path, 'modules', module_name)
|
512
|
+
FileUtils.mkdir_p(module_target_path)
|
513
|
+
FileUtils.cp_r(
|
514
|
+
Dir.glob(File.join(config[:kitchen_root], '*')).reject { |entry| entry =~ /modules/ },
|
515
|
+
module_target_path,
|
516
|
+
remove_destination: true
|
517
|
+
)
|
518
|
+
end
|
519
|
+
end
|
520
|
+
end
|
521
|
+
|
522
|
+
def prepare_puppet_config
|
523
|
+
return unless puppet_config
|
524
|
+
|
525
|
+
info('Preparing puppet.conf')
|
526
|
+
debug("Using puppet config from #{puppet_config}")
|
527
|
+
|
528
|
+
FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
|
529
|
+
end
|
530
|
+
|
531
|
+
def prepare_hiera_config
|
532
|
+
return unless hiera_config
|
533
|
+
|
534
|
+
info('Preparing hiera')
|
535
|
+
debug("Using hiera from #{hiera_config}")
|
536
|
+
|
537
|
+
FileUtils.cp_r(hiera_config, File.join(sandbox_path, 'hiera.yaml'))
|
538
|
+
end
|
539
|
+
|
540
|
+
def prepare_fileserver_config
|
541
|
+
return unless fileserver_config
|
542
|
+
|
543
|
+
info('Preparing fileserver')
|
544
|
+
debug("Using fileserver config from #{fileserver_config}")
|
545
|
+
|
546
|
+
FileUtils.cp_r(fileserver_config, File.join(sandbox_path, 'fileserver.conf'))
|
547
|
+
end
|
548
|
+
|
549
|
+
def prepare_hiera_data
|
550
|
+
return unless hiera_data
|
551
|
+
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}")
|
555
|
+
FileUtils.mkdir_p(tmp_hiera_dir)
|
556
|
+
FileUtils.cp_r(Dir.glob("#{hiera_data}/*"), tmp_hiera_dir)
|
557
|
+
end
|
558
|
+
|
559
|
+
def resolve_with_librarian
|
560
|
+
Kitchen.mutex.synchronize do
|
561
|
+
Puppet::Librarian.new(puppetfile, tmpmodules_dir, logger).resolve
|
562
|
+
end
|
563
|
+
end
|
564
|
+
end
|
565
|
+
end
|
566
|
+
end
|