kitchen-puppet 1.45.2 → 1.45.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf7a2a60c11e9a20415c8fcfc8172075ad8ea7b5
|
4
|
+
data.tar.gz: cb579c531f8582c9959f5f6478958145709d0f65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efac3f00213d07f2870a003ad45c7a2a1a05002da6e8d76841ef32cda1d3d5db333851b030f5b44ca6273323db67c6f829e737be0a4b0d54af486ff875cc84b5
|
7
|
+
data.tar.gz: d663a3526270cec9dbc62d694bda9e618a4f5b9dbcd551ce4ca3f4240a9b5a9826f837dd3664a4944e7320502c550af7105df65257e55c82dd92019f9c2d50a9
|
@@ -182,8 +182,7 @@ module Kitchen
|
|
182
182
|
INSTALL
|
183
183
|
end
|
184
184
|
|
185
|
-
def init_command
|
186
|
-
end
|
185
|
+
def init_command; end
|
187
186
|
|
188
187
|
def create_sandbox
|
189
188
|
super
|
@@ -241,8 +240,7 @@ module Kitchen
|
|
241
240
|
|
242
241
|
protected
|
243
242
|
|
244
|
-
def load_needed_dependencies
|
245
|
-
end
|
243
|
+
def load_needed_dependencies!; end
|
246
244
|
|
247
245
|
def puppet_config
|
248
246
|
config[:puppet_config_path]
|
@@ -921,7 +921,7 @@ module Kitchen
|
|
921
921
|
elsif powershell_shell?
|
922
922
|
"; if(@(#{[config[:puppet_whitelist_exit_code]].join(', ')}) -contains $LASTEXITCODE) {exit 0} else {exit $LASTEXITCODE}"
|
923
923
|
else
|
924
|
-
|
924
|
+
'; RC=$?; [ ' + [config[:puppet_whitelist_exit_code]].flatten.map { |x| "\$RC -eq #{x}" }.join(' -o ') + ' ] && exit 0; exit $RC'
|
925
925
|
end
|
926
926
|
end
|
927
927
|
|
@@ -0,0 +1,1098 @@
|
|
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 'uri'
|
24
|
+
require 'json'
|
25
|
+
require 'kitchen'
|
26
|
+
require 'kitchen/provisioner/puppet/librarian'
|
27
|
+
|
28
|
+
module Kitchen
|
29
|
+
class Busser
|
30
|
+
def non_suite_dirs
|
31
|
+
%w(data data_bags environments nodes roles puppet)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module Configurable
|
36
|
+
def platform_name
|
37
|
+
instance.platform.name
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module Provisioner
|
42
|
+
#
|
43
|
+
# Puppet Apply provisioner.
|
44
|
+
#
|
45
|
+
class PuppetApply < Base
|
46
|
+
attr_accessor :tmp_dir
|
47
|
+
|
48
|
+
default_config :require_puppet_collections, false
|
49
|
+
default_config :puppet_yum_collections_repo, 'http://yum.puppetlabs.com/puppetlabs-release-pc1-el-6.noarch.rpm'
|
50
|
+
default_config :puppet_apt_collections_repo, 'http://apt.puppetlabs.com/puppetlabs-release-pc1-wheezy.deb'
|
51
|
+
default_config :puppet_coll_remote_path, '/opt/puppetlabs'
|
52
|
+
default_config :puppet_version, nil
|
53
|
+
default_config :facter_version, nil
|
54
|
+
default_config :hiera_version, nil
|
55
|
+
default_config :install_hiera, false
|
56
|
+
default_config :hiera_package, 'hiera-puppet'
|
57
|
+
default_config :require_puppet_repo, true
|
58
|
+
default_config :require_chef_for_busser, true
|
59
|
+
default_config :resolve_with_librarian_puppet, true
|
60
|
+
default_config :puppet_environment, nil
|
61
|
+
default_config :puppet_apt_repo, 'http://apt.puppetlabs.com/puppetlabs-release-precise.deb'
|
62
|
+
default_config :puppet_yum_repo, 'https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm'
|
63
|
+
default_config :chef_bootstrap_url, 'https://www.getchef.com/chef/install.sh'
|
64
|
+
default_config :puppet_logdest, nil
|
65
|
+
default_config :custom_install_command, nil
|
66
|
+
default_config :puppet_whitelist_exit_code, nil
|
67
|
+
default_config :require_puppet_omnibus, false
|
68
|
+
default_config :puppet_omnibus_url, 'https://raw.githubusercontent.com/petems/puppet-install-shell/master/install_puppet.sh'
|
69
|
+
default_config :puppet_enc, nil
|
70
|
+
default_config :ignore_spec_fixtures, false
|
71
|
+
|
72
|
+
default_config :puppet_apply_command, nil
|
73
|
+
|
74
|
+
default_config :puppet_git_init, nil
|
75
|
+
default_config :puppet_git_pr, nil
|
76
|
+
|
77
|
+
default_config :http_proxy, nil
|
78
|
+
default_config :https_proxy, nil
|
79
|
+
|
80
|
+
default_config :ignored_paths_from_root, []
|
81
|
+
default_config :hiera_data_remote_path, '/var/lib/hiera'
|
82
|
+
default_config :manifest, 'site.pp'
|
83
|
+
|
84
|
+
default_config :manifests_path do |provisioner|
|
85
|
+
provisioner.calculate_path('manifests') ||
|
86
|
+
raise('No manifests_path detected. Please specify one in .kitchen.yml')
|
87
|
+
end
|
88
|
+
|
89
|
+
default_config :modules_path do |provisioner|
|
90
|
+
modules_path = provisioner.calculate_path('modules')
|
91
|
+
if modules_path.nil? && provisioner.calculate_path('Puppetfile', :file).nil?
|
92
|
+
raise('No modules_path detected. Please specify one in .kitchen.yml')
|
93
|
+
end
|
94
|
+
modules_path
|
95
|
+
end
|
96
|
+
|
97
|
+
default_config :files_path do |provisioner|
|
98
|
+
provisioner.calculate_path('files') || 'files'
|
99
|
+
end
|
100
|
+
|
101
|
+
default_config :hiera_data_path do |provisioner|
|
102
|
+
provisioner.calculate_path('hiera')
|
103
|
+
end
|
104
|
+
|
105
|
+
default_config :puppet_config_path do |provisioner|
|
106
|
+
provisioner.calculate_path('puppet.conf', :file)
|
107
|
+
end
|
108
|
+
|
109
|
+
default_config :hiera_config_path do |provisioner|
|
110
|
+
provisioner.calculate_path('hiera.yaml', :file)
|
111
|
+
end
|
112
|
+
|
113
|
+
default_config :fileserver_config_path do |provisioner|
|
114
|
+
provisioner.calculate_path('fileserver.conf', :file)
|
115
|
+
end
|
116
|
+
default_config :puppetfile_path do |provisioner|
|
117
|
+
provisioner.calculate_path('Puppetfile', :file)
|
118
|
+
end
|
119
|
+
|
120
|
+
default_config :modulefile_path do |provisioner|
|
121
|
+
provisioner.calculate_path('Modulefile', :file)
|
122
|
+
end
|
123
|
+
|
124
|
+
default_config :metadata_json_path do |provisioner|
|
125
|
+
provisioner.calculate_path('metadata.json', :file)
|
126
|
+
end
|
127
|
+
|
128
|
+
default_config :manifests_path do |provisioner|
|
129
|
+
provisioner.calculate_path('manifests', :directory)
|
130
|
+
end
|
131
|
+
|
132
|
+
default_config :spec_files_path do |provisioner|
|
133
|
+
provisioner.calculate_path('spec', :directory)
|
134
|
+
end
|
135
|
+
|
136
|
+
default_config :spec_files_remote_path, '/etc/puppet/spec'
|
137
|
+
|
138
|
+
default_config :puppet_debug, false
|
139
|
+
default_config :puppet_verbose, false
|
140
|
+
default_config :puppet_noop, false
|
141
|
+
default_config :platform, &:platform_name
|
142
|
+
default_config :update_package_repos, true
|
143
|
+
default_config :remove_puppet_repo, false
|
144
|
+
default_config :install_custom_facts, false
|
145
|
+
default_config :custom_facts, {}
|
146
|
+
default_config :facterlib, nil
|
147
|
+
default_config :puppet_detailed_exitcodes, nil
|
148
|
+
default_config :facter_file, nil
|
149
|
+
default_config :librarian_puppet_ssl_file, nil
|
150
|
+
|
151
|
+
default_config :hiera_eyaml, false
|
152
|
+
default_config :hiera_eyaml_key_remote_path, '/etc/puppet/secure/keys'
|
153
|
+
|
154
|
+
default_config :hiera_eyaml_key_path do |provisioner|
|
155
|
+
provisioner.calculate_path('hiera_keys')
|
156
|
+
end
|
157
|
+
|
158
|
+
default_config :hiera_deep_merge, false
|
159
|
+
default_config :puppet_no_sudo, false
|
160
|
+
|
161
|
+
def calculate_path(path, type = :directory)
|
162
|
+
base = config[:test_base_path]
|
163
|
+
candidates = []
|
164
|
+
candidates << File.join(base, instance.suite.name, 'puppet', path)
|
165
|
+
candidates << File.join(base, instance.suite.name, path)
|
166
|
+
candidates << File.join(base, path)
|
167
|
+
candidates << File.join(Dir.pwd, path)
|
168
|
+
|
169
|
+
candidates.find do |c|
|
170
|
+
type == :directory ? File.directory?(c) : File.file?(c)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
175
|
+
def install_command
|
176
|
+
return unless config[:require_puppet_collections] || config[:require_puppet_repo] || config[:require_puppet_omnibus]
|
177
|
+
if config[:require_puppet_omnibus]
|
178
|
+
install_omnibus_command
|
179
|
+
elsif config[:require_puppet_collections]
|
180
|
+
install_command_collections
|
181
|
+
else
|
182
|
+
case puppet_platform
|
183
|
+
when 'debian', 'ubuntu'
|
184
|
+
info("Installing puppet on #{config[:platform]}")
|
185
|
+
# need to add a CR to avoid trouble with proxy settings concatenation
|
186
|
+
<<-INSTALL
|
187
|
+
|
188
|
+
if [ ! $(which puppet) ]; then
|
189
|
+
#{sudo('apt-get')} -y install wget
|
190
|
+
#{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
|
191
|
+
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
192
|
+
#{update_packages_debian_cmd}
|
193
|
+
#{sudo_env('apt-get')} -y install facter#{facter_debian_version}
|
194
|
+
#{sudo_env('apt-get')} -y install puppet-common#{puppet_debian_version}
|
195
|
+
#{sudo_env('apt-get')} -y install puppet#{puppet_debian_version}
|
196
|
+
#{install_hiera}
|
197
|
+
fi
|
198
|
+
#{install_eyaml}
|
199
|
+
#{install_deep_merge}
|
200
|
+
#{install_busser}
|
201
|
+
#{custom_install_command}
|
202
|
+
INSTALL
|
203
|
+
when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
|
204
|
+
info("Installing puppet from yum on #{puppet_platform}")
|
205
|
+
# need to add a CR to avoid trouble with proxy settings concatenation
|
206
|
+
<<-INSTALL
|
207
|
+
|
208
|
+
if [ ! $(which puppet) ]; then
|
209
|
+
#{install_puppet_yum_repo}
|
210
|
+
fi
|
211
|
+
#{install_eyaml}
|
212
|
+
#{install_deep_merge}
|
213
|
+
#{install_busser}
|
214
|
+
#{custom_install_command}
|
215
|
+
INSTALL
|
216
|
+
else
|
217
|
+
info('Installing puppet, will try to determine platform os')
|
218
|
+
# need to add a CR to avoid trouble with proxy settings concatenation
|
219
|
+
<<-INSTALL
|
220
|
+
|
221
|
+
if [ ! $(which puppet) ]; then
|
222
|
+
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
|
223
|
+
#{install_puppet_yum_repo}
|
224
|
+
else
|
225
|
+
if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
|
226
|
+
#{install_puppet_yum_repo}
|
227
|
+
else
|
228
|
+
#{sudo('apt-get')} -y install wget
|
229
|
+
#{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
|
230
|
+
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
231
|
+
#{update_packages_debian_cmd}
|
232
|
+
#{sudo_env('apt-get')} -y install facter#{facter_debian_version}
|
233
|
+
#{sudo_env('apt-get')} -y install puppet-common#{puppet_debian_version}
|
234
|
+
#{sudo_env('apt-get')} -y install puppet#{puppet_debian_version}
|
235
|
+
#{install_hiera}
|
236
|
+
fi
|
237
|
+
fi
|
238
|
+
fi
|
239
|
+
#{install_eyaml}
|
240
|
+
#{install_deep_merge}
|
241
|
+
#{install_busser}
|
242
|
+
#{custom_install_command}
|
243
|
+
INSTALL
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
248
|
+
|
249
|
+
def install_command_collections
|
250
|
+
case puppet_platform
|
251
|
+
when 'debian', 'ubuntu'
|
252
|
+
info("Installing Puppet Collections on #{puppet_platform}")
|
253
|
+
<<-INSTALL
|
254
|
+
#{Util.shell_helpers}
|
255
|
+
if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
|
256
|
+
if [ ! -f "#{config[:puppet_apt_collections_repo]}" ]; then
|
257
|
+
#{sudo('apt-get')} -y install wget
|
258
|
+
#{sudo('wget')} #{wget_proxy_parm} #{config[:puppet_apt_collections_repo]}
|
259
|
+
fi
|
260
|
+
#{sudo('dpkg')} -i #{puppet_apt_coll_repo_file}
|
261
|
+
#{sudo('apt-get')} update
|
262
|
+
#{sudo_env('apt-get')} -y install puppet-agent#{puppet_debian_version}
|
263
|
+
fi
|
264
|
+
#{install_eyaml("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
265
|
+
#{install_deep_merge}
|
266
|
+
#{install_busser}
|
267
|
+
#{custom_install_command}
|
268
|
+
INSTALL
|
269
|
+
when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
|
270
|
+
info("Installing Puppet Collections on #{puppet_platform}")
|
271
|
+
<<-INSTALL
|
272
|
+
#{Util.shell_helpers}
|
273
|
+
if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
|
274
|
+
echo "-----> #{sudo_env('yum')} -y localinstall #{config[:puppet_yum_collections_repo]}"
|
275
|
+
#{sudo_env('yum')} -y localinstall #{config[:puppet_yum_collections_repo]}
|
276
|
+
#{sudo_env('yum')} -y install puppet-agent#{puppet_redhat_version}
|
277
|
+
fi
|
278
|
+
#{install_eyaml("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
279
|
+
#{install_deep_merge}
|
280
|
+
#{install_busser}
|
281
|
+
#{custom_install_command}
|
282
|
+
INSTALL
|
283
|
+
else
|
284
|
+
info('Installing Puppet Collections, will try to determine platform os')
|
285
|
+
<<-INSTALL
|
286
|
+
#{Util.shell_helpers}
|
287
|
+
if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
|
288
|
+
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ] || \
|
289
|
+
[ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
|
290
|
+
echo "-----> #{sudo_env('yum')} -y localinstall #{config[:puppet_yum_collections_repo]}"
|
291
|
+
#{sudo_env('yum')} -y localinstall #{config[:puppet_yum_collections_repo]}
|
292
|
+
#{sudo_env('yum')} -y install puppet-agent#{puppet_redhat_version}
|
293
|
+
else
|
294
|
+
#{sudo('apt-get')} -y install wget
|
295
|
+
#{sudo('wget')} #{wget_proxy_parm} #{config[:puppet_apt_collections_repo]}
|
296
|
+
#{sudo('dpkg')} -i #{puppet_apt_coll_repo_file}
|
297
|
+
#{sudo('apt-get')} update
|
298
|
+
#{sudo_env('apt-get')} -y install puppet-agent#{puppet_debian_version}
|
299
|
+
fi
|
300
|
+
fi
|
301
|
+
#{install_eyaml("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
302
|
+
#{install_deep_merge}
|
303
|
+
#{install_busser}
|
304
|
+
#{custom_install_command}
|
305
|
+
INSTALL
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
def install_deep_merge
|
310
|
+
return unless config[:hiera_deep_merge]
|
311
|
+
<<-INSTALL
|
312
|
+
# Support for hash merge lookups to recursively merge hash keys
|
313
|
+
if [[ $(#{sudo('gem')} list deep_merge -i) == 'false' ]]; then
|
314
|
+
echo '-----> Installing deep_merge to provide deep_merge of hiera hashes'
|
315
|
+
#{sudo('gem')} install #{gem_proxy_parm} --no-ri --no-rdoc deep_merge
|
316
|
+
fi
|
317
|
+
INSTALL
|
318
|
+
end
|
319
|
+
|
320
|
+
def install_eyaml(gem_cmd = 'gem')
|
321
|
+
return unless config[:hiera_eyaml]
|
322
|
+
<<-INSTALL
|
323
|
+
# A backend for Hiera that provides per-value asymmetric encryption of sensitive data
|
324
|
+
if [[ $(#{sudo(gem_cmd)} list hiera-eyaml -i) == 'false' ]]; then
|
325
|
+
echo '-----> Installing hiera-eyaml to provide encryption of hiera data'
|
326
|
+
#{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc highline -v 1.6.21
|
327
|
+
#{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml
|
328
|
+
fi
|
329
|
+
INSTALL
|
330
|
+
end
|
331
|
+
|
332
|
+
def install_busser
|
333
|
+
return unless config[:require_chef_for_busser]
|
334
|
+
<<-INSTALL
|
335
|
+
#{Util.shell_helpers}
|
336
|
+
# install chef omnibus so that busser works as this is needed to run tests :(
|
337
|
+
# TODO: work out how to install enough ruby
|
338
|
+
# and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
|
339
|
+
# whole chef client
|
340
|
+
if [ ! -d "/opt/chef" ]
|
341
|
+
then
|
342
|
+
echo '-----> Installing Chef Omnibus to install busser to run tests'
|
343
|
+
#{export_http_proxy_parm}
|
344
|
+
#{export_https_proxy_parm}
|
345
|
+
do_download #{chef_url} /tmp/install.sh
|
346
|
+
#{sudo('sh')} /tmp/install.sh
|
347
|
+
fi
|
348
|
+
INSTALL
|
349
|
+
end
|
350
|
+
|
351
|
+
def install_omnibus_command
|
352
|
+
info('Installing puppet using puppet omnibus')
|
353
|
+
<<-INSTALL
|
354
|
+
#{Util.shell_helpers}
|
355
|
+
if [ ! $(which puppet) ]; then
|
356
|
+
echo "-----> Installing Puppet Omnibus"
|
357
|
+
#{export_http_proxy_parm}
|
358
|
+
#{export_https_proxy_parm}
|
359
|
+
do_download #{config[:puppet_omnibus_url]} /tmp/install_puppet.sh
|
360
|
+
#{sudo_env('sh')} /tmp/install_puppet.sh
|
361
|
+
fi
|
362
|
+
INSTALL
|
363
|
+
end
|
364
|
+
|
365
|
+
def install_hiera
|
366
|
+
return unless config[:install_hiera]
|
367
|
+
<<-INSTALL
|
368
|
+
#{sudo_env('apt-get')} -y install #{hiera_package}
|
369
|
+
INSTALL
|
370
|
+
end
|
371
|
+
|
372
|
+
def hiera_package
|
373
|
+
"#{config[:hiera_package]}#{puppet_hiera_debian_version}"
|
374
|
+
end
|
375
|
+
|
376
|
+
# /bin/wget -P /etc/pki/rpm-gpg/ http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
|
377
|
+
# changed to curl
|
378
|
+
|
379
|
+
def install_puppet_yum_repo
|
380
|
+
<<-INSTALL
|
381
|
+
rhelversion=$(cat /etc/redhat-release | grep 'release 7')
|
382
|
+
# For CentOS7/RHEL7 the rdo release contains puppetlabs repo, creating conflict. Create temp-repo
|
383
|
+
#{sudo_env('curl')} -o /etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
|
384
|
+
if [ -n "$rhelversion" ]; then
|
385
|
+
echo '[puppettemp-products]
|
386
|
+
name=Puppet Labs Products - \$basearch
|
387
|
+
baseurl=http://yum.puppetlabs.com/el/7/products/\$basearch
|
388
|
+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs
|
389
|
+
enabled=0
|
390
|
+
gpgcheck=1
|
391
|
+
[puppettemp-deps]
|
392
|
+
name=Puppet Labs Dependencies - \$basearch
|
393
|
+
baseurl=http://yum.puppetlabs.com/el/7/dependencies/\$basearch
|
394
|
+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs
|
395
|
+
enabled=0
|
396
|
+
gpgcheck=1' | sudo tee /etc/yum.repos.d/puppettemp.repo > /dev/null
|
397
|
+
sudo sed -i 's/^[ \t]*//' /etc/yum.repos.d/puppettemp.repo
|
398
|
+
#{update_packages_redhat_cmd}
|
399
|
+
#{sudo_env('yum')} -y --enablerepo=puppettemp-products --enablerepo=puppettemp-deps install puppet#{puppet_redhat_version}
|
400
|
+
# Clean up temporary puppet repo
|
401
|
+
sudo rm -rf /etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs
|
402
|
+
sudo rm -rf /etc/yum.repos.d/puppettemp.repo
|
403
|
+
else
|
404
|
+
#{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
|
405
|
+
#{update_packages_redhat_cmd}
|
406
|
+
#{sudo_env('yum')} -y install puppet#{puppet_redhat_version}
|
407
|
+
fi
|
408
|
+
INSTALL
|
409
|
+
end
|
410
|
+
|
411
|
+
def custom_install_command
|
412
|
+
<<-INSTALL
|
413
|
+
#{config[:custom_install_command]}
|
414
|
+
INSTALL
|
415
|
+
end
|
416
|
+
|
417
|
+
def init_command
|
418
|
+
dirs = %w(modules manifests files hiera hiera.yaml facter spec enc)
|
419
|
+
.map { |dir| File.join(config[:root_path], dir) }.join(' ')
|
420
|
+
cmd = "#{sudo('rm')} -rf #{dirs} #{hiera_data_remote_path} \
|
421
|
+
/etc/hiera.yaml #{puppet_dir}/hiera.yaml \
|
422
|
+
#{spec_files_remote_path} \
|
423
|
+
#{puppet_dir}/fileserver.conf;"
|
424
|
+
cmd += config[:puppet_environment] ? "#{sudo('rm')} -f #{File.join(puppet_dir, config[:puppet_environment])};" : ''
|
425
|
+
cmd += " mkdir -p #{config[:root_path]}; #{sudo('mkdir')} -p #{puppet_dir}"
|
426
|
+
debug(cmd)
|
427
|
+
cmd
|
428
|
+
end
|
429
|
+
|
430
|
+
def create_sandbox
|
431
|
+
super
|
432
|
+
debug("Creating local sandbox in #{sandbox_path}")
|
433
|
+
yield if block_given?
|
434
|
+
prepare_modules
|
435
|
+
prepare_manifests
|
436
|
+
prepare_files
|
437
|
+
prepare_facter_file
|
438
|
+
prepare_facts
|
439
|
+
prepare_puppet_config
|
440
|
+
prepare_hiera_config
|
441
|
+
prepare_fileserver_config
|
442
|
+
prepare_hiera_data
|
443
|
+
prepare_enc
|
444
|
+
prepare_spec_files
|
445
|
+
info('Finished Preparing files for transfer')
|
446
|
+
end
|
447
|
+
|
448
|
+
def cleanup_sandbox
|
449
|
+
return if sandbox_path.nil?
|
450
|
+
debug("Cleaning up local sandbox in #{sandbox_path}")
|
451
|
+
FileUtils.rmtree(sandbox_path)
|
452
|
+
return if remove_repo.nil?
|
453
|
+
debug("Cleaning up remote sandbox: #{remove_repo}")
|
454
|
+
instance.remote_exec remove_repo
|
455
|
+
end
|
456
|
+
|
457
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
458
|
+
def prepare_command
|
459
|
+
commands = []
|
460
|
+
if puppet_git_init
|
461
|
+
commands << [
|
462
|
+
sudo('rm -rf'), '/etc/puppet'
|
463
|
+
].join(' ')
|
464
|
+
|
465
|
+
commands << [
|
466
|
+
sudo('git clone'), puppet_git_init, '/etc/puppet'
|
467
|
+
].join(' ')
|
468
|
+
end
|
469
|
+
|
470
|
+
if puppet_git_pr
|
471
|
+
commands << [
|
472
|
+
sudo('git'),
|
473
|
+
'--git-dir=/etc/puppet/.git/',
|
474
|
+
'fetch -f',
|
475
|
+
'origin',
|
476
|
+
"pull/#{puppet_git_pr}/head:pr_#{puppet_git_pr}"
|
477
|
+
].join(' ')
|
478
|
+
|
479
|
+
commands << [
|
480
|
+
sudo('git'),
|
481
|
+
'--git-dir=/etc/puppet/.git/',
|
482
|
+
'--work-tree=/etc/puppet/',
|
483
|
+
'checkout',
|
484
|
+
"pr_#{puppet_git_pr}"
|
485
|
+
].join(' ')
|
486
|
+
end
|
487
|
+
|
488
|
+
if puppet_config
|
489
|
+
commands << [
|
490
|
+
sudo('cp'),
|
491
|
+
File.join(config[:root_path], 'puppet.conf'),
|
492
|
+
puppet_dir
|
493
|
+
].join(' ')
|
494
|
+
end
|
495
|
+
|
496
|
+
if hiera_config
|
497
|
+
commands << [
|
498
|
+
sudo('cp'), File.join(config[:root_path], 'hiera.yaml'), '/etc/'
|
499
|
+
].join(' ')
|
500
|
+
|
501
|
+
commands << [
|
502
|
+
sudo('cp'), File.join(config[:root_path], 'hiera.yaml'), hiera_config_dir
|
503
|
+
].join(' ')
|
504
|
+
end
|
505
|
+
|
506
|
+
if fileserver_config
|
507
|
+
commands << [
|
508
|
+
sudo('cp'),
|
509
|
+
File.join(config[:root_path], 'fileserver.conf'),
|
510
|
+
puppet_dir
|
511
|
+
].join(' ')
|
512
|
+
end
|
513
|
+
|
514
|
+
if hiera_data && hiera_data_remote_path == '/var/lib/hiera'
|
515
|
+
commands << [
|
516
|
+
sudo('cp -r'), File.join(config[:root_path], 'hiera'), '/var/lib/'
|
517
|
+
].join(' ')
|
518
|
+
end
|
519
|
+
|
520
|
+
if hiera_data && hiera_data_remote_path != '/var/lib/hiera'
|
521
|
+
commands << [
|
522
|
+
sudo('mkdir -p'), hiera_data_remote_path
|
523
|
+
].join(' ')
|
524
|
+
commands << [
|
525
|
+
sudo('cp -r'), File.join(config[:root_path], 'hiera/*'), hiera_data_remote_path
|
526
|
+
].join(' ')
|
527
|
+
end
|
528
|
+
|
529
|
+
if hiera_eyaml
|
530
|
+
commands << [
|
531
|
+
sudo('mkdir -p'), hiera_eyaml_key_remote_path
|
532
|
+
].join(' ')
|
533
|
+
commands << [
|
534
|
+
sudo('cp -r'), File.join(config[:root_path], 'hiera_keys/*'), hiera_eyaml_key_remote_path
|
535
|
+
].join(' ')
|
536
|
+
end
|
537
|
+
|
538
|
+
if puppet_environment
|
539
|
+
commands << [
|
540
|
+
sudo('ln -s '), config[:root_path], File.join(puppet_dir, config[:puppet_environment])
|
541
|
+
].join(' ')
|
542
|
+
end
|
543
|
+
|
544
|
+
if spec_files_path && spec_files_remote_path
|
545
|
+
commands << [
|
546
|
+
sudo('mkdir -p'), spec_files_remote_path
|
547
|
+
].join(' ')
|
548
|
+
commands << [
|
549
|
+
sudo('cp -r'), File.join(config[:root_path], 'spec/*'), spec_files_remote_path
|
550
|
+
].join(' ')
|
551
|
+
end
|
552
|
+
|
553
|
+
if config[:puppet_enc]
|
554
|
+
commands << [
|
555
|
+
sudo('chmod 755'), File.join("#{config[:root_path]}/enc", File.basename(config[:puppet_enc]))
|
556
|
+
].join(' ')
|
557
|
+
end
|
558
|
+
|
559
|
+
command = commands.join(' && ')
|
560
|
+
debug(command)
|
561
|
+
command
|
562
|
+
end
|
563
|
+
|
564
|
+
def run_command
|
565
|
+
if !config[:puppet_apply_command].nil?
|
566
|
+
return config[:puppet_apply_command]
|
567
|
+
else
|
568
|
+
result = [
|
569
|
+
facterlib,
|
570
|
+
custom_facts,
|
571
|
+
puppet_manifestdir,
|
572
|
+
puppet_cmd,
|
573
|
+
'apply',
|
574
|
+
File.join(config[:root_path], 'manifests', manifest),
|
575
|
+
"--modulepath=#{File.join(config[:root_path], 'modules')}",
|
576
|
+
"--fileserverconfig=#{File.join(config[:root_path], 'fileserver.conf')}",
|
577
|
+
custom_options,
|
578
|
+
puppet_environment_flag,
|
579
|
+
puppet_noop_flag,
|
580
|
+
puppet_enc_flag,
|
581
|
+
puppet_detailed_exitcodes_flag,
|
582
|
+
puppet_verbose_flag,
|
583
|
+
puppet_debug_flag,
|
584
|
+
puppet_logdest_flag,
|
585
|
+
puppet_whitelist_exit_code
|
586
|
+
].join(' ')
|
587
|
+
info("Going to invoke puppet apply with: #{result}")
|
588
|
+
result
|
589
|
+
end
|
590
|
+
end
|
591
|
+
|
592
|
+
protected
|
593
|
+
|
594
|
+
def load_needed_dependencies!
|
595
|
+
return unless File.exist?(puppetfile)
|
596
|
+
return unless config[:resolve_with_librarian_puppet]
|
597
|
+
debug("Puppetfile found at #{puppetfile}, loading Librarian-Puppet")
|
598
|
+
Puppet::Librarian.load!(logger)
|
599
|
+
end
|
600
|
+
|
601
|
+
def tmpmodules_dir
|
602
|
+
File.join(sandbox_path, 'modules')
|
603
|
+
end
|
604
|
+
|
605
|
+
def puppetfile
|
606
|
+
config[:puppetfile_path] || ''
|
607
|
+
end
|
608
|
+
|
609
|
+
def modulefile
|
610
|
+
config[:modulefile_path] || ''
|
611
|
+
end
|
612
|
+
|
613
|
+
def metadata_json
|
614
|
+
config[:metadata_json_path] || ''
|
615
|
+
end
|
616
|
+
|
617
|
+
def manifest
|
618
|
+
config[:manifest]
|
619
|
+
end
|
620
|
+
|
621
|
+
def manifests
|
622
|
+
config[:manifests_path]
|
623
|
+
end
|
624
|
+
|
625
|
+
def modules
|
626
|
+
config[:modules_path]
|
627
|
+
end
|
628
|
+
|
629
|
+
def files
|
630
|
+
config[:files_path] || 'files'
|
631
|
+
end
|
632
|
+
|
633
|
+
def puppet_config
|
634
|
+
config[:puppet_config_path]
|
635
|
+
end
|
636
|
+
|
637
|
+
def puppet_environment
|
638
|
+
config[:puppet_environment]
|
639
|
+
end
|
640
|
+
|
641
|
+
def puppet_git_init
|
642
|
+
config[:puppet_git_init]
|
643
|
+
end
|
644
|
+
|
645
|
+
def puppet_git_pr
|
646
|
+
config[:puppet_git_pr]
|
647
|
+
end
|
648
|
+
|
649
|
+
def hiera_config
|
650
|
+
config[:hiera_config_path]
|
651
|
+
end
|
652
|
+
|
653
|
+
def fileserver_config
|
654
|
+
config[:fileserver_config_path]
|
655
|
+
end
|
656
|
+
|
657
|
+
def hiera_data
|
658
|
+
config[:hiera_data_path]
|
659
|
+
end
|
660
|
+
|
661
|
+
def hiera_data_remote_path
|
662
|
+
config[:hiera_data_remote_path]
|
663
|
+
end
|
664
|
+
|
665
|
+
def hiera_eyaml
|
666
|
+
config[:hiera_eyaml]
|
667
|
+
end
|
668
|
+
|
669
|
+
def hiera_eyaml_key_path
|
670
|
+
config[:hiera_eyaml_key_path]
|
671
|
+
end
|
672
|
+
|
673
|
+
def hiera_eyaml_key_remote_path
|
674
|
+
config[:hiera_eyaml_key_remote_path]
|
675
|
+
end
|
676
|
+
|
677
|
+
def hiera_deep_merge
|
678
|
+
config[:hiera_deep_merge]
|
679
|
+
end
|
680
|
+
|
681
|
+
def librarian_puppet_ssl_file
|
682
|
+
config[:librarian_puppet_ssl_file]
|
683
|
+
end
|
684
|
+
|
685
|
+
def puppet_cmd
|
686
|
+
puppet_bin = 'puppet'
|
687
|
+
if config[:require_puppet_collections]
|
688
|
+
puppet_bin = "#{config[:puppet_coll_remote_path]}/bin/puppet"
|
689
|
+
end
|
690
|
+
|
691
|
+
if config[:puppet_no_sudo]
|
692
|
+
puppet_bin
|
693
|
+
else
|
694
|
+
sudo_env(puppet_bin)
|
695
|
+
end
|
696
|
+
end
|
697
|
+
|
698
|
+
def puppet_dir
|
699
|
+
if config[:require_puppet_collections]
|
700
|
+
'/etc/puppetlabs/puppet'
|
701
|
+
else
|
702
|
+
'/etc/puppet'
|
703
|
+
end
|
704
|
+
end
|
705
|
+
|
706
|
+
def hiera_config_dir
|
707
|
+
if config[:require_puppet_collections]
|
708
|
+
'/etc/puppetlabs/code'
|
709
|
+
else
|
710
|
+
'/etc/puppet'
|
711
|
+
end
|
712
|
+
end
|
713
|
+
|
714
|
+
def puppet_debian_version
|
715
|
+
config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
|
716
|
+
end
|
717
|
+
|
718
|
+
def facter_debian_version
|
719
|
+
config[:facter_version] ? "=#{config[:facter_version]}" : nil
|
720
|
+
end
|
721
|
+
|
722
|
+
def puppet_hiera_debian_version
|
723
|
+
config[:hiera_version] ? "=#{config[:hiera_version]}" : nil
|
724
|
+
end
|
725
|
+
|
726
|
+
def puppet_redhat_version
|
727
|
+
if puppet_platform == 'amazon'
|
728
|
+
config[:puppet_version]
|
729
|
+
else
|
730
|
+
config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
|
731
|
+
end
|
732
|
+
end
|
733
|
+
|
734
|
+
def puppet_environment_flag
|
735
|
+
if config[:puppet_version] =~ /^2/
|
736
|
+
config[:puppet_environment] ? "--environment=#{config[:puppet_environment]}" : nil
|
737
|
+
else
|
738
|
+
config[:puppet_environment] ? "--environment=#{config[:puppet_environment]} --environmentpath=#{puppet_dir}" : nil
|
739
|
+
end
|
740
|
+
end
|
741
|
+
|
742
|
+
def puppet_manifestdir
|
743
|
+
return nil if config[:require_puppet_collections]
|
744
|
+
return nil if config[:puppet_environment]
|
745
|
+
bash_vars = "export MANIFESTDIR='#{File.join(config[:root_path], 'manifests')}';"
|
746
|
+
debug(bash_vars)
|
747
|
+
bash_vars
|
748
|
+
end
|
749
|
+
|
750
|
+
def custom_options
|
751
|
+
config[:custom_options] || ''
|
752
|
+
end
|
753
|
+
|
754
|
+
def puppet_noop_flag
|
755
|
+
config[:puppet_noop] ? '--noop' : nil
|
756
|
+
end
|
757
|
+
|
758
|
+
def puppet_debug_flag
|
759
|
+
config[:puppet_debug] ? '-d' : nil
|
760
|
+
end
|
761
|
+
|
762
|
+
def puppet_verbose_flag
|
763
|
+
config[:puppet_verbose] ? '-v' : nil
|
764
|
+
end
|
765
|
+
|
766
|
+
def puppet_logdest_flag
|
767
|
+
return nil unless config[:puppet_logdest]
|
768
|
+
destinations = ''
|
769
|
+
config[:puppet_logdest].each do |dest|
|
770
|
+
destinations << "--logdest #{dest} "
|
771
|
+
end
|
772
|
+
destinations
|
773
|
+
end
|
774
|
+
|
775
|
+
def puppet_platform
|
776
|
+
config[:platform].gsub(/-.*/, '')
|
777
|
+
end
|
778
|
+
|
779
|
+
def update_packages_debian_cmd
|
780
|
+
config[:update_package_repos] ? "#{sudo_env('apt-get')} update" : nil
|
781
|
+
end
|
782
|
+
|
783
|
+
def update_packages_redhat_cmd
|
784
|
+
# #{sudo('yum')}
|
785
|
+
config[:update_package_repos] ? "#{sudo_env('yum')} makecache" : nil
|
786
|
+
end
|
787
|
+
|
788
|
+
def sudo_env(pm)
|
789
|
+
s = https_proxy ? "https_proxy=#{https_proxy}" : nil
|
790
|
+
p = http_proxy ? "http_proxy=#{http_proxy}" : nil
|
791
|
+
p || s ? "#{sudo('env')} #{p} #{s} #{pm}" : sudo(pm).to_s
|
792
|
+
end
|
793
|
+
|
794
|
+
def remove_puppet_repo
|
795
|
+
config[:remove_puppet_repo]
|
796
|
+
end
|
797
|
+
|
798
|
+
def spec_files_path
|
799
|
+
config[:spec_files_path]
|
800
|
+
end
|
801
|
+
|
802
|
+
def spec_files_remote_path
|
803
|
+
config[:spec_files_remote_path]
|
804
|
+
end
|
805
|
+
|
806
|
+
def facterlib
|
807
|
+
factpath = nil
|
808
|
+
factpath = File.join(config[:root_path], 'facter').to_s if config[:install_custom_facts] && !config[:custom_facts].none?
|
809
|
+
factpath = File.join(config[:root_path], 'facter').to_s if config[:facter_file]
|
810
|
+
factpath = "#{factpath}:" if config[:facterlib] && !factpath.nil?
|
811
|
+
factpath = "#{factpath}#{config[:facterlib]}" if config[:facterlib]
|
812
|
+
return nil if factpath.nil?
|
813
|
+
bash_vars = "export FACTERLIB='#{factpath}';"
|
814
|
+
debug(bash_vars)
|
815
|
+
bash_vars
|
816
|
+
end
|
817
|
+
|
818
|
+
def custom_facts
|
819
|
+
return nil if config[:custom_facts].none?
|
820
|
+
return nil if config[:install_custom_facts]
|
821
|
+
bash_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
|
822
|
+
bash_vars = "export #{bash_vars};"
|
823
|
+
debug(bash_vars)
|
824
|
+
bash_vars
|
825
|
+
end
|
826
|
+
|
827
|
+
def puppet_enc_flag
|
828
|
+
config[:puppet_enc] ? "--node_terminus=exec --external_nodes=#{config[:root_path]}/enc/#{File.basename(config[:puppet_enc])}" : nil
|
829
|
+
end
|
830
|
+
|
831
|
+
def puppet_detailed_exitcodes_flag
|
832
|
+
config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
|
833
|
+
end
|
834
|
+
|
835
|
+
def remove_repo
|
836
|
+
remove_puppet_repo ? "#{sudo('rm')} -rf /tmp/kitchen #{hiera_data_remote_path} #{hiera_eyaml_key_remote_path} #{puppet_dir}/* " : nil
|
837
|
+
end
|
838
|
+
|
839
|
+
def puppet_whitelist_exit_code
|
840
|
+
config[:puppet_whitelist_exit_code] ? "; [ $? -eq #{config[:puppet_whitelist_exit_code]} ] && exit 0" : nil
|
841
|
+
end
|
842
|
+
|
843
|
+
def puppet_apt_repo
|
844
|
+
platform_version = config[:platform].partition('-')[2]
|
845
|
+
case puppet_platform
|
846
|
+
when 'ubuntu'
|
847
|
+
case platform_version
|
848
|
+
when '14.10'
|
849
|
+
# Utopic Repo
|
850
|
+
'https://apt.puppetlabs.com/puppetlabs-release-utopic.deb'
|
851
|
+
when '14.04'
|
852
|
+
# Trusty Repo
|
853
|
+
'https://apt.puppetlabs.com/puppetlabs-release-trusty.deb'
|
854
|
+
when '12.04'
|
855
|
+
# Precise Repo
|
856
|
+
'https://apt.puppetlabs.com/puppetlabs-release-precise.deb'
|
857
|
+
else
|
858
|
+
# Configured Repo
|
859
|
+
config[:puppet_apt_repo]
|
860
|
+
end
|
861
|
+
when 'debian'
|
862
|
+
case platform_version.gsub(/\..*/, '')
|
863
|
+
when '8'
|
864
|
+
# Debian Jessie
|
865
|
+
'https://apt.puppetlabs.com/puppetlabs-release-jessie.deb'
|
866
|
+
when '7'
|
867
|
+
# Debian Wheezy
|
868
|
+
'https://apt.puppetlabs.com/puppetlabs-release-wheezy.deb'
|
869
|
+
when '6'
|
870
|
+
# Debian Squeeze
|
871
|
+
'https://apt.puppetlabs.com/puppetlabs-release-squeeze.deb'
|
872
|
+
else
|
873
|
+
# Configured Repo
|
874
|
+
config[:puppet_apt_repo]
|
875
|
+
end
|
876
|
+
else
|
877
|
+
debug("Apt repo detection failed with platform - #{config[:platform]}")
|
878
|
+
false
|
879
|
+
end
|
880
|
+
end
|
881
|
+
|
882
|
+
def puppet_apt_repo_file
|
883
|
+
puppet_apt_repo.split('/').last if puppet_apt_repo
|
884
|
+
end
|
885
|
+
|
886
|
+
def puppet_apt_coll_repo_file
|
887
|
+
config[:puppet_apt_collections_repo].split('/').last
|
888
|
+
end
|
889
|
+
|
890
|
+
def puppet_yum_repo
|
891
|
+
config[:puppet_yum_repo]
|
892
|
+
end
|
893
|
+
|
894
|
+
def proxy_parm
|
895
|
+
http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
|
896
|
+
end
|
897
|
+
|
898
|
+
def gem_proxy_parm
|
899
|
+
http_proxy ? "--http-proxy #{http_proxy}" : nil
|
900
|
+
end
|
901
|
+
|
902
|
+
def wget_proxy_parm
|
903
|
+
p = http_proxy ? "-e http_proxy=#{http_proxy}" : nil
|
904
|
+
s = https_proxy ? "-e https_proxy=#{https_proxy}" : nil
|
905
|
+
p || s ? "-e use_proxy=yes #{p} #{s}" : nil
|
906
|
+
end
|
907
|
+
|
908
|
+
def export_http_proxy_parm
|
909
|
+
http_proxy ? "export http_proxy=#{http_proxy}" : nil
|
910
|
+
end
|
911
|
+
|
912
|
+
def export_https_proxy_parm
|
913
|
+
http_proxy ? "export https_proxy=#{http_proxy}" : nil
|
914
|
+
end
|
915
|
+
|
916
|
+
def http_proxy
|
917
|
+
config[:http_proxy]
|
918
|
+
end
|
919
|
+
|
920
|
+
def https_proxy
|
921
|
+
config[:https_proxy]
|
922
|
+
end
|
923
|
+
|
924
|
+
def chef_url
|
925
|
+
config[:chef_bootstrap_url]
|
926
|
+
end
|
927
|
+
|
928
|
+
def prepare_manifests
|
929
|
+
info('Preparing manifests')
|
930
|
+
debug("Using manifests from #{manifests}")
|
931
|
+
|
932
|
+
tmp_manifests_dir = File.join(sandbox_path, 'manifests')
|
933
|
+
FileUtils.mkdir_p(tmp_manifests_dir)
|
934
|
+
FileUtils.cp_r(Dir.glob("#{manifests}/*"), tmp_manifests_dir)
|
935
|
+
end
|
936
|
+
|
937
|
+
def prepare_files
|
938
|
+
info('Preparing files')
|
939
|
+
unless File.directory?(files)
|
940
|
+
info 'nothing to do for files'
|
941
|
+
return
|
942
|
+
end
|
943
|
+
|
944
|
+
debug("Using files from #{files}")
|
945
|
+
|
946
|
+
tmp_files_dir = File.join(sandbox_path, 'files')
|
947
|
+
FileUtils.mkdir_p(tmp_files_dir)
|
948
|
+
FileUtils.cp_r(Dir.glob("#{files}/*"), tmp_files_dir)
|
949
|
+
end
|
950
|
+
|
951
|
+
def prepare_facter_file
|
952
|
+
return unless config[:facter_file]
|
953
|
+
info 'Copying facter file'
|
954
|
+
facter_dir = File.join(sandbox_path, 'facter')
|
955
|
+
FileUtils.mkdir_p(facter_dir)
|
956
|
+
FileUtils.cp_r(config[:facter_file], facter_dir)
|
957
|
+
end
|
958
|
+
|
959
|
+
def prepare_facts
|
960
|
+
return unless config[:install_custom_facts]
|
961
|
+
return unless config[:custom_facts]
|
962
|
+
info 'Installing custom facts'
|
963
|
+
facter_dir = File.join(sandbox_path, 'facter')
|
964
|
+
FileUtils.mkdir_p(facter_dir)
|
965
|
+
tmp_facter_file = File.join(facter_dir, 'kitchen.rb')
|
966
|
+
facter_facts = Hash[config[:custom_facts].map { |k, v| [k.to_s, v.to_s] }]
|
967
|
+
File.open(tmp_facter_file, 'a') do |out|
|
968
|
+
facter_facts.each do |k, v|
|
969
|
+
out.write "\nFacter.add(:#{k}) do\n"
|
970
|
+
out.write " setcode do\n"
|
971
|
+
out.write " \"#{v}\"\n"
|
972
|
+
out.write " end\n"
|
973
|
+
out.write "end\n"
|
974
|
+
end
|
975
|
+
end
|
976
|
+
end
|
977
|
+
|
978
|
+
def prepare_modules
|
979
|
+
info('Preparing modules')
|
980
|
+
|
981
|
+
FileUtils.mkdir_p(tmpmodules_dir)
|
982
|
+
resolve_with_librarian if File.exist?(puppetfile) && config[:resolve_with_librarian_puppet]
|
983
|
+
|
984
|
+
if modules && modules.include?(':')
|
985
|
+
debug('Found multiple directories in module path merging.....')
|
986
|
+
modules_array = modules.split(':')
|
987
|
+
modules_array.each do |m|
|
988
|
+
if File.directory?(m)
|
989
|
+
debug("Copying modules from #{m} to #{tmpmodules_dir}")
|
990
|
+
FileUtils.cp_r(Dir.glob("#{m}/*"), tmpmodules_dir, remove_destination: true)
|
991
|
+
end
|
992
|
+
end
|
993
|
+
elsif modules && File.directory?(modules)
|
994
|
+
debug("Copying modules from #{modules} to #{tmpmodules_dir}")
|
995
|
+
FileUtils.cp_r(Dir.glob("#{modules}/*"), tmpmodules_dir, remove_destination: true)
|
996
|
+
else
|
997
|
+
info 'nothing to do for modules'
|
998
|
+
end
|
999
|
+
|
1000
|
+
copy_self_as_module
|
1001
|
+
end
|
1002
|
+
|
1003
|
+
def copy_self_as_module
|
1004
|
+
if File.exist?(modulefile)
|
1005
|
+
warn('Modulefile found but this is depricated, ignoring it, see https://tickets.puppetlabs.com/browse/PUP-1188')
|
1006
|
+
end
|
1007
|
+
|
1008
|
+
return unless File.exist?(metadata_json)
|
1009
|
+
module_name = nil
|
1010
|
+
begin
|
1011
|
+
module_name = JSON.parse(IO.read(metadata_json))['name'].split('-').last
|
1012
|
+
rescue
|
1013
|
+
error("not able to load or parse #{metadata_json_path} for the name of the module")
|
1014
|
+
end
|
1015
|
+
|
1016
|
+
return unless module_name
|
1017
|
+
module_target_path = File.join(sandbox_path, 'modules', module_name)
|
1018
|
+
FileUtils.mkdir_p(module_target_path)
|
1019
|
+
|
1020
|
+
excluded_paths = %w(modules spec pkg) + config[:ignored_paths_from_root]
|
1021
|
+
|
1022
|
+
FileUtils.cp_r(
|
1023
|
+
Dir.glob(File.join(config[:kitchen_root], '*')).reject { |entry| entry =~ /#{excluded_paths.join('$|')}$/ },
|
1024
|
+
module_target_path,
|
1025
|
+
remove_destination: true
|
1026
|
+
)
|
1027
|
+
end
|
1028
|
+
|
1029
|
+
def prepare_puppet_config
|
1030
|
+
return unless puppet_config
|
1031
|
+
|
1032
|
+
info('Preparing puppet.conf')
|
1033
|
+
debug("Using puppet config from #{puppet_config}")
|
1034
|
+
|
1035
|
+
FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
|
1036
|
+
end
|
1037
|
+
|
1038
|
+
def prepare_enc
|
1039
|
+
return unless config[:puppet_enc]
|
1040
|
+
info 'Copying enc file'
|
1041
|
+
enc_dir = File.join(sandbox_path, 'enc')
|
1042
|
+
FileUtils.mkdir_p(enc_dir)
|
1043
|
+
FileUtils.cp_r(config[:puppet_enc], File.join(enc_dir,'/'))
|
1044
|
+
end
|
1045
|
+
|
1046
|
+
def prepare_hiera_config
|
1047
|
+
return unless hiera_config
|
1048
|
+
|
1049
|
+
info('Preparing hiera')
|
1050
|
+
debug("Using hiera from #{hiera_config}")
|
1051
|
+
|
1052
|
+
FileUtils.cp_r(hiera_config, File.join(sandbox_path, 'hiera.yaml'))
|
1053
|
+
end
|
1054
|
+
|
1055
|
+
def prepare_fileserver_config
|
1056
|
+
return unless fileserver_config
|
1057
|
+
|
1058
|
+
info('Preparing fileserver')
|
1059
|
+
debug("Using fileserver config from #{fileserver_config}")
|
1060
|
+
|
1061
|
+
FileUtils.cp_r(fileserver_config, File.join(sandbox_path, 'fileserver.conf'))
|
1062
|
+
end
|
1063
|
+
|
1064
|
+
def prepare_hiera_data
|
1065
|
+
return unless hiera_data
|
1066
|
+
info('Preparing hiera data')
|
1067
|
+
tmp_hiera_dir = File.join(sandbox_path, 'hiera')
|
1068
|
+
debug("Copying hiera data from #{hiera_data} to #{tmp_hiera_dir}")
|
1069
|
+
FileUtils.mkdir_p(tmp_hiera_dir)
|
1070
|
+
FileUtils.cp_r(Dir.glob("#{hiera_data}/*"), tmp_hiera_dir)
|
1071
|
+
return unless hiera_eyaml_key_path
|
1072
|
+
tmp_hiera_key_dir = File.join(sandbox_path, 'hiera_keys')
|
1073
|
+
debug("Copying hiera eyaml keys from #{hiera_eyaml_key_path} to #{tmp_hiera_key_dir}")
|
1074
|
+
FileUtils.mkdir_p(tmp_hiera_key_dir)
|
1075
|
+
FileUtils.cp_r(Dir.glob("#{hiera_eyaml_key_path}/*"), tmp_hiera_key_dir)
|
1076
|
+
end
|
1077
|
+
|
1078
|
+
def prepare_spec_files
|
1079
|
+
return unless spec_files_path
|
1080
|
+
info('Preparing spec files')
|
1081
|
+
tmp_spec_dir = File.join(sandbox_path, 'spec')
|
1082
|
+
debug("Copying specs from #{spec_files_path} to #{tmp_spec_dir}")
|
1083
|
+
FileUtils.mkdir_p(tmp_spec_dir)
|
1084
|
+
FileUtils.cp_r(Dir.glob(File.join(spec_files_path, '*')).reject { |entry| entry =~ /fixtures$/ }, tmp_spec_dir) if config[:ignore_spec_fixtures]
|
1085
|
+
FileUtils.cp_r(Dir.glob("#{spec_files_path}/*"), tmp_spec_dir) unless config[:ignore_spec_fixtures]
|
1086
|
+
end
|
1087
|
+
|
1088
|
+
def resolve_with_librarian
|
1089
|
+
Kitchen.mutex.synchronize do
|
1090
|
+
ENV['SSL_CERT_FILE'] = librarian_puppet_ssl_file if librarian_puppet_ssl_file
|
1091
|
+
Puppet::Librarian.new(puppetfile, tmpmodules_dir, logger).resolve
|
1092
|
+
ENV['SSL_CERT_FILE'] = '' if librarian_puppet_ssl_file
|
1093
|
+
end
|
1094
|
+
end
|
1095
|
+
end
|
1096
|
+
end
|
1097
|
+
end
|
1098
|
+
|
data/provisioner_options.md
CHANGED
@@ -79,7 +79,7 @@ puppet_noop| false| puppet runs in a no-op or dry-run mode
|
|
79
79
|
puppet_no_sudo | false | allow puppet command to run without sudo if required
|
80
80
|
puppet_verbose| false| Extra information logging on puppet run
|
81
81
|
puppet_version | "latest"| desired version, affects apt installs.
|
82
|
-
puppet_whitelist_exit_code | nil | Whitelist exit code expected from puppet run. Intended to be used together with `puppet_detailed_exitcodes`.
|
82
|
+
puppet_whitelist_exit_code | nil | Whitelist exit code expected from puppet run. Intended to be used together with `puppet_detailed_exitcodes`. You can also specify a yaml list here (you should use 0 and 2 for `puppet_detailed_exitcodes` to capture puppet runtime errors and allow multiple converge runs (without changes)).
|
83
83
|
puppet_yum_repo | "https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm"| yum repo RH/Centos6
|
84
84
|
_for RH/Centos7 change to_ | "https://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm" |
|
85
85
|
puppet_yum_collections_repo | "http://yum.puppetlabs.com/puppetlabs-release-pc1-el-6.noarch.rpm" | yum collections repo RH/Centos6
|
@@ -293,3 +293,28 @@ Use a `Rakefile` similar to one in https://github.com/vincentbernat/serverspec-e
|
|
293
293
|
With such approach we can achieve flexibility of running same test suite both in test kitchen and actual, even production, instances.
|
294
294
|
|
295
295
|
Beware: kitchen-shell-verifier is not yet merged into test-kitchen upstream so using separate gem is unavoidable so far
|
296
|
+
|
297
|
+
## Checking puppet apply success (with puppet_detailed_exitcodes)
|
298
|
+
|
299
|
+
If you do not enable puppet_detailed_exitcodes, the provisioner only failes if the manifest can not be compiled. If the manifest contains errors (some manifests can not be executed) puppet will return exit 0 and thus the provisioner will be successfull, altought your catalog has not been fully applied. Probably this is not what you want.
|
300
|
+
|
301
|
+
When you enable `puppet_detailed_exitcodes`, you can specify the error conditions to check for with `puppet_whitelist_exit_code` also, otherwise the provisioner will fail altought everything is fine (and changes have been made).
|
302
|
+
|
303
|
+
Puppet will return with one of the following codes (see https://docs.puppet.com/puppet/latest/man/agent.html) when `puppet_detailed_exitcodes` is true:
|
304
|
+
|
305
|
+
* 0: The run succeeded with no changes or failures; the system was already in the desired state.
|
306
|
+
* 1: The run failed, or wasn't attempted due to another run already in progress.
|
307
|
+
* 2: The run succeeded, and some resources were changed.
|
308
|
+
* 4: The run succeeded, and some resources failed.
|
309
|
+
* 6: The run succeeded, and included both changes and failures.
|
310
|
+
|
311
|
+
If you enable `puppet_detailed_exitcodes` you should should probably set `puppet_whitelist_exit_code` to 0 and 2
|
312
|
+
|
313
|
+
```yaml
|
314
|
+
provisioner:
|
315
|
+
puppet_detailed_exitcodes: true
|
316
|
+
puppet_whitelist_exit_code:
|
317
|
+
- 0
|
318
|
+
- 2
|
319
|
+
```
|
320
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.45.
|
4
|
+
version: 1.45.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neill Turner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-kitchen
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- lib/kitchen/provisioner/puppet/librarian.rb
|
60
60
|
- lib/kitchen/provisioner/puppet_agent.rb
|
61
61
|
- lib/kitchen/provisioner/puppet_apply.rb
|
62
|
+
- lib/kitchen/provisioner/puppet_apply.rb.new
|
62
63
|
- provisioner_options.md
|
63
64
|
homepage: https://github.com/neillturner/kitchen-puppet
|
64
65
|
licenses:
|