kitchen-puppet 3.4.2 → 3.5.0
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.
- checksums.yaml +4 -4
- data/README.md +283 -283
- data/kitchen-puppet.gemspec +33 -32
- data/lib/kitchen-puppet/version.rb +7 -7
- data/lib/kitchen/provisioner/puppet/librarian.rb +111 -111
- data/lib/kitchen/provisioner/puppet/r10k.rb +73 -73
- data/lib/kitchen/provisioner/puppet_agent.rb +430 -430
- data/lib/kitchen/provisioner/puppet_apply.rb +1465 -1465
- data/lib/kitchen/provisioner/puppet_bolt.rb +307 -307
- data/provisioner_options.md +412 -411
- metadata +19 -6
@@ -1,1465 +1,1465 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
#
|
4
|
-
# Author:: Chris Lundquist (<chris.lundquist@github.com>) Neill Turner (<neillwturner@gmail.com>)
|
5
|
-
#
|
6
|
-
# Copyright (C) 2013,2014 Chris Lundquist, Neill Turner
|
7
|
-
#
|
8
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
-
# you may not use this file except in compliance with the License.
|
10
|
-
# You may obtain a copy of the License at
|
11
|
-
#
|
12
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
-
#
|
14
|
-
# Unless required by applicable law or agreed to in writing, software
|
15
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
-
# See the License for the specific language governing permissions and
|
18
|
-
# limitations under the License.
|
19
|
-
#
|
20
|
-
# See https://github.com/neillturner/kitchen-puppet/blob/master/provisioner_options.md
|
21
|
-
# for documentation configuration parameters with puppet_apply provisioner.
|
22
|
-
#
|
23
|
-
|
24
|
-
require 'uri'
|
25
|
-
require 'json'
|
26
|
-
require 'kitchen'
|
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, true
|
49
|
-
default_config :puppet_yum_collections_repo, 'http://yum.puppetlabs.com/puppet5/puppet5-release-el-6.noarch.rpm'
|
50
|
-
default_config :puppet_apt_collections_repo, 'http://apt.puppetlabs.com/puppet5-release-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 :hiera_writer_files, nil
|
58
|
-
default_config :require_puppet_repo, true
|
59
|
-
default_config :require_chef_for_busser, true
|
60
|
-
default_config :resolve_with_librarian_puppet, true
|
61
|
-
default_config :resolve_with_r10k, false
|
62
|
-
default_config :puppet_environment, nil
|
63
|
-
default_config :puppet_environment_config_path do |provisioner|
|
64
|
-
provisioner.calculate_path('environment.conf')
|
65
|
-
end
|
66
|
-
default_config :puppet_environment_remote_modules_path, 'modules'
|
67
|
-
default_config :puppet_environment_remote_manifests_path, 'manifests'
|
68
|
-
default_config :puppet_environment_remote_hieradata_path, 'hieradata'
|
69
|
-
default_config :puppet_environment_hiera_config_path do |provisioner|
|
70
|
-
provisioner.calculate_path('hiera.yaml', :file)
|
71
|
-
end
|
72
|
-
default_config :puppet_apt_repo, 'http://apt.puppetlabs.com/puppetlabs-release-precise.deb'
|
73
|
-
default_config :puppet_yum_repo, 'https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm'
|
74
|
-
default_config :chef_bootstrap_url, 'https://www.chef.io/chef/install.sh'
|
75
|
-
default_config :puppet_logdest, nil
|
76
|
-
default_config :custom_install_command, nil
|
77
|
-
default_config :custom_pre_install_command, nil
|
78
|
-
default_config :custom_pre_apply_command, nil
|
79
|
-
default_config :custom_post_apply_command, nil
|
80
|
-
default_config :puppet_whitelist_exit_code, nil
|
81
|
-
default_config :require_puppet_omnibus, false
|
82
|
-
default_config :puppet_omnibus_url, 'https://raw.githubusercontent.com/petems/puppet-install-shell/master/
|
83
|
-
default_config :puppet_enc, nil
|
84
|
-
default_config :ignore_spec_fixtures, false
|
85
|
-
|
86
|
-
default_config :puppet_apply_command, nil
|
87
|
-
|
88
|
-
default_config :puppet_git_init, nil
|
89
|
-
default_config :puppet_git_pr, nil
|
90
|
-
|
91
|
-
default_config :http_proxy, nil
|
92
|
-
default_config :https_proxy, nil
|
93
|
-
default_config :no_proxy, nil
|
94
|
-
|
95
|
-
default_config :ignored_paths_from_root, ['spec']
|
96
|
-
default_config :hiera_data_remote_path, nil
|
97
|
-
default_config :manifest, ''
|
98
|
-
default_config :puppet_binary, 'puppet'
|
99
|
-
|
100
|
-
default_config :manifests_path do |provisioner|
|
101
|
-
provisioner.calculate_path('manifests') ||
|
102
|
-
raise('No manifests_path detected. Please specify one in .kitchen.yml')
|
103
|
-
end
|
104
|
-
|
105
|
-
default_config :modules_path do |provisioner|
|
106
|
-
modules_path = provisioner.calculate_path('modules')
|
107
|
-
if modules_path.nil? && provisioner.calculate_path('Puppetfile', :file).nil?
|
108
|
-
raise('No modules_path detected. Please specify one in .kitchen.yml')
|
109
|
-
end
|
110
|
-
modules_path
|
111
|
-
end
|
112
|
-
|
113
|
-
default_config :files_path do |provisioner|
|
114
|
-
provisioner.calculate_path('files') || 'files'
|
115
|
-
end
|
116
|
-
|
117
|
-
default_config :hiera_data_path do |provisioner|
|
118
|
-
provisioner.calculate_path('hiera')
|
119
|
-
end
|
120
|
-
|
121
|
-
default_config :puppet_config_path do |provisioner|
|
122
|
-
provisioner.calculate_path('puppet.conf', :file)
|
123
|
-
end
|
124
|
-
|
125
|
-
default_config :hiera_config_path do |provisioner|
|
126
|
-
provisioner.calculate_path('hiera.global.yaml', :file) ||
|
127
|
-
provisioner.calculate_path('hiera.yaml', :file)
|
128
|
-
end
|
129
|
-
|
130
|
-
default_config :fileserver_config_path do |provisioner|
|
131
|
-
provisioner.calculate_path('fileserver.conf', :file)
|
132
|
-
end
|
133
|
-
default_config :puppetfile_path do |provisioner|
|
134
|
-
provisioner.calculate_path('Puppetfile', :file)
|
135
|
-
end
|
136
|
-
|
137
|
-
default_config :modulefile_path do |provisioner|
|
138
|
-
provisioner.calculate_path('Modulefile', :file)
|
139
|
-
end
|
140
|
-
|
141
|
-
default_config :metadata_json_path do |provisioner|
|
142
|
-
provisioner.calculate_path('metadata.json', :file)
|
143
|
-
end
|
144
|
-
|
145
|
-
default_config :manifests_path do |provisioner|
|
146
|
-
provisioner.calculate_path('manifests', :directory)
|
147
|
-
end
|
148
|
-
|
149
|
-
default_config :spec_files_path do |provisioner|
|
150
|
-
provisioner.calculate_path('spec', :directory)
|
151
|
-
end
|
152
|
-
|
153
|
-
default_config :spec_files_remote_path, '/etc/puppet/spec'
|
154
|
-
|
155
|
-
default_config :puppet_debug, false
|
156
|
-
default_config :puppet_verbose, false
|
157
|
-
default_config :puppet_noop, false
|
158
|
-
default_config :puppet_show_diff, false
|
159
|
-
default_config :puppet_future_parser, false
|
160
|
-
default_config :platform, &:platform_name
|
161
|
-
default_config :update_package_repos, true
|
162
|
-
default_config :remove_puppet_repo, false
|
163
|
-
default_config :install_custom_facts, false
|
164
|
-
default_config :custom_facts, {}
|
165
|
-
default_config :facterlib, nil
|
166
|
-
default_config :puppet_detailed_exitcodes, nil
|
167
|
-
default_config :facter_file, nil
|
168
|
-
default_config :librarian_puppet_ssl_file, nil
|
169
|
-
default_config :r10k_ssl_file, nil
|
170
|
-
|
171
|
-
default_config :hiera_eyaml, false
|
172
|
-
default_config :hiera_eyaml_key_remote_path, '/etc/puppet/secure/keys'
|
173
|
-
default_config :puppet_environmentpath_remote_path, nil
|
174
|
-
|
175
|
-
default_config :hiera_eyaml_gpg, false
|
176
|
-
default_config :hiera_eyaml_gpg_recipients, false
|
177
|
-
default_config :hiera_eyaml_gpg_secring, false
|
178
|
-
default_config :hiera_eyaml_gpg_pubring, false
|
179
|
-
default_config :hiera_eyaml_gpg_remote_path, '/home/vagrant/.gnupg'
|
180
|
-
|
181
|
-
default_config :hiera_eyaml_key_path do |provisioner|
|
182
|
-
provisioner.calculate_path('hiera_keys')
|
183
|
-
end
|
184
|
-
|
185
|
-
default_config :hiera_deep_merge, false
|
186
|
-
default_config :puppet_no_sudo, false
|
187
|
-
|
188
|
-
def calculate_path(path, type = :directory)
|
189
|
-
base = config[:test_base_path]
|
190
|
-
candidates = []
|
191
|
-
candidates << File.join(base, instance.suite.name, 'puppet', path)
|
192
|
-
candidates << File.join(base, instance.suite.name, path)
|
193
|
-
candidates << File.join(base, path)
|
194
|
-
candidates << File.join(Dir.pwd, path)
|
195
|
-
|
196
|
-
candidates.find do |c|
|
197
|
-
type == :directory ? File.directory?(c) : File.file?(c)
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
202
|
-
def install_command
|
203
|
-
return unless config[:require_puppet_collections] || config[:require_puppet_repo] || config[:require_puppet_omnibus]
|
204
|
-
if config[:require_puppet_omnibus]
|
205
|
-
install_omnibus_command
|
206
|
-
elsif config[:require_puppet_collections]
|
207
|
-
install_command_collections
|
208
|
-
else
|
209
|
-
case puppet_platform
|
210
|
-
when 'debian', 'ubuntu'
|
211
|
-
info("Installing puppet on #{config[:platform]}")
|
212
|
-
# need to add a CR to avoid trouble with proxy settings concatenation
|
213
|
-
<<-INSTALL
|
214
|
-
|
215
|
-
#{custom_pre_install_command}
|
216
|
-
if [ ! $(which puppet) ]; then
|
217
|
-
#{sudo('apt-get')} -y install wget
|
218
|
-
#{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
|
219
|
-
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
220
|
-
#{update_packages_debian_cmd}
|
221
|
-
#{sudo_env('apt-get')} -y install facter#{facter_debian_version}
|
222
|
-
#{sudo_env('apt-get')} -y install puppet-common#{puppet_debian_version}
|
223
|
-
#{sudo_env('apt-get')} -y install puppet#{puppet_debian_version}
|
224
|
-
#{install_hiera}
|
225
|
-
fi
|
226
|
-
#{install_eyaml}
|
227
|
-
#{install_eyaml_gpg}
|
228
|
-
#{install_deep_merge}
|
229
|
-
#{install_busser}
|
230
|
-
#{custom_install_command}
|
231
|
-
INSTALL
|
232
|
-
when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
|
233
|
-
info("Installing puppet from yum on #{puppet_platform}")
|
234
|
-
# need to add a CR to avoid trouble with proxy settings concatenation
|
235
|
-
<<-INSTALL
|
236
|
-
|
237
|
-
#{custom_pre_install_command}
|
238
|
-
if [ ! $(which puppet) ]; then
|
239
|
-
#{install_puppet_yum_repo}
|
240
|
-
fi
|
241
|
-
#{install_eyaml}
|
242
|
-
#{install_eyaml_gpg}
|
243
|
-
#{install_deep_merge}
|
244
|
-
#{install_busser}
|
245
|
-
#{custom_install_command}
|
246
|
-
INSTALL
|
247
|
-
when /^windows.*/
|
248
|
-
info("Installing puppet on #{puppet_platform}")
|
249
|
-
info('Powershell is not recognised by core test-kitchen assuming it is present') unless powershell_shell?
|
250
|
-
<<-INSTALL
|
251
|
-
if(Get-Command puppet -ErrorAction 0) { return; }
|
252
|
-
$architecture = if( [Environment]::Is64BitOperatingSystem ) { '-x64' } else { '' }
|
253
|
-
if( '#{puppet_windows_version}' -eq 'latest' ) {
|
254
|
-
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-agent-${architecture}-latest.msi"
|
255
|
-
} elseif( '#{puppet_windows_version}' -like '5.*' ) {
|
256
|
-
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet5/puppet-agent-#{puppet_windows_version}-${architecture}.msi"
|
257
|
-
} else {
|
258
|
-
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-#{puppet_windows_version}${architecture}.msi"
|
259
|
-
}
|
260
|
-
Invoke-WebRequest $MsiUrl -UseBasicParsing -OutFile "C:/puppet.msi" #{posh_proxy_parm}
|
261
|
-
$process = Start-Process -FilePath msiexec.exe -Wait -PassThru -ArgumentList '/qn', '/norestart', '/i', 'C:\\puppet.msi'
|
262
|
-
if ($process.ExitCode -ne 0) {
|
263
|
-
Write-Host "Installer failed."
|
264
|
-
Exit 1
|
265
|
-
}
|
266
|
-
|
267
|
-
#{install_busser}
|
268
|
-
INSTALL
|
269
|
-
else
|
270
|
-
info('Installing puppet, will try to determine platform os')
|
271
|
-
# need to add a CR to avoid trouble with proxy settings concatenation
|
272
|
-
<<-INSTALL
|
273
|
-
|
274
|
-
#{custom_pre_install_command}
|
275
|
-
if [ ! $(which puppet) ]; then
|
276
|
-
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
|
277
|
-
#{install_puppet_yum_repo}
|
278
|
-
else
|
279
|
-
if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
|
280
|
-
#{install_puppet_yum_repo}
|
281
|
-
else
|
282
|
-
#{sudo('apt-get')} -y install wget
|
283
|
-
#{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
|
284
|
-
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
285
|
-
#{update_packages_debian_cmd}
|
286
|
-
#{sudo_env('apt-get')} -y install facter#{facter_debian_version}
|
287
|
-
#{sudo_env('apt-get')} -y install puppet-common#{puppet_debian_version}
|
288
|
-
#{sudo_env('apt-get')} -y install puppet#{puppet_debian_version}
|
289
|
-
#{install_hiera}
|
290
|
-
fi
|
291
|
-
fi
|
292
|
-
fi
|
293
|
-
#{install_eyaml}
|
294
|
-
#{install_eyaml_gpg}
|
295
|
-
#{install_deep_merge}
|
296
|
-
#{install_busser}
|
297
|
-
#{custom_install_command}
|
298
|
-
INSTALL
|
299
|
-
end
|
300
|
-
end
|
301
|
-
end
|
302
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
303
|
-
|
304
|
-
def install_command_collections
|
305
|
-
case puppet_platform
|
306
|
-
when 'debian', 'ubuntu'
|
307
|
-
info("Installing Puppet Collections on #{puppet_platform}")
|
308
|
-
<<-INSTALL
|
309
|
-
|
310
|
-
#{Util.shell_helpers}
|
311
|
-
#{custom_pre_install_command}
|
312
|
-
if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
|
313
|
-
if [ ! -f "#{config[:puppet_apt_collections_repo]}" ]; then
|
314
|
-
#{sudo('apt-get')} -y install wget
|
315
|
-
#{sudo('wget')} #{wget_proxy_parm} #{config[:puppet_apt_collections_repo]}
|
316
|
-
fi
|
317
|
-
#{sudo('dpkg')} -i #{puppet_apt_coll_repo_file}
|
318
|
-
#{sudo('apt-get')} update
|
319
|
-
#{sudo_env('apt-get')} -y install puppet-agent#{puppet_debian_version}
|
320
|
-
fi
|
321
|
-
#{install_eyaml("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
322
|
-
#{install_eyaml_gpg("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
323
|
-
#{install_deep_merge}
|
324
|
-
#{install_busser}
|
325
|
-
#{custom_install_command}
|
326
|
-
INSTALL
|
327
|
-
when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
|
328
|
-
info("Installing Puppet Collections on #{puppet_platform}")
|
329
|
-
<<-INSTALL
|
330
|
-
|
331
|
-
#{Util.shell_helpers}
|
332
|
-
#{custom_pre_install_command}
|
333
|
-
if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
|
334
|
-
echo "-----> #{sudo_env('yum')} -y --nogpgcheck install #{config[:puppet_yum_collections_repo]}"
|
335
|
-
#{sudo_env('yum')} clean all
|
336
|
-
#{sudo_env('yum')} -y --nogpgcheck install #{config[:puppet_yum_collections_repo]}
|
337
|
-
#{sudo_env('yum')} -y --nogpgcheck install puppet-agent#{puppet_redhat_version}
|
338
|
-
fi
|
339
|
-
#{install_eyaml("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
340
|
-
#{install_eyaml_gpg("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
341
|
-
#{install_deep_merge}
|
342
|
-
#{install_busser}
|
343
|
-
#{custom_install_command}
|
344
|
-
INSTALL
|
345
|
-
when /^windows.*/
|
346
|
-
info("Installing Puppet Collections on #{puppet_platform}")
|
347
|
-
info('Powershell is not recognised by core test-kitchen assuming it is present') unless powershell_shell?
|
348
|
-
<<-INSTALL
|
349
|
-
if(Get-Command puppet -ErrorAction 0) { return; }
|
350
|
-
$architecture = if( [Environment]::Is64BitOperatingSystem ) { 'x64' } else { 'x86' }
|
351
|
-
if( '#{puppet_windows_version}' -eq 'latest' ) {
|
352
|
-
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-agent-${architecture}-latest.msi"
|
353
|
-
} elseif( '#{puppet_windows_version}' -like '5.*' ) {
|
354
|
-
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet5/puppet-agent-#{puppet_windows_version}-${architecture}.msi"
|
355
|
-
} else {
|
356
|
-
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-agent-#{puppet_windows_version}${architecture}.msi"
|
357
|
-
}
|
358
|
-
Invoke-WebRequest $MsiUrl -UseBasicParsing -OutFile "C:/puppet-agent.msi" #{posh_proxy_parm}
|
359
|
-
$process = Start-Process -FilePath msiexec.exe -Wait -PassThru -ArgumentList '/qn', '/norestart', '/i', 'C:\\puppet-agent.msi'
|
360
|
-
if ($process.ExitCode -ne 0) {
|
361
|
-
Write-Host "Installer failed."
|
362
|
-
Exit 1
|
363
|
-
}
|
364
|
-
|
365
|
-
#{install_busser}
|
366
|
-
INSTALL
|
367
|
-
else
|
368
|
-
info('Installing Puppet Collections, will try to determine platform os')
|
369
|
-
<<-INSTALL
|
370
|
-
|
371
|
-
#{Util.shell_helpers}
|
372
|
-
#{custom_pre_install_command}
|
373
|
-
if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
|
374
|
-
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ] || \
|
375
|
-
[ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
|
376
|
-
echo "-----> #{sudo_env('yum')} -y --nogpgcheck install #{config[:puppet_yum_collections_repo]}"
|
377
|
-
#{sudo_env('yum')} -y --nogpgcheck install #{config[:puppet_yum_collections_repo]}
|
378
|
-
#{sudo_env('yum')} -y --nogpgcheck install puppet-agent#{puppet_redhat_version}
|
379
|
-
else
|
380
|
-
#{sudo('apt-get')} -y install wget
|
381
|
-
#{sudo('wget')} #{wget_proxy_parm} #{config[:puppet_apt_collections_repo]}
|
382
|
-
#{sudo('dpkg')} -i #{puppet_apt_coll_repo_file}
|
383
|
-
#{sudo('apt-get')} update
|
384
|
-
#{sudo_env('apt-get')} -y install puppet-agent#{puppet_debian_version}
|
385
|
-
fi
|
386
|
-
fi
|
387
|
-
#{install_eyaml("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
388
|
-
#{install_eyaml_gpg("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
389
|
-
#{install_deep_merge}
|
390
|
-
#{install_busser}
|
391
|
-
#{custom_install_command}
|
392
|
-
INSTALL
|
393
|
-
end
|
394
|
-
end
|
395
|
-
|
396
|
-
def install_deep_merge
|
397
|
-
return unless config[:hiera_deep_merge]
|
398
|
-
<<-INSTALL
|
399
|
-
# Support for hash merge lookups to recursively merge hash keys
|
400
|
-
if [[ $(#{sudo('gem')} list deep_merge -i) == 'false' ]]; then
|
401
|
-
echo '-----> Installing deep_merge to provide deep_merge of hiera hashes'
|
402
|
-
#{sudo('gem')} install #{gem_proxy_parm} --no-ri --no-rdoc deep_merge
|
403
|
-
fi
|
404
|
-
INSTALL
|
405
|
-
end
|
406
|
-
|
407
|
-
def install_eyaml(gem_cmd = 'gem')
|
408
|
-
return unless config[:hiera_eyaml]
|
409
|
-
<<-INSTALL
|
410
|
-
# A backend for Hiera that provides per-value asymmetric encryption of sensitive data
|
411
|
-
if [[ $(#{sudo(gem_cmd)} list hiera-eyaml -i) == 'false' ]]; then
|
412
|
-
echo '-----> Installing hiera-eyaml to provide encryption of hiera data'
|
413
|
-
#{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc highline -v 1.6.21
|
414
|
-
#{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml
|
415
|
-
fi
|
416
|
-
INSTALL
|
417
|
-
end
|
418
|
-
|
419
|
-
def install_eyaml_gpg(gem_cmd = 'gem')
|
420
|
-
return unless config[:hiera_eyaml_gpg]
|
421
|
-
<<-INSTALL
|
422
|
-
# A backend for Hiera that provides per-value asymmetric encryption of sensitive data
|
423
|
-
if [[ $(#{sudo(gem_cmd)} list hiera-eyaml-gpg -i) == 'false' ]]; then
|
424
|
-
echo '-----> Installing hiera-eyaml-gpg to provide encryption of hiera data'
|
425
|
-
#{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc highline -v 1.6.21
|
426
|
-
#{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml
|
427
|
-
#{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml-gpg
|
428
|
-
#{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc ruby_gpg
|
429
|
-
fi
|
430
|
-
INSTALL
|
431
|
-
end
|
432
|
-
|
433
|
-
def install_busser
|
434
|
-
return unless config[:require_chef_for_busser]
|
435
|
-
info("Install busser on #{puppet_platform}")
|
436
|
-
case puppet_platform
|
437
|
-
when /^windows.*/
|
438
|
-
# https://raw.githubusercontent.com/opscode/knife-windows/master/lib/chef/knife/bootstrap/windows-chef-client-msi.erb
|
439
|
-
<<-INSTALL
|
440
|
-
$webclient = New-Object System.Net.WebClient; $webclient.DownloadFile('https://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chef-windows-11.12.8-1.windows.msi','chef-windows-11.12.8-1.windows.msi')
|
441
|
-
msiexec /qn /i chef-windows-11.12.8-1.windows.msi
|
442
|
-
|
443
|
-
cmd.exe /C "SET PATH=%PATH%;`"C:\\opscode\\chef\\embedded\\bin`";`"C:\\tmp\\busser\\gems\\bin`""
|
444
|
-
|
445
|
-
INSTALL
|
446
|
-
else
|
447
|
-
<<-INSTALL
|
448
|
-
#{Util.shell_helpers}
|
449
|
-
# install chef omnibus so that busser works as this is needed to run tests :(
|
450
|
-
# TODO: work out how to install enough ruby
|
451
|
-
# and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
|
452
|
-
# whole chef client
|
453
|
-
if [ ! -d "/opt/chef" ]
|
454
|
-
then
|
455
|
-
echo '-----> Installing Chef Omnibus to install busser to run tests'
|
456
|
-
#{export_http_proxy_parm}
|
457
|
-
#{export_https_proxy_parm}
|
458
|
-
#{export_no_proxy_parm}
|
459
|
-
do_download #{chef_url} /tmp/install.sh
|
460
|
-
#{sudo('sh')} /tmp/install.sh
|
461
|
-
fi
|
462
|
-
INSTALL
|
463
|
-
end
|
464
|
-
end
|
465
|
-
|
466
|
-
def install_omnibus_command
|
467
|
-
info('Installing puppet using puppet omnibus')
|
468
|
-
|
469
|
-
version = ''
|
470
|
-
version = "-v #{config[:puppet_version]}" unless config[:puppet_version].nil?
|
471
|
-
|
472
|
-
<<-INSTALL
|
473
|
-
#{Util.shell_helpers}
|
474
|
-
if [ ! $(which puppet) ]; then
|
475
|
-
echo "-----> Installing Puppet Omnibus"
|
476
|
-
#{export_http_proxy_parm}
|
477
|
-
#{export_https_proxy_parm}
|
478
|
-
#{export_no_proxy_parm}
|
479
|
-
do_download #{config[:puppet_omnibus_url]} /tmp/install_puppet.sh
|
480
|
-
#{sudo_env('sh')} /tmp/install_puppet.sh #{version}
|
481
|
-
fi
|
482
|
-
INSTALL
|
483
|
-
end
|
484
|
-
|
485
|
-
def install_hiera
|
486
|
-
return unless config[:install_hiera]
|
487
|
-
<<-INSTALL
|
488
|
-
#{sudo_env('apt-get')} -y install #{hiera_package}
|
489
|
-
INSTALL
|
490
|
-
end
|
491
|
-
|
492
|
-
def hiera_package
|
493
|
-
"#{config[:hiera_package]}#{puppet_hiera_debian_version}"
|
494
|
-
end
|
495
|
-
|
496
|
-
# /bin/wget -P /etc/pki/rpm-gpg/ http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
|
497
|
-
# changed to curl
|
498
|
-
|
499
|
-
def install_puppet_yum_repo
|
500
|
-
<<-INSTALL
|
501
|
-
rhelversion=$(cat /etc/redhat-release | grep 'release 7')
|
502
|
-
# For CentOS7/RHEL7 the rdo release contains puppetlabs repo, creating conflict. Create temp-repo
|
503
|
-
#{sudo_env('curl')} -o /etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
|
504
|
-
if [ -n "$rhelversion" ]; then
|
505
|
-
echo '[puppettemp-products]
|
506
|
-
name=Puppet Labs Products - \$basearch
|
507
|
-
baseurl=http://yum.puppetlabs.com/el/7/products/\$basearch
|
508
|
-
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs
|
509
|
-
enabled=0
|
510
|
-
gpgcheck=1
|
511
|
-
[puppettemp-deps]
|
512
|
-
name=Puppet Labs Dependencies - \$basearch
|
513
|
-
baseurl=http://yum.puppetlabs.com/el/7/dependencies/\$basearch
|
514
|
-
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs
|
515
|
-
enabled=0
|
516
|
-
gpgcheck=1' | sudo tee /etc/yum.repos.d/puppettemp.repo > /dev/null
|
517
|
-
sudo sed -i 's/^[ \t]*//' /etc/yum.repos.d/puppettemp.repo
|
518
|
-
#{update_packages_redhat_cmd}
|
519
|
-
#{sudo_env('yum')} -y --enablerepo=puppettemp-products --enablerepo=puppettemp-deps install puppet#{puppet_redhat_version}
|
520
|
-
# Clean up temporary puppet repo
|
521
|
-
sudo rm -rf /etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs
|
522
|
-
sudo rm -rf /etc/yum.repos.d/puppettemp.repo
|
523
|
-
else
|
524
|
-
#{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
|
525
|
-
#{update_packages_redhat_cmd}
|
526
|
-
#{sudo_env('yum')} -y --nogpgcheck install puppet#{puppet_redhat_version}
|
527
|
-
fi
|
528
|
-
INSTALL
|
529
|
-
end
|
530
|
-
|
531
|
-
def custom_pre_install_command
|
532
|
-
<<-INSTALL
|
533
|
-
#{config[:custom_pre_install_command]}
|
534
|
-
INSTALL
|
535
|
-
end
|
536
|
-
|
537
|
-
def custom_install_command
|
538
|
-
<<-INSTALL
|
539
|
-
#{config[:custom_install_command]}
|
540
|
-
INSTALL
|
541
|
-
end
|
542
|
-
|
543
|
-
def init_command
|
544
|
-
todelete = %w[modules manifests files hiera hiera.yaml hiera.global.yaml facter spec enc environment]
|
545
|
-
.map { |dir| File.join(config[:root_path], dir) }
|
546
|
-
todelete += [hiera_data_remote_path,
|
547
|
-
'/etc/hiera.yaml',
|
548
|
-
"#{puppet_dir}/hiera.yaml",
|
549
|
-
spec_files_remote_path.to_s,
|
550
|
-
"#{puppet_dir}/fileserver.conf"]
|
551
|
-
todelete << File.join(puppet_dir, puppet_environment) if puppet_environment
|
552
|
-
todelete << File.join(puppet_environmentpath_remote_path, puppet_environment) if puppet_environment_config && puppet_environment
|
553
|
-
cmd = "#{sudo(rm_command_paths(todelete))};"
|
554
|
-
cmd += " #{mkdir_command} #{config[:root_path]};"
|
555
|
-
cmd += " #{sudo(mkdir_command)} #{puppet_dir}"
|
556
|
-
debug(cmd)
|
557
|
-
cmd
|
558
|
-
end
|
559
|
-
|
560
|
-
def create_sandbox
|
561
|
-
super
|
562
|
-
debug("Creating local sandbox in #{sandbox_path}")
|
563
|
-
yield if block_given?
|
564
|
-
prepare_modules
|
565
|
-
prepare_manifests
|
566
|
-
prepare_files
|
567
|
-
prepare_facter_file
|
568
|
-
prepare_facts
|
569
|
-
prepare_puppet_config
|
570
|
-
prepare_hiera_config
|
571
|
-
prepare_puppet_environment
|
572
|
-
prepare_fileserver_config
|
573
|
-
prepare_hiera_data
|
574
|
-
prepare_enc
|
575
|
-
prepare_spec_files
|
576
|
-
info('Finished Preparing files for transfer')
|
577
|
-
end
|
578
|
-
|
579
|
-
def cleanup_sandbox
|
580
|
-
return if sandbox_path.nil?
|
581
|
-
debug("Cleaning up local sandbox in #{sandbox_path}")
|
582
|
-
FileUtils.rmtree(sandbox_path)
|
583
|
-
return if remove_repo.nil?
|
584
|
-
debug("Cleaning up remote sandbox: #{remove_repo}")
|
585
|
-
instance.remote_exec remove_repo
|
586
|
-
end
|
587
|
-
|
588
|
-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
589
|
-
def prepare_command
|
590
|
-
commands = []
|
591
|
-
if puppet_git_init
|
592
|
-
commands << [
|
593
|
-
sudo('rm -rf'), '/etc/puppet'
|
594
|
-
].join(' ')
|
595
|
-
|
596
|
-
commands << [
|
597
|
-
sudo('git clone'), puppet_git_init, '/etc/puppet'
|
598
|
-
].join(' ')
|
599
|
-
end
|
600
|
-
|
601
|
-
if puppet_git_pr
|
602
|
-
commands << [
|
603
|
-
sudo('git'),
|
604
|
-
'--git-dir=/etc/puppet/.git/',
|
605
|
-
'fetch -f',
|
606
|
-
'origin',
|
607
|
-
"pull/#{puppet_git_pr}/head:pr_#{puppet_git_pr}"
|
608
|
-
].join(' ')
|
609
|
-
|
610
|
-
commands << [
|
611
|
-
sudo('git'),
|
612
|
-
'--git-dir=/etc/puppet/.git/',
|
613
|
-
'--work-tree=/etc/puppet/',
|
614
|
-
'checkout',
|
615
|
-
"pr_#{puppet_git_pr}"
|
616
|
-
].join(' ')
|
617
|
-
end
|
618
|
-
|
619
|
-
if puppet_config
|
620
|
-
commands << [
|
621
|
-
sudo(cp_command),
|
622
|
-
File.join(config[:root_path], 'puppet.conf'),
|
623
|
-
puppet_dir
|
624
|
-
].join(' ')
|
625
|
-
end
|
626
|
-
|
627
|
-
if fileserver_config
|
628
|
-
commands << [
|
629
|
-
sudo(cp_command),
|
630
|
-
File.join(config[:root_path], 'fileserver.conf'),
|
631
|
-
puppet_dir
|
632
|
-
].join(' ')
|
633
|
-
end
|
634
|
-
|
635
|
-
if hiera_data
|
636
|
-
commands << [
|
637
|
-
sudo(mkdir_command), hiera_data_remote_path
|
638
|
-
].join(' ')
|
639
|
-
commands << [
|
640
|
-
sudo("#{cp_command} -r"), File.join(config[:root_path], 'hiera/*'), hiera_data_remote_path
|
641
|
-
].join(' ')
|
642
|
-
end
|
643
|
-
|
644
|
-
if hiera_eyaml
|
645
|
-
commands << [
|
646
|
-
sudo(mkdir_command), hiera_eyaml_key_remote_path
|
647
|
-
].join(' ')
|
648
|
-
commands << [
|
649
|
-
sudo("#{cp_command} -r"), File.join(config[:root_path], 'hiera_keys/*'), hiera_eyaml_key_remote_path
|
650
|
-
].join(' ')
|
651
|
-
end
|
652
|
-
|
653
|
-
if hiera_eyaml_gpg
|
654
|
-
commands << [
|
655
|
-
sudo('mkdir -p'), hiera_eyaml_gpg_remote_path
|
656
|
-
].join(' ')
|
657
|
-
commands << [
|
658
|
-
sudo('cp -r'), File.join(config[:root_path], hiera_eyaml_gpg_recipients), hiera_eyaml_gpg_remote_path
|
659
|
-
].join(' ')
|
660
|
-
commands << [
|
661
|
-
sudo('cp -r'), File.join(config[:root_path], hiera_eyaml_gpg_secring), hiera_eyaml_gpg_remote_path
|
662
|
-
].join(' ')
|
663
|
-
commands << [
|
664
|
-
sudo('cp -r'), File.join(config[:root_path], hiera_eyaml_gpg_pubring), hiera_eyaml_gpg_remote_path
|
665
|
-
].join(' ')
|
666
|
-
end
|
667
|
-
|
668
|
-
if puppet_environment
|
669
|
-
commands << [
|
670
|
-
sudo('ln -s '), config[:root_path], File.join(puppet_dir, puppet_environment)
|
671
|
-
].join(' ')
|
672
|
-
end
|
673
|
-
|
674
|
-
if puppet_environment_config && puppet_environment
|
675
|
-
commands << [
|
676
|
-
sudo(mkdir_command), puppet_environmentpath_remote_path
|
677
|
-
].join(' ')
|
678
|
-
commands << [
|
679
|
-
sudo(mkdir_command), File.join(puppet_environmentpath_remote_path, puppet_environment)
|
680
|
-
].join(' ')
|
681
|
-
commands << [
|
682
|
-
sudo('ln -s '), File.join(config[:root_path], 'modules'), File.join(puppet_environmentpath_remote_path, puppet_environment, puppet_environment_remote_modules_path)
|
683
|
-
].join(' ')
|
684
|
-
commands << [
|
685
|
-
sudo('ln -s '), File.join(config[:root_path], 'manifests'), File.join(puppet_environmentpath_remote_path, puppet_environment, puppet_environment_remote_manifests_path)
|
686
|
-
].join(' ')
|
687
|
-
commands << [
|
688
|
-
sudo('ln -s '), File.join(config[:root_path], 'hiera'), File.join(puppet_environmentpath_remote_path, puppet_environment, puppet_environment_remote_hieradata_path)
|
689
|
-
].join(' ')
|
690
|
-
commands << [
|
691
|
-
sudo('cp'), File.join(config[:root_path], 'environment', 'environment.conf'), File.join(puppet_environmentpath_remote_path, puppet_environment, 'environment.conf')
|
692
|
-
].join(' ')
|
693
|
-
commands << [
|
694
|
-
sudo('cp'), File.join(config[:root_path], 'environment', 'hiera.yaml'), File.join(puppet_environmentpath_remote_path, puppet_environment, 'hiera.yaml')
|
695
|
-
].join(' ')
|
696
|
-
end
|
697
|
-
|
698
|
-
if spec_files_path && spec_files_remote_path
|
699
|
-
commands << [
|
700
|
-
sudo(mkdir_command), spec_files_remote_path
|
701
|
-
].join(' ')
|
702
|
-
commands << [
|
703
|
-
sudo("#{cp_command} -r"), File.join(config[:root_path], 'spec/*'), spec_files_remote_path
|
704
|
-
].join(' ')
|
705
|
-
end
|
706
|
-
|
707
|
-
if config[:puppet_enc]
|
708
|
-
commands << [
|
709
|
-
sudo('chmod 755'), File.join("#{config[:root_path]}/enc", File.basename(config[:puppet_enc]))
|
710
|
-
].join(' ')
|
711
|
-
end
|
712
|
-
|
713
|
-
command = powershell? ? commands.join('; ') : commands.join(' && ')
|
714
|
-
debug(command)
|
715
|
-
command
|
716
|
-
end
|
717
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
718
|
-
|
719
|
-
def run_command
|
720
|
-
return config[:puppet_apply_command] unless config[:puppet_apply_command].nil?
|
721
|
-
result = [
|
722
|
-
facterlib,
|
723
|
-
custom_facts,
|
724
|
-
puppet_manifestdir,
|
725
|
-
puppet_cmd,
|
726
|
-
'apply',
|
727
|
-
File.join(config[:root_path], 'manifests', manifest),
|
728
|
-
"--modulepath=#{File.join(config[:root_path], 'modules')}",
|
729
|
-
"--fileserverconfig=#{File.join(config[:root_path], 'fileserver.conf')}",
|
730
|
-
custom_options,
|
731
|
-
puppet_environment_flag,
|
732
|
-
puppet_noop_flag,
|
733
|
-
puppet_enc_flag,
|
734
|
-
puppet_hiera_flag,
|
735
|
-
puppet_detailed_exitcodes_flag,
|
736
|
-
puppet_verbose_flag,
|
737
|
-
puppet_debug_flag,
|
738
|
-
puppet_logdest_flag,
|
739
|
-
puppet_future_parser_flag,
|
740
|
-
puppet_show_diff_flag,
|
741
|
-
puppet_whitelist_exit_code
|
742
|
-
].join(' ')
|
743
|
-
if config[:custom_post_apply_command]
|
744
|
-
custom_post_apply_trap = <<-TRAP
|
745
|
-
function custom_post_apply_command {
|
746
|
-
#{config[:custom_post_apply_command]}
|
747
|
-
}
|
748
|
-
trap custom_post_apply_command EXIT
|
749
|
-
TRAP
|
750
|
-
end
|
751
|
-
result = <<-RUN
|
752
|
-
#{config[:custom_pre_apply_command]}
|
753
|
-
#{custom_post_apply_trap}
|
754
|
-
#{result}
|
755
|
-
RUN
|
756
|
-
info("Going to invoke puppet apply with: #{result}")
|
757
|
-
result
|
758
|
-
end
|
759
|
-
|
760
|
-
protected
|
761
|
-
|
762
|
-
def load_needed_dependencies!
|
763
|
-
return unless File.exist?(puppetfile)
|
764
|
-
return unless config[:resolve_with_librarian_puppet] || config[:resolve_with_r10k]
|
765
|
-
if config[:resolve_with_librarian_puppet]
|
766
|
-
require 'kitchen/provisioner/puppet/librarian'
|
767
|
-
debug("Puppetfile found at #{puppetfile}, loading Librarian-Puppet")
|
768
|
-
Puppet::Librarian.load!(logger)
|
769
|
-
elsif config[:resolve_with_r10k]
|
770
|
-
require 'kitchen/provisioner/puppet/r10k'
|
771
|
-
debug("Puppetfile found at #{puppetfile}, loading R10K")
|
772
|
-
Puppet::R10K.load!(logger)
|
773
|
-
end
|
774
|
-
end
|
775
|
-
|
776
|
-
def tmpmodules_dir
|
777
|
-
File.join(sandbox_path, 'modules')
|
778
|
-
end
|
779
|
-
|
780
|
-
def puppetfile
|
781
|
-
config[:puppetfile_path] || ''
|
782
|
-
end
|
783
|
-
|
784
|
-
def modulefile
|
785
|
-
config[:modulefile_path] || ''
|
786
|
-
end
|
787
|
-
|
788
|
-
def metadata_json
|
789
|
-
config[:metadata_json_path] || ''
|
790
|
-
end
|
791
|
-
|
792
|
-
def manifest
|
793
|
-
config[:manifest]
|
794
|
-
end
|
795
|
-
|
796
|
-
def manifests
|
797
|
-
config[:manifests_path]
|
798
|
-
end
|
799
|
-
|
800
|
-
def modules
|
801
|
-
config[:modules_path]
|
802
|
-
end
|
803
|
-
|
804
|
-
def files
|
805
|
-
config[:files_path] || 'files'
|
806
|
-
end
|
807
|
-
|
808
|
-
def puppet_config
|
809
|
-
config[:puppet_config_path]
|
810
|
-
end
|
811
|
-
|
812
|
-
def puppet_environment
|
813
|
-
config[:puppet_environment]
|
814
|
-
end
|
815
|
-
|
816
|
-
def puppet_environment_config
|
817
|
-
if config[:puppet_environment_config_path] && !puppet_environment
|
818
|
-
raise("ERROR: found environment config '#{config[:puppet_environment_config_path]}', however no 'puppet_environment' is specified. Please specify 'puppet_environment' or unset 'puppet_environment_config_path' in .kitchen.yml")
|
819
|
-
end
|
820
|
-
config[:puppet_environment_config_path]
|
821
|
-
end
|
822
|
-
|
823
|
-
def puppet_environment_remote_modules_path
|
824
|
-
config[:puppet_environment_remote_modules_path]
|
825
|
-
end
|
826
|
-
|
827
|
-
def puppet_environment_remote_manifests_path
|
828
|
-
config[:puppet_environment_remote_manifests_path]
|
829
|
-
end
|
830
|
-
|
831
|
-
def puppet_environment_remote_hieradata_path
|
832
|
-
config[:puppet_environment_remote_hieradata_path]
|
833
|
-
end
|
834
|
-
|
835
|
-
def puppet_git_init
|
836
|
-
config[:puppet_git_init]
|
837
|
-
end
|
838
|
-
|
839
|
-
def puppet_git_pr
|
840
|
-
config[:puppet_git_pr]
|
841
|
-
end
|
842
|
-
|
843
|
-
def hiera_config
|
844
|
-
config[:hiera_config_path]
|
845
|
-
end
|
846
|
-
|
847
|
-
def puppet_environment_hiera_config
|
848
|
-
config[:puppet_environment_hiera_config_path]
|
849
|
-
end
|
850
|
-
|
851
|
-
def fileserver_config
|
852
|
-
config[:fileserver_config_path]
|
853
|
-
end
|
854
|
-
|
855
|
-
def hiera_data
|
856
|
-
config[:hiera_data_path]
|
857
|
-
end
|
858
|
-
|
859
|
-
def hiera_data_remote_path
|
860
|
-
return config[:hiera_data_remote_path] if config[:hiera_data_remote_path]
|
861
|
-
|
862
|
-
if config[:require_puppet_collections]
|
863
|
-
powershell? ? 'C:/ProgramData/PuppetLabs/code/environments/production/hieradata' : '/etc/puppetlabs/code/environments/production/hieradata'
|
864
|
-
else
|
865
|
-
powershell? ? 'C:/ProgramData/PuppetLabs/hiera/var' : '/var/lib/hiera'
|
866
|
-
end
|
867
|
-
end
|
868
|
-
|
869
|
-
def hiera_writer
|
870
|
-
config[:hiera_writer_files]
|
871
|
-
end
|
872
|
-
|
873
|
-
def hiera_eyaml
|
874
|
-
config[:hiera_eyaml]
|
875
|
-
end
|
876
|
-
|
877
|
-
def hiera_eyaml_gpg
|
878
|
-
config[:hiera_eyaml_gpg]
|
879
|
-
end
|
880
|
-
|
881
|
-
def hiera_eyaml_gpg_recipients
|
882
|
-
config[:hiera_eyaml_gpg_recipients]
|
883
|
-
end
|
884
|
-
|
885
|
-
def hiera_eyaml_gpg_secring
|
886
|
-
config[:hiera_eyaml_gpg_secring]
|
887
|
-
end
|
888
|
-
|
889
|
-
def hiera_eyaml_gpg_pubring
|
890
|
-
config[:hiera_eyaml_gpg_pubring]
|
891
|
-
end
|
892
|
-
|
893
|
-
def hiera_eyaml_gpg_remote_path
|
894
|
-
config[:hiera_eyaml_gpg_remote_path]
|
895
|
-
end
|
896
|
-
|
897
|
-
def hiera_eyaml_key_path
|
898
|
-
config[:hiera_eyaml_key_path]
|
899
|
-
end
|
900
|
-
|
901
|
-
def hiera_eyaml_key_remote_path
|
902
|
-
config[:hiera_eyaml_key_remote_path]
|
903
|
-
end
|
904
|
-
|
905
|
-
def hiera_deep_merge
|
906
|
-
config[:hiera_deep_merge]
|
907
|
-
end
|
908
|
-
|
909
|
-
def librarian_puppet_ssl_file
|
910
|
-
config[:librarian_puppet_ssl_file]
|
911
|
-
end
|
912
|
-
|
913
|
-
def r10k_ssl_file
|
914
|
-
config[:r10k_puppet_ssl_file] || config[:librarian_puppet_ssl_file]
|
915
|
-
end
|
916
|
-
|
917
|
-
def puppet_cmd
|
918
|
-
return '& "C:\Program Files\Puppet Labs\Puppet\bin\puppet"' if powershell?
|
919
|
-
|
920
|
-
puppet_bin = config[:require_puppet_collections] ? "#{config[:puppet_coll_remote_path]}/bin/puppet" : config[:puppet_binary]
|
921
|
-
|
922
|
-
if config[:puppet_no_sudo]
|
923
|
-
puppet_bin
|
924
|
-
else
|
925
|
-
sudo_env(puppet_bin)
|
926
|
-
end
|
927
|
-
end
|
928
|
-
|
929
|
-
def puppet_dir
|
930
|
-
return 'C:/ProgramData/PuppetLabs/puppet/etc' if powershell?
|
931
|
-
config[:require_puppet_collections] ? '/etc/puppetlabs/puppet' : '/etc/puppet'
|
932
|
-
end
|
933
|
-
|
934
|
-
def puppet_environmentpath_remote_path
|
935
|
-
return config[:puppet_environmentpath_remote_path] if config[:puppet_environmentpath_remote_path]
|
936
|
-
if config[:puppet_version] =~ /^3/
|
937
|
-
powershell? ? 'C:/ProgramData/PuppetLabs/puppet/etc' : '/etc/puppet/environments'
|
938
|
-
else
|
939
|
-
powershell? ? 'C:/ProgramData/PuppetLabs/code/environments' : '/etc/puppetlabs/code/environments'
|
940
|
-
end
|
941
|
-
end
|
942
|
-
|
943
|
-
def hiera_config_dir
|
944
|
-
return 'C:/ProgramData/PuppetLabs/puppet/etc' if powershell?
|
945
|
-
config[:require_puppet_collections] ? '/etc/puppetlabs/code' : '/etc/puppet'
|
946
|
-
end
|
947
|
-
|
948
|
-
def puppet_debian_version
|
949
|
-
config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
|
950
|
-
end
|
951
|
-
|
952
|
-
def facter_debian_version
|
953
|
-
config[:facter_version] ? "=#{config[:facter_version]}" : nil
|
954
|
-
end
|
955
|
-
|
956
|
-
def puppet_hiera_debian_version
|
957
|
-
config[:hiera_version] ? "=#{config[:hiera_version]}" : nil
|
958
|
-
end
|
959
|
-
|
960
|
-
def puppet_redhat_version
|
961
|
-
if puppet_platform == 'amazon'
|
962
|
-
config[:puppet_version]
|
963
|
-
else
|
964
|
-
config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
|
965
|
-
end
|
966
|
-
end
|
967
|
-
|
968
|
-
def puppet_windows_version
|
969
|
-
config[:puppet_version] ? config[:puppet_version].to_s : 'latest'
|
970
|
-
end
|
971
|
-
|
972
|
-
def puppet_environment_flag
|
973
|
-
if config[:puppet_version] =~ /^2/
|
974
|
-
config[:puppet_environment] ? "--environment=#{puppet_environment}" : nil
|
975
|
-
else
|
976
|
-
config[:puppet_environment] ? "--environment=#{puppet_environment} --environmentpath=#{puppet_environmentpath_remote_path}" : nil
|
977
|
-
end
|
978
|
-
end
|
979
|
-
|
980
|
-
def puppet_manifestdir
|
981
|
-
return nil if config[:require_puppet_collections]
|
982
|
-
return nil if config[:puppet_environment]
|
983
|
-
return nil if powershell?
|
984
|
-
bash_vars = "export MANIFESTDIR='#{File.join(config[:root_path], 'manifests')}';"
|
985
|
-
debug(bash_vars)
|
986
|
-
bash_vars
|
987
|
-
end
|
988
|
-
|
989
|
-
def custom_options
|
990
|
-
config[:custom_options] || ''
|
991
|
-
end
|
992
|
-
|
993
|
-
def puppet_noop_flag
|
994
|
-
config[:puppet_noop] ? '--noop' : nil
|
995
|
-
end
|
996
|
-
|
997
|
-
def puppet_debug_flag
|
998
|
-
config[:puppet_debug] ? '-d' : nil
|
999
|
-
end
|
1000
|
-
|
1001
|
-
def puppet_verbose_flag
|
1002
|
-
config[:puppet_verbose] ? '-v' : nil
|
1003
|
-
end
|
1004
|
-
|
1005
|
-
def puppet_show_diff_flag
|
1006
|
-
config[:puppet_show_diff] ? '--show_diff' : nil
|
1007
|
-
end
|
1008
|
-
|
1009
|
-
def puppet_future_parser_flag
|
1010
|
-
config[:puppet_future_parser] ? '--parser=future' : nil
|
1011
|
-
end
|
1012
|
-
|
1013
|
-
def puppet_logdest_flag
|
1014
|
-
return nil unless config[:puppet_logdest]
|
1015
|
-
destinations = ''
|
1016
|
-
config[:puppet_logdest].each do |dest|
|
1017
|
-
destinations << "--logdest #{dest} "
|
1018
|
-
end
|
1019
|
-
destinations
|
1020
|
-
end
|
1021
|
-
|
1022
|
-
def puppet_platform
|
1023
|
-
config[:platform].gsub(/-.*/, '')
|
1024
|
-
end
|
1025
|
-
|
1026
|
-
def update_packages_debian_cmd
|
1027
|
-
config[:update_package_repos] ? "#{sudo_env('apt-get')} update" : nil
|
1028
|
-
end
|
1029
|
-
|
1030
|
-
def update_packages_redhat_cmd
|
1031
|
-
# #{sudo('yum')}
|
1032
|
-
config[:update_package_repos] ? "#{sudo_env('yum')} makecache" : nil
|
1033
|
-
end
|
1034
|
-
|
1035
|
-
def sudo_env(pm)
|
1036
|
-
s = https_proxy ? "https_proxy=#{https_proxy}" : nil
|
1037
|
-
p = http_proxy ? "http_proxy=#{http_proxy}" : nil
|
1038
|
-
n = no_proxy ? "no_proxy=#{no_proxy}" : nil
|
1039
|
-
p || s ? "#{sudo('env')} #{p} #{s} #{n} #{pm}" : sudo(pm).to_s
|
1040
|
-
end
|
1041
|
-
|
1042
|
-
def remove_puppet_repo
|
1043
|
-
config[:remove_puppet_repo]
|
1044
|
-
end
|
1045
|
-
|
1046
|
-
def spec_files_path
|
1047
|
-
config[:spec_files_path]
|
1048
|
-
end
|
1049
|
-
|
1050
|
-
def spec_files_remote_path
|
1051
|
-
config[:spec_files_remote_path]
|
1052
|
-
end
|
1053
|
-
|
1054
|
-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
1055
|
-
def facterlib
|
1056
|
-
factpath = nil
|
1057
|
-
factpath = File.join(config[:root_path], 'facter').to_s if config[:install_custom_facts] && config[:custom_facts].any?
|
1058
|
-
factpath = File.join(config[:root_path], 'facter').to_s if config[:facter_file]
|
1059
|
-
factpath = "#{factpath}:" if config[:facterlib] && !factpath.nil?
|
1060
|
-
factpath = "#{factpath}#{config[:facterlib]}" if config[:facterlib]
|
1061
|
-
return nil if factpath.nil?
|
1062
|
-
bash_vars = "export FACTERLIB='#{factpath}';"
|
1063
|
-
debug(bash_vars)
|
1064
|
-
bash_vars
|
1065
|
-
end
|
1066
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
1067
|
-
|
1068
|
-
def custom_facts
|
1069
|
-
return nil if config[:custom_facts].none?
|
1070
|
-
return nil if config[:install_custom_facts]
|
1071
|
-
if powershell?
|
1072
|
-
environment_vars = config[:custom_facts].map { |k, v| "$env:FACTER_#{k}='#{v}'" }.join('; ')
|
1073
|
-
environment_vars = "#{environment_vars};"
|
1074
|
-
else
|
1075
|
-
environment_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
|
1076
|
-
environment_vars = "export #{environment_vars};"
|
1077
|
-
end
|
1078
|
-
debug(environment_vars)
|
1079
|
-
environment_vars
|
1080
|
-
end
|
1081
|
-
|
1082
|
-
def puppet_enc_flag
|
1083
|
-
config[:puppet_enc] ? "--node_terminus=exec --external_nodes=#{config[:root_path]}/enc/#{File.basename(config[:puppet_enc])}" : nil
|
1084
|
-
end
|
1085
|
-
|
1086
|
-
def puppet_hiera_flag
|
1087
|
-
hiera_config ? "--hiera_config=#{config[:root_path]}/hiera.global.yaml" : nil
|
1088
|
-
end
|
1089
|
-
|
1090
|
-
def puppet_detailed_exitcodes_flag
|
1091
|
-
config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
|
1092
|
-
end
|
1093
|
-
|
1094
|
-
def remove_repo
|
1095
|
-
remove_puppet_repo ? "#{sudo('rm')} -rf /tmp/kitchen #{hiera_data_remote_path} #{hiera_eyaml_key_remote_path} #{puppet_dir}/* " : nil
|
1096
|
-
end
|
1097
|
-
|
1098
|
-
def puppet_whitelist_exit_code
|
1099
|
-
if config[:puppet_whitelist_exit_code].nil?
|
1100
|
-
powershell? ? '; exit $LASTEXITCODE' : nil
|
1101
|
-
elsif powershell?
|
1102
|
-
"; if(@(#{[config[:puppet_whitelist_exit_code]].join(', ')}) -contains $LASTEXITCODE) {exit 0} else {exit $LASTEXITCODE}"
|
1103
|
-
else
|
1104
|
-
'; RC=$?; [ ' + [config[:puppet_whitelist_exit_code]].flatten.map { |x| "\$RC -eq #{x}" }.join(' -o ') + ' ] && exit 0; exit $RC'
|
1105
|
-
end
|
1106
|
-
end
|
1107
|
-
|
1108
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
1109
|
-
def puppet_apt_repo
|
1110
|
-
platform_version = config[:platform].partition('-')[2]
|
1111
|
-
case puppet_platform
|
1112
|
-
when 'ubuntu'
|
1113
|
-
case platform_version
|
1114
|
-
when '14.10'
|
1115
|
-
# Utopic Repo
|
1116
|
-
'https://apt.puppetlabs.com/puppetlabs-release-utopic.deb'
|
1117
|
-
when '14.04'
|
1118
|
-
# Trusty Repo
|
1119
|
-
'https://apt.puppetlabs.com/puppetlabs-release-trusty.deb'
|
1120
|
-
when '12.04'
|
1121
|
-
# Precise Repo
|
1122
|
-
'https://apt.puppetlabs.com/puppetlabs-release-precise.deb'
|
1123
|
-
else
|
1124
|
-
# Configured Repo
|
1125
|
-
config[:puppet_apt_repo]
|
1126
|
-
end
|
1127
|
-
when 'debian'
|
1128
|
-
case platform_version.gsub(/\..*/, '')
|
1129
|
-
when '8'
|
1130
|
-
# Debian Jessie
|
1131
|
-
'https://apt.puppetlabs.com/puppetlabs-release-jessie.deb'
|
1132
|
-
when '7'
|
1133
|
-
# Debian Wheezy
|
1134
|
-
'https://apt.puppetlabs.com/puppetlabs-release-wheezy.deb'
|
1135
|
-
when '6'
|
1136
|
-
# Debian Squeeze
|
1137
|
-
'https://apt.puppetlabs.com/puppetlabs-release-squeeze.deb'
|
1138
|
-
else
|
1139
|
-
# Configured Repo
|
1140
|
-
config[:puppet_apt_repo]
|
1141
|
-
end
|
1142
|
-
else
|
1143
|
-
debug("Apt repo detection failed with platform - #{config[:platform]}")
|
1144
|
-
false
|
1145
|
-
end
|
1146
|
-
end
|
1147
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
1148
|
-
|
1149
|
-
def puppet_apt_repo_file
|
1150
|
-
puppet_apt_repo.split('/').last if puppet_apt_repo
|
1151
|
-
end
|
1152
|
-
|
1153
|
-
def puppet_apt_coll_repo_file
|
1154
|
-
config[:puppet_apt_collections_repo].split('/').last
|
1155
|
-
end
|
1156
|
-
|
1157
|
-
def puppet_yum_repo
|
1158
|
-
config[:puppet_yum_repo]
|
1159
|
-
end
|
1160
|
-
|
1161
|
-
def proxy_parm
|
1162
|
-
http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
|
1163
|
-
end
|
1164
|
-
|
1165
|
-
def gem_proxy_parm
|
1166
|
-
p = http_proxy ? "--http-proxy #{http_proxy}" : nil
|
1167
|
-
n = no_proxy ? "--no-http-proxy #{no_proxy}" : nil
|
1168
|
-
p || n ? "#{p} #{n}" : nil
|
1169
|
-
end
|
1170
|
-
|
1171
|
-
def wget_proxy_parm
|
1172
|
-
p = http_proxy ? "-e http_proxy=#{http_proxy}" : nil
|
1173
|
-
s = https_proxy ? "-e https_proxy=#{https_proxy}" : nil
|
1174
|
-
n = no_proxy ? "-e no_proxy=#{no_proxy}" : nil
|
1175
|
-
p || s ? "-e use_proxy=yes #{p} #{s} #{n}" : nil
|
1176
|
-
end
|
1177
|
-
|
1178
|
-
def posh_proxy_parm
|
1179
|
-
http_proxy ? "-Proxy #{http_proxy}" : nil
|
1180
|
-
end
|
1181
|
-
|
1182
|
-
def powershell?
|
1183
|
-
return true if powershell_shell?
|
1184
|
-
return true if puppet_platform =~ /^windows.*/
|
1185
|
-
false
|
1186
|
-
end
|
1187
|
-
|
1188
|
-
def export_http_proxy_parm
|
1189
|
-
http_proxy ? "export http_proxy=#{http_proxy}" : nil
|
1190
|
-
end
|
1191
|
-
|
1192
|
-
def export_https_proxy_parm
|
1193
|
-
https_proxy ? "export https_proxy=#{https_proxy}" : nil
|
1194
|
-
end
|
1195
|
-
|
1196
|
-
def export_no_proxy_parm
|
1197
|
-
no_proxy ? "export no_proxy=#{no_proxy}" : nil
|
1198
|
-
end
|
1199
|
-
|
1200
|
-
def http_proxy
|
1201
|
-
config[:http_proxy]
|
1202
|
-
end
|
1203
|
-
|
1204
|
-
def https_proxy
|
1205
|
-
config[:https_proxy]
|
1206
|
-
end
|
1207
|
-
|
1208
|
-
def no_proxy
|
1209
|
-
config[:no_proxy]
|
1210
|
-
end
|
1211
|
-
|
1212
|
-
def chef_url
|
1213
|
-
config[:chef_bootstrap_url]
|
1214
|
-
end
|
1215
|
-
|
1216
|
-
def prepare_manifests
|
1217
|
-
info('Preparing manifests')
|
1218
|
-
debug("Using manifests from #{manifests}")
|
1219
|
-
|
1220
|
-
tmp_manifests_dir = File.join(sandbox_path, 'manifests')
|
1221
|
-
FileUtils.mkdir_p(tmp_manifests_dir)
|
1222
|
-
FileUtils.cp_r(Dir.glob("#{manifests}/*"), tmp_manifests_dir)
|
1223
|
-
end
|
1224
|
-
|
1225
|
-
def prepare_files
|
1226
|
-
info('Preparing files')
|
1227
|
-
unless File.directory?(files)
|
1228
|
-
info 'nothing to do for files'
|
1229
|
-
return
|
1230
|
-
end
|
1231
|
-
|
1232
|
-
debug("Using files from #{files}")
|
1233
|
-
|
1234
|
-
tmp_files_dir = File.join(sandbox_path, 'files')
|
1235
|
-
FileUtils.mkdir_p(tmp_files_dir)
|
1236
|
-
FileUtils.cp_r(Dir.glob("#{files}/*"), tmp_files_dir)
|
1237
|
-
end
|
1238
|
-
|
1239
|
-
def prepare_facter_file
|
1240
|
-
return unless config[:facter_file]
|
1241
|
-
info 'Copying facter file'
|
1242
|
-
facter_dir = File.join(sandbox_path, 'facter')
|
1243
|
-
FileUtils.mkdir_p(facter_dir)
|
1244
|
-
FileUtils.cp_r(config[:facter_file], facter_dir)
|
1245
|
-
end
|
1246
|
-
|
1247
|
-
def prepare_facts
|
1248
|
-
return unless config[:install_custom_facts]
|
1249
|
-
return unless config[:custom_facts]
|
1250
|
-
info 'Installing custom facts'
|
1251
|
-
facter_dir = File.join(sandbox_path, 'facter')
|
1252
|
-
FileUtils.mkdir_p(facter_dir)
|
1253
|
-
tmp_facter_file = File.join(facter_dir, 'kitchen.rb')
|
1254
|
-
facter_facts = Hash[config[:custom_facts]]
|
1255
|
-
File.open(tmp_facter_file, 'a') do |out|
|
1256
|
-
facter_facts.each do |k, v|
|
1257
|
-
out.write "\nFacter.add(:#{k}) do\n"
|
1258
|
-
out.write " setcode do\n"
|
1259
|
-
if [Array, Hash].include? v.class
|
1260
|
-
out.write " #{v}\n"
|
1261
|
-
else
|
1262
|
-
out.write " \"#{v}\"\n"
|
1263
|
-
end
|
1264
|
-
out.write " end\n"
|
1265
|
-
out.write "end\n"
|
1266
|
-
end
|
1267
|
-
end
|
1268
|
-
end
|
1269
|
-
|
1270
|
-
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
1271
|
-
def prepare_modules
|
1272
|
-
info('Preparing modules')
|
1273
|
-
|
1274
|
-
FileUtils.mkdir_p(tmpmodules_dir)
|
1275
|
-
resolve_with_librarian if File.exist?(puppetfile) && config[:resolve_with_librarian_puppet]
|
1276
|
-
resolve_with_r10k if File.exist?(puppetfile) && config[:resolve_with_r10k] && !config[:resolve_with_librarian_puppet]
|
1277
|
-
modules_to_copy = {}
|
1278
|
-
|
1279
|
-
# If root dir (.) is a module, add it for copying
|
1280
|
-
self_name = read_self_module_name
|
1281
|
-
modules_to_copy[self_name] = '.' if self_name
|
1282
|
-
|
1283
|
-
if modules
|
1284
|
-
modules_array = modules.split(':')
|
1285
|
-
modules_array.each do |m_path|
|
1286
|
-
Dir.glob("#{m_path}/*").each do |m|
|
1287
|
-
name = File.basename(m)
|
1288
|
-
if modules_to_copy.include? name
|
1289
|
-
debug("Found duplicated module: #{name}. The path taking precedence: '#{modules_to_copy[name]}', ignoring '#{m}'")
|
1290
|
-
else
|
1291
|
-
modules_to_copy[name] = m
|
1292
|
-
end
|
1293
|
-
end
|
1294
|
-
end
|
1295
|
-
end
|
1296
|
-
|
1297
|
-
if modules_to_copy.empty?
|
1298
|
-
info 'Nothing to do for modules'
|
1299
|
-
else
|
1300
|
-
copy_modules(modules_to_copy, tmpmodules_dir)
|
1301
|
-
end
|
1302
|
-
end
|
1303
|
-
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
1304
|
-
|
1305
|
-
def copy_modules(modules, destination)
|
1306
|
-
excluded_paths = %w[modules pkg] + config[:ignored_paths_from_root]
|
1307
|
-
debug("Copying modules to directory: #{destination}")
|
1308
|
-
modules.each do |name, source|
|
1309
|
-
next unless File.directory?(source)
|
1310
|
-
debug("Copying module #{name} from #{source}...")
|
1311
|
-
target = "#{destination}/#{name}"
|
1312
|
-
FileUtils.mkdir_p(target) unless File.exist? target
|
1313
|
-
FileUtils.cp_r(
|
1314
|
-
Dir.glob("#{source}/*").reject { |entry| entry =~ /#{excluded_paths.join('$|')}$/ },
|
1315
|
-
target,
|
1316
|
-
remove_destination: true
|
1317
|
-
)
|
1318
|
-
end
|
1319
|
-
end
|
1320
|
-
|
1321
|
-
def read_self_module_name
|
1322
|
-
if File.exist?(modulefile)
|
1323
|
-
warn('Modulefile found but this is deprecated, ignoring it, see https://tickets.puppetlabs.com/browse/PUP-1188')
|
1324
|
-
end
|
1325
|
-
|
1326
|
-
return unless File.exist?(metadata_json)
|
1327
|
-
module_name = nil
|
1328
|
-
begin
|
1329
|
-
module_name = JSON.parse(IO.read(metadata_json))['name'].split('-').last
|
1330
|
-
rescue JSON::ParserError
|
1331
|
-
error("not able to load or parse #{metadata_json} for the name of the module")
|
1332
|
-
end
|
1333
|
-
|
1334
|
-
module_name
|
1335
|
-
end
|
1336
|
-
|
1337
|
-
def prepare_puppet_config
|
1338
|
-
return unless puppet_config
|
1339
|
-
|
1340
|
-
info('Preparing puppet.conf')
|
1341
|
-
debug("Using puppet config from #{puppet_config}")
|
1342
|
-
|
1343
|
-
FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
|
1344
|
-
end
|
1345
|
-
|
1346
|
-
def prepare_enc
|
1347
|
-
return unless config[:puppet_enc]
|
1348
|
-
info 'Copying enc file'
|
1349
|
-
enc_dir = File.join(sandbox_path, 'enc')
|
1350
|
-
FileUtils.mkdir_p(enc_dir)
|
1351
|
-
FileUtils.cp_r(config[:puppet_enc], File.join(enc_dir, '/'))
|
1352
|
-
end
|
1353
|
-
|
1354
|
-
def prepare_puppet_environment
|
1355
|
-
return unless puppet_environment_config
|
1356
|
-
|
1357
|
-
info('Preparing Environment Config')
|
1358
|
-
environment_dir = File.join(sandbox_path, 'environment')
|
1359
|
-
FileUtils.mkdir_p(environment_dir)
|
1360
|
-
debug("Using Environment Config environment.conf from #{puppet_environment_config}")
|
1361
|
-
FileUtils.cp_r(puppet_environment_config, File.join(environment_dir, 'environment.conf'))
|
1362
|
-
if puppet_environment_hiera_config
|
1363
|
-
debug("Using Environment Hiera Config hiera.yaml from #{puppet_environment_hiera_config}")
|
1364
|
-
FileUtils.cp_r(puppet_environment_hiera_config, File.join(environment_dir, 'hiera.yaml'))
|
1365
|
-
else
|
1366
|
-
info('No Environment hiera.yaml found')
|
1367
|
-
end
|
1368
|
-
end
|
1369
|
-
|
1370
|
-
def prepare_hiera_config
|
1371
|
-
return unless hiera_config
|
1372
|
-
|
1373
|
-
info('Preparing hiera (global layer)')
|
1374
|
-
debug("Using hiera from #{hiera_config}")
|
1375
|
-
|
1376
|
-
FileUtils.cp_r(hiera_config, File.join(sandbox_path, 'hiera.global.yaml'))
|
1377
|
-
end
|
1378
|
-
|
1379
|
-
def prepare_fileserver_config
|
1380
|
-
return unless fileserver_config
|
1381
|
-
|
1382
|
-
info('Preparing fileserver')
|
1383
|
-
debug("Using fileserver config from #{fileserver_config}")
|
1384
|
-
|
1385
|
-
FileUtils.cp_r(fileserver_config, File.join(sandbox_path, 'fileserver.conf'))
|
1386
|
-
end
|
1387
|
-
|
1388
|
-
def prepare_hiera_data
|
1389
|
-
return unless hiera_data
|
1390
|
-
info('Preparing hiera data')
|
1391
|
-
tmp_hiera_dir = File.join(sandbox_path, 'hiera')
|
1392
|
-
debug("Copying hiera data from #{hiera_data} to #{tmp_hiera_dir}")
|
1393
|
-
FileUtils.mkdir_p(tmp_hiera_dir)
|
1394
|
-
FileUtils.cp_r(Dir.glob("#{hiera_data}/*"), tmp_hiera_dir)
|
1395
|
-
if hiera_writer
|
1396
|
-
hiera_writer.each do |file|
|
1397
|
-
file.each do |filename, hiera_hash|
|
1398
|
-
debug("Creating hiera yaml file #{tmp_hiera_dir}/#{filename}")
|
1399
|
-
dir = File.join(tmp_hiera_dir, File.dirname(filename.to_s))
|
1400
|
-
FileUtils.mkdir_p(dir)
|
1401
|
-
output_file = open(File.join(dir, File.basename(filename.to_s)), 'w')
|
1402
|
-
# convert json and back before converting to yaml to recursively convert symbols to strings, heh
|
1403
|
-
output_file.write JSON[hiera_hash.to_json].to_yaml
|
1404
|
-
output_file.close
|
1405
|
-
end
|
1406
|
-
end
|
1407
|
-
end
|
1408
|
-
return unless hiera_eyaml_key_path
|
1409
|
-
tmp_hiera_key_dir = File.join(sandbox_path, 'hiera_keys')
|
1410
|
-
debug("Copying hiera eyaml keys from #{hiera_eyaml_key_path} to #{tmp_hiera_key_dir}")
|
1411
|
-
FileUtils.mkdir_p(tmp_hiera_key_dir)
|
1412
|
-
FileUtils.cp_r(Dir.glob("#{hiera_eyaml_key_path}/*"), tmp_hiera_key_dir)
|
1413
|
-
end
|
1414
|
-
|
1415
|
-
def prepare_spec_files
|
1416
|
-
return unless spec_files_path
|
1417
|
-
info('Preparing spec files')
|
1418
|
-
tmp_spec_dir = File.join(sandbox_path, 'spec')
|
1419
|
-
debug("Copying specs from #{spec_files_path} to #{tmp_spec_dir}")
|
1420
|
-
FileUtils.mkdir_p(tmp_spec_dir)
|
1421
|
-
FileUtils.cp_r(Dir.glob(File.join(spec_files_path, '*')).reject { |entry| entry =~ /fixtures$/ }, tmp_spec_dir) if config[:ignore_spec_fixtures]
|
1422
|
-
FileUtils.cp_r(Dir.glob("#{spec_files_path}/*"), tmp_spec_dir) unless config[:ignore_spec_fixtures]
|
1423
|
-
end
|
1424
|
-
|
1425
|
-
def resolve_with_librarian
|
1426
|
-
require 'kitchen/provisioner/puppet/librarian'
|
1427
|
-
Kitchen.mutex.synchronize do
|
1428
|
-
ENV['SSL_CERT_FILE'] = librarian_puppet_ssl_file if librarian_puppet_ssl_file
|
1429
|
-
Puppet::Librarian.new(puppetfile, tmpmodules_dir, logger).resolve
|
1430
|
-
ENV['SSL_CERT_FILE'] = '' if librarian_puppet_ssl_file
|
1431
|
-
end
|
1432
|
-
end
|
1433
|
-
|
1434
|
-
def resolve_with_r10k
|
1435
|
-
require 'kitchen/provisioner/puppet/r10k'
|
1436
|
-
Kitchen.mutex.synchronize do
|
1437
|
-
ENV['SSL_CERT_FILE'] = r10k_ssl_file if r10k_ssl_file
|
1438
|
-
Puppet::R10K.new(puppetfile, tmpmodules_dir, logger).resolve
|
1439
|
-
ENV['SSL_CERT_FILE'] = '' if r10k_ssl_file
|
1440
|
-
end
|
1441
|
-
end
|
1442
|
-
|
1443
|
-
def cp_command
|
1444
|
-
return 'cp -force' if powershell?
|
1445
|
-
'cp'
|
1446
|
-
end
|
1447
|
-
|
1448
|
-
def rm_command
|
1449
|
-
return 'rm -force -recurse' if powershell?
|
1450
|
-
'rm -rf'
|
1451
|
-
end
|
1452
|
-
|
1453
|
-
def mkdir_command
|
1454
|
-
return 'mkdir -force -path' if powershell?
|
1455
|
-
'mkdir -p'
|
1456
|
-
end
|
1457
|
-
|
1458
|
-
def rm_command_paths(paths)
|
1459
|
-
return :nil if paths.length.zero?
|
1460
|
-
return "#{rm_command} \"#{paths.join('", "')}\"" if powershell?
|
1461
|
-
"#{rm_command} #{paths.join(' ')}"
|
1462
|
-
end
|
1463
|
-
end
|
1464
|
-
end
|
1465
|
-
end
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
#
|
4
|
+
# Author:: Chris Lundquist (<chris.lundquist@github.com>) Neill Turner (<neillwturner@gmail.com>)
|
5
|
+
#
|
6
|
+
# Copyright (C) 2013,2014 Chris Lundquist, Neill Turner
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
# See https://github.com/neillturner/kitchen-puppet/blob/master/provisioner_options.md
|
21
|
+
# for documentation configuration parameters with puppet_apply provisioner.
|
22
|
+
#
|
23
|
+
|
24
|
+
require 'uri'
|
25
|
+
require 'json'
|
26
|
+
require 'kitchen'
|
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, true
|
49
|
+
default_config :puppet_yum_collections_repo, 'http://yum.puppetlabs.com/puppet5/puppet5-release-el-6.noarch.rpm'
|
50
|
+
default_config :puppet_apt_collections_repo, 'http://apt.puppetlabs.com/puppet5-release-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 :hiera_writer_files, nil
|
58
|
+
default_config :require_puppet_repo, true
|
59
|
+
default_config :require_chef_for_busser, true
|
60
|
+
default_config :resolve_with_librarian_puppet, true
|
61
|
+
default_config :resolve_with_r10k, false
|
62
|
+
default_config :puppet_environment, nil
|
63
|
+
default_config :puppet_environment_config_path do |provisioner|
|
64
|
+
provisioner.calculate_path('environment.conf')
|
65
|
+
end
|
66
|
+
default_config :puppet_environment_remote_modules_path, 'modules'
|
67
|
+
default_config :puppet_environment_remote_manifests_path, 'manifests'
|
68
|
+
default_config :puppet_environment_remote_hieradata_path, 'hieradata'
|
69
|
+
default_config :puppet_environment_hiera_config_path do |provisioner|
|
70
|
+
provisioner.calculate_path('hiera.yaml', :file)
|
71
|
+
end
|
72
|
+
default_config :puppet_apt_repo, 'http://apt.puppetlabs.com/puppetlabs-release-precise.deb'
|
73
|
+
default_config :puppet_yum_repo, 'https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm'
|
74
|
+
default_config :chef_bootstrap_url, 'https://www.chef.io/chef/install.sh'
|
75
|
+
default_config :puppet_logdest, nil
|
76
|
+
default_config :custom_install_command, nil
|
77
|
+
default_config :custom_pre_install_command, nil
|
78
|
+
default_config :custom_pre_apply_command, nil
|
79
|
+
default_config :custom_post_apply_command, nil
|
80
|
+
default_config :puppet_whitelist_exit_code, nil
|
81
|
+
default_config :require_puppet_omnibus, false
|
82
|
+
default_config :puppet_omnibus_url, 'https://raw.githubusercontent.com/petems/puppet-install-shell/master/install_puppet_6_agent.sh'
|
83
|
+
default_config :puppet_enc, nil
|
84
|
+
default_config :ignore_spec_fixtures, false
|
85
|
+
|
86
|
+
default_config :puppet_apply_command, nil
|
87
|
+
|
88
|
+
default_config :puppet_git_init, nil
|
89
|
+
default_config :puppet_git_pr, nil
|
90
|
+
|
91
|
+
default_config :http_proxy, nil
|
92
|
+
default_config :https_proxy, nil
|
93
|
+
default_config :no_proxy, nil
|
94
|
+
|
95
|
+
default_config :ignored_paths_from_root, ['spec']
|
96
|
+
default_config :hiera_data_remote_path, nil
|
97
|
+
default_config :manifest, ''
|
98
|
+
default_config :puppet_binary, 'puppet'
|
99
|
+
|
100
|
+
default_config :manifests_path do |provisioner|
|
101
|
+
provisioner.calculate_path('manifests') ||
|
102
|
+
raise('No manifests_path detected. Please specify one in .kitchen.yml')
|
103
|
+
end
|
104
|
+
|
105
|
+
default_config :modules_path do |provisioner|
|
106
|
+
modules_path = provisioner.calculate_path('modules')
|
107
|
+
if modules_path.nil? && provisioner.calculate_path('Puppetfile', :file).nil?
|
108
|
+
raise('No modules_path detected. Please specify one in .kitchen.yml')
|
109
|
+
end
|
110
|
+
modules_path
|
111
|
+
end
|
112
|
+
|
113
|
+
default_config :files_path do |provisioner|
|
114
|
+
provisioner.calculate_path('files') || 'files'
|
115
|
+
end
|
116
|
+
|
117
|
+
default_config :hiera_data_path do |provisioner|
|
118
|
+
provisioner.calculate_path('hiera')
|
119
|
+
end
|
120
|
+
|
121
|
+
default_config :puppet_config_path do |provisioner|
|
122
|
+
provisioner.calculate_path('puppet.conf', :file)
|
123
|
+
end
|
124
|
+
|
125
|
+
default_config :hiera_config_path do |provisioner|
|
126
|
+
provisioner.calculate_path('hiera.global.yaml', :file) ||
|
127
|
+
provisioner.calculate_path('hiera.yaml', :file)
|
128
|
+
end
|
129
|
+
|
130
|
+
default_config :fileserver_config_path do |provisioner|
|
131
|
+
provisioner.calculate_path('fileserver.conf', :file)
|
132
|
+
end
|
133
|
+
default_config :puppetfile_path do |provisioner|
|
134
|
+
provisioner.calculate_path('Puppetfile', :file)
|
135
|
+
end
|
136
|
+
|
137
|
+
default_config :modulefile_path do |provisioner|
|
138
|
+
provisioner.calculate_path('Modulefile', :file)
|
139
|
+
end
|
140
|
+
|
141
|
+
default_config :metadata_json_path do |provisioner|
|
142
|
+
provisioner.calculate_path('metadata.json', :file)
|
143
|
+
end
|
144
|
+
|
145
|
+
default_config :manifests_path do |provisioner|
|
146
|
+
provisioner.calculate_path('manifests', :directory)
|
147
|
+
end
|
148
|
+
|
149
|
+
default_config :spec_files_path do |provisioner|
|
150
|
+
provisioner.calculate_path('spec', :directory)
|
151
|
+
end
|
152
|
+
|
153
|
+
default_config :spec_files_remote_path, '/etc/puppet/spec'
|
154
|
+
|
155
|
+
default_config :puppet_debug, false
|
156
|
+
default_config :puppet_verbose, false
|
157
|
+
default_config :puppet_noop, false
|
158
|
+
default_config :puppet_show_diff, false
|
159
|
+
default_config :puppet_future_parser, false
|
160
|
+
default_config :platform, &:platform_name
|
161
|
+
default_config :update_package_repos, true
|
162
|
+
default_config :remove_puppet_repo, false
|
163
|
+
default_config :install_custom_facts, false
|
164
|
+
default_config :custom_facts, {}
|
165
|
+
default_config :facterlib, nil
|
166
|
+
default_config :puppet_detailed_exitcodes, nil
|
167
|
+
default_config :facter_file, nil
|
168
|
+
default_config :librarian_puppet_ssl_file, nil
|
169
|
+
default_config :r10k_ssl_file, nil
|
170
|
+
|
171
|
+
default_config :hiera_eyaml, false
|
172
|
+
default_config :hiera_eyaml_key_remote_path, '/etc/puppet/secure/keys'
|
173
|
+
default_config :puppet_environmentpath_remote_path, nil
|
174
|
+
|
175
|
+
default_config :hiera_eyaml_gpg, false
|
176
|
+
default_config :hiera_eyaml_gpg_recipients, false
|
177
|
+
default_config :hiera_eyaml_gpg_secring, false
|
178
|
+
default_config :hiera_eyaml_gpg_pubring, false
|
179
|
+
default_config :hiera_eyaml_gpg_remote_path, '/home/vagrant/.gnupg'
|
180
|
+
|
181
|
+
default_config :hiera_eyaml_key_path do |provisioner|
|
182
|
+
provisioner.calculate_path('hiera_keys')
|
183
|
+
end
|
184
|
+
|
185
|
+
default_config :hiera_deep_merge, false
|
186
|
+
default_config :puppet_no_sudo, false
|
187
|
+
|
188
|
+
def calculate_path(path, type = :directory)
|
189
|
+
base = config[:test_base_path]
|
190
|
+
candidates = []
|
191
|
+
candidates << File.join(base, instance.suite.name, 'puppet', path)
|
192
|
+
candidates << File.join(base, instance.suite.name, path)
|
193
|
+
candidates << File.join(base, path)
|
194
|
+
candidates << File.join(Dir.pwd, path)
|
195
|
+
|
196
|
+
candidates.find do |c|
|
197
|
+
type == :directory ? File.directory?(c) : File.file?(c)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
202
|
+
def install_command
|
203
|
+
return unless config[:require_puppet_collections] || config[:require_puppet_repo] || config[:require_puppet_omnibus]
|
204
|
+
if config[:require_puppet_omnibus]
|
205
|
+
install_omnibus_command
|
206
|
+
elsif config[:require_puppet_collections]
|
207
|
+
install_command_collections
|
208
|
+
else
|
209
|
+
case puppet_platform
|
210
|
+
when 'debian', 'ubuntu'
|
211
|
+
info("Installing puppet on #{config[:platform]}")
|
212
|
+
# need to add a CR to avoid trouble with proxy settings concatenation
|
213
|
+
<<-INSTALL
|
214
|
+
|
215
|
+
#{custom_pre_install_command}
|
216
|
+
if [ ! $(which puppet) ]; then
|
217
|
+
#{sudo('apt-get')} -y install wget
|
218
|
+
#{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
|
219
|
+
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
220
|
+
#{update_packages_debian_cmd}
|
221
|
+
#{sudo_env('apt-get')} -y install facter#{facter_debian_version}
|
222
|
+
#{sudo_env('apt-get')} -y install puppet-common#{puppet_debian_version}
|
223
|
+
#{sudo_env('apt-get')} -y install puppet#{puppet_debian_version}
|
224
|
+
#{install_hiera}
|
225
|
+
fi
|
226
|
+
#{install_eyaml}
|
227
|
+
#{install_eyaml_gpg}
|
228
|
+
#{install_deep_merge}
|
229
|
+
#{install_busser}
|
230
|
+
#{custom_install_command}
|
231
|
+
INSTALL
|
232
|
+
when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
|
233
|
+
info("Installing puppet from yum on #{puppet_platform}")
|
234
|
+
# need to add a CR to avoid trouble with proxy settings concatenation
|
235
|
+
<<-INSTALL
|
236
|
+
|
237
|
+
#{custom_pre_install_command}
|
238
|
+
if [ ! $(which puppet) ]; then
|
239
|
+
#{install_puppet_yum_repo}
|
240
|
+
fi
|
241
|
+
#{install_eyaml}
|
242
|
+
#{install_eyaml_gpg}
|
243
|
+
#{install_deep_merge}
|
244
|
+
#{install_busser}
|
245
|
+
#{custom_install_command}
|
246
|
+
INSTALL
|
247
|
+
when /^windows.*/
|
248
|
+
info("Installing puppet on #{puppet_platform}")
|
249
|
+
info('Powershell is not recognised by core test-kitchen assuming it is present') unless powershell_shell?
|
250
|
+
<<-INSTALL
|
251
|
+
if(Get-Command puppet -ErrorAction 0) { return; }
|
252
|
+
$architecture = if( [Environment]::Is64BitOperatingSystem ) { '-x64' } else { '' }
|
253
|
+
if( '#{puppet_windows_version}' -eq 'latest' ) {
|
254
|
+
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-agent-${architecture}-latest.msi"
|
255
|
+
} elseif( '#{puppet_windows_version}' -like '5.*' ) {
|
256
|
+
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet5/puppet-agent-#{puppet_windows_version}-${architecture}.msi"
|
257
|
+
} else {
|
258
|
+
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-#{puppet_windows_version}${architecture}.msi"
|
259
|
+
}
|
260
|
+
Invoke-WebRequest $MsiUrl -UseBasicParsing -OutFile "C:/puppet.msi" #{posh_proxy_parm}
|
261
|
+
$process = Start-Process -FilePath msiexec.exe -Wait -PassThru -ArgumentList '/qn', '/norestart', '/i', 'C:\\puppet.msi'
|
262
|
+
if ($process.ExitCode -ne 0) {
|
263
|
+
Write-Host "Installer failed."
|
264
|
+
Exit 1
|
265
|
+
}
|
266
|
+
|
267
|
+
#{install_busser}
|
268
|
+
INSTALL
|
269
|
+
else
|
270
|
+
info('Installing puppet, will try to determine platform os')
|
271
|
+
# need to add a CR to avoid trouble with proxy settings concatenation
|
272
|
+
<<-INSTALL
|
273
|
+
|
274
|
+
#{custom_pre_install_command}
|
275
|
+
if [ ! $(which puppet) ]; then
|
276
|
+
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ]; then
|
277
|
+
#{install_puppet_yum_repo}
|
278
|
+
else
|
279
|
+
if [ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
|
280
|
+
#{install_puppet_yum_repo}
|
281
|
+
else
|
282
|
+
#{sudo('apt-get')} -y install wget
|
283
|
+
#{sudo('wget')} #{wget_proxy_parm} #{puppet_apt_repo}
|
284
|
+
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
285
|
+
#{update_packages_debian_cmd}
|
286
|
+
#{sudo_env('apt-get')} -y install facter#{facter_debian_version}
|
287
|
+
#{sudo_env('apt-get')} -y install puppet-common#{puppet_debian_version}
|
288
|
+
#{sudo_env('apt-get')} -y install puppet#{puppet_debian_version}
|
289
|
+
#{install_hiera}
|
290
|
+
fi
|
291
|
+
fi
|
292
|
+
fi
|
293
|
+
#{install_eyaml}
|
294
|
+
#{install_eyaml_gpg}
|
295
|
+
#{install_deep_merge}
|
296
|
+
#{install_busser}
|
297
|
+
#{custom_install_command}
|
298
|
+
INSTALL
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
303
|
+
|
304
|
+
def install_command_collections
|
305
|
+
case puppet_platform
|
306
|
+
when 'debian', 'ubuntu'
|
307
|
+
info("Installing Puppet Collections on #{puppet_platform}")
|
308
|
+
<<-INSTALL
|
309
|
+
|
310
|
+
#{Util.shell_helpers}
|
311
|
+
#{custom_pre_install_command}
|
312
|
+
if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
|
313
|
+
if [ ! -f "#{config[:puppet_apt_collections_repo]}" ]; then
|
314
|
+
#{sudo('apt-get')} -y install wget
|
315
|
+
#{sudo('wget')} #{wget_proxy_parm} #{config[:puppet_apt_collections_repo]}
|
316
|
+
fi
|
317
|
+
#{sudo('dpkg')} -i #{puppet_apt_coll_repo_file}
|
318
|
+
#{sudo('apt-get')} update
|
319
|
+
#{sudo_env('apt-get')} -y install puppet-agent#{puppet_debian_version}
|
320
|
+
fi
|
321
|
+
#{install_eyaml("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
322
|
+
#{install_eyaml_gpg("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
323
|
+
#{install_deep_merge}
|
324
|
+
#{install_busser}
|
325
|
+
#{custom_install_command}
|
326
|
+
INSTALL
|
327
|
+
when 'redhat', 'centos', 'fedora', 'oracle', 'amazon'
|
328
|
+
info("Installing Puppet Collections on #{puppet_platform}")
|
329
|
+
<<-INSTALL
|
330
|
+
|
331
|
+
#{Util.shell_helpers}
|
332
|
+
#{custom_pre_install_command}
|
333
|
+
if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
|
334
|
+
echo "-----> #{sudo_env('yum')} -y --nogpgcheck install #{config[:puppet_yum_collections_repo]}"
|
335
|
+
#{sudo_env('yum')} clean all
|
336
|
+
#{sudo_env('yum')} -y --nogpgcheck install #{config[:puppet_yum_collections_repo]}
|
337
|
+
#{sudo_env('yum')} -y --nogpgcheck install puppet-agent#{puppet_redhat_version}
|
338
|
+
fi
|
339
|
+
#{install_eyaml("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
340
|
+
#{install_eyaml_gpg("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
341
|
+
#{install_deep_merge}
|
342
|
+
#{install_busser}
|
343
|
+
#{custom_install_command}
|
344
|
+
INSTALL
|
345
|
+
when /^windows.*/
|
346
|
+
info("Installing Puppet Collections on #{puppet_platform}")
|
347
|
+
info('Powershell is not recognised by core test-kitchen assuming it is present') unless powershell_shell?
|
348
|
+
<<-INSTALL
|
349
|
+
if(Get-Command puppet -ErrorAction 0) { return; }
|
350
|
+
$architecture = if( [Environment]::Is64BitOperatingSystem ) { 'x64' } else { 'x86' }
|
351
|
+
if( '#{puppet_windows_version}' -eq 'latest' ) {
|
352
|
+
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-agent-${architecture}-latest.msi"
|
353
|
+
} elseif( '#{puppet_windows_version}' -like '5.*' ) {
|
354
|
+
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet5/puppet-agent-#{puppet_windows_version}-${architecture}.msi"
|
355
|
+
} else {
|
356
|
+
$MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-agent-#{puppet_windows_version}${architecture}.msi"
|
357
|
+
}
|
358
|
+
Invoke-WebRequest $MsiUrl -UseBasicParsing -OutFile "C:/puppet-agent.msi" #{posh_proxy_parm}
|
359
|
+
$process = Start-Process -FilePath msiexec.exe -Wait -PassThru -ArgumentList '/qn', '/norestart', '/i', 'C:\\puppet-agent.msi'
|
360
|
+
if ($process.ExitCode -ne 0) {
|
361
|
+
Write-Host "Installer failed."
|
362
|
+
Exit 1
|
363
|
+
}
|
364
|
+
|
365
|
+
#{install_busser}
|
366
|
+
INSTALL
|
367
|
+
else
|
368
|
+
info('Installing Puppet Collections, will try to determine platform os')
|
369
|
+
<<-INSTALL
|
370
|
+
|
371
|
+
#{Util.shell_helpers}
|
372
|
+
#{custom_pre_install_command}
|
373
|
+
if [ ! -d "#{config[:puppet_coll_remote_path]}" ]; then
|
374
|
+
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ] || [ -f /etc/oracle-release ] || \
|
375
|
+
[ -f /etc/system-release ] || [ grep -q 'Amazon Linux' /etc/system-release ]; then
|
376
|
+
echo "-----> #{sudo_env('yum')} -y --nogpgcheck install #{config[:puppet_yum_collections_repo]}"
|
377
|
+
#{sudo_env('yum')} -y --nogpgcheck install #{config[:puppet_yum_collections_repo]}
|
378
|
+
#{sudo_env('yum')} -y --nogpgcheck install puppet-agent#{puppet_redhat_version}
|
379
|
+
else
|
380
|
+
#{sudo('apt-get')} -y install wget
|
381
|
+
#{sudo('wget')} #{wget_proxy_parm} #{config[:puppet_apt_collections_repo]}
|
382
|
+
#{sudo('dpkg')} -i #{puppet_apt_coll_repo_file}
|
383
|
+
#{sudo('apt-get')} update
|
384
|
+
#{sudo_env('apt-get')} -y install puppet-agent#{puppet_debian_version}
|
385
|
+
fi
|
386
|
+
fi
|
387
|
+
#{install_eyaml("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
388
|
+
#{install_eyaml_gpg("#{config[:puppet_coll_remote_path]}/puppet/bin/gem")}
|
389
|
+
#{install_deep_merge}
|
390
|
+
#{install_busser}
|
391
|
+
#{custom_install_command}
|
392
|
+
INSTALL
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
def install_deep_merge
|
397
|
+
return unless config[:hiera_deep_merge]
|
398
|
+
<<-INSTALL
|
399
|
+
# Support for hash merge lookups to recursively merge hash keys
|
400
|
+
if [[ $(#{sudo('gem')} list deep_merge -i) == 'false' ]]; then
|
401
|
+
echo '-----> Installing deep_merge to provide deep_merge of hiera hashes'
|
402
|
+
#{sudo('gem')} install #{gem_proxy_parm} --no-ri --no-rdoc deep_merge
|
403
|
+
fi
|
404
|
+
INSTALL
|
405
|
+
end
|
406
|
+
|
407
|
+
def install_eyaml(gem_cmd = 'gem')
|
408
|
+
return unless config[:hiera_eyaml]
|
409
|
+
<<-INSTALL
|
410
|
+
# A backend for Hiera that provides per-value asymmetric encryption of sensitive data
|
411
|
+
if [[ $(#{sudo(gem_cmd)} list hiera-eyaml -i) == 'false' ]]; then
|
412
|
+
echo '-----> Installing hiera-eyaml to provide encryption of hiera data'
|
413
|
+
#{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc highline -v 1.6.21
|
414
|
+
#{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml
|
415
|
+
fi
|
416
|
+
INSTALL
|
417
|
+
end
|
418
|
+
|
419
|
+
def install_eyaml_gpg(gem_cmd = 'gem')
|
420
|
+
return unless config[:hiera_eyaml_gpg]
|
421
|
+
<<-INSTALL
|
422
|
+
# A backend for Hiera that provides per-value asymmetric encryption of sensitive data
|
423
|
+
if [[ $(#{sudo(gem_cmd)} list hiera-eyaml-gpg -i) == 'false' ]]; then
|
424
|
+
echo '-----> Installing hiera-eyaml-gpg to provide encryption of hiera data'
|
425
|
+
#{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc highline -v 1.6.21
|
426
|
+
#{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml
|
427
|
+
#{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc hiera-eyaml-gpg
|
428
|
+
#{sudo(gem_cmd)} install #{gem_proxy_parm} --no-ri --no-rdoc ruby_gpg
|
429
|
+
fi
|
430
|
+
INSTALL
|
431
|
+
end
|
432
|
+
|
433
|
+
def install_busser
|
434
|
+
return unless config[:require_chef_for_busser]
|
435
|
+
info("Install busser on #{puppet_platform}")
|
436
|
+
case puppet_platform
|
437
|
+
when /^windows.*/
|
438
|
+
# https://raw.githubusercontent.com/opscode/knife-windows/master/lib/chef/knife/bootstrap/windows-chef-client-msi.erb
|
439
|
+
<<-INSTALL
|
440
|
+
$webclient = New-Object System.Net.WebClient; $webclient.DownloadFile('https://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chef-windows-11.12.8-1.windows.msi','chef-windows-11.12.8-1.windows.msi')
|
441
|
+
msiexec /qn /i chef-windows-11.12.8-1.windows.msi
|
442
|
+
|
443
|
+
cmd.exe /C "SET PATH=%PATH%;`"C:\\opscode\\chef\\embedded\\bin`";`"C:\\tmp\\busser\\gems\\bin`""
|
444
|
+
|
445
|
+
INSTALL
|
446
|
+
else
|
447
|
+
<<-INSTALL
|
448
|
+
#{Util.shell_helpers}
|
449
|
+
# install chef omnibus so that busser works as this is needed to run tests :(
|
450
|
+
# TODO: work out how to install enough ruby
|
451
|
+
# and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
|
452
|
+
# whole chef client
|
453
|
+
if [ ! -d "/opt/chef" ]
|
454
|
+
then
|
455
|
+
echo '-----> Installing Chef Omnibus to install busser to run tests'
|
456
|
+
#{export_http_proxy_parm}
|
457
|
+
#{export_https_proxy_parm}
|
458
|
+
#{export_no_proxy_parm}
|
459
|
+
do_download #{chef_url} /tmp/install.sh
|
460
|
+
#{sudo('sh')} /tmp/install.sh
|
461
|
+
fi
|
462
|
+
INSTALL
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
def install_omnibus_command
|
467
|
+
info('Installing puppet using puppet omnibus')
|
468
|
+
|
469
|
+
version = ''
|
470
|
+
version = "-v #{config[:puppet_version]}" unless config[:puppet_version].nil?
|
471
|
+
|
472
|
+
<<-INSTALL
|
473
|
+
#{Util.shell_helpers}
|
474
|
+
if [ ! $(which puppet) ]; then
|
475
|
+
echo "-----> Installing Puppet Omnibus"
|
476
|
+
#{export_http_proxy_parm}
|
477
|
+
#{export_https_proxy_parm}
|
478
|
+
#{export_no_proxy_parm}
|
479
|
+
do_download #{config[:puppet_omnibus_url]} /tmp/install_puppet.sh
|
480
|
+
#{sudo_env('sh')} /tmp/install_puppet.sh #{version}
|
481
|
+
fi
|
482
|
+
INSTALL
|
483
|
+
end
|
484
|
+
|
485
|
+
def install_hiera
|
486
|
+
return unless config[:install_hiera]
|
487
|
+
<<-INSTALL
|
488
|
+
#{sudo_env('apt-get')} -y install #{hiera_package}
|
489
|
+
INSTALL
|
490
|
+
end
|
491
|
+
|
492
|
+
def hiera_package
|
493
|
+
"#{config[:hiera_package]}#{puppet_hiera_debian_version}"
|
494
|
+
end
|
495
|
+
|
496
|
+
# /bin/wget -P /etc/pki/rpm-gpg/ http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
|
497
|
+
# changed to curl
|
498
|
+
|
499
|
+
def install_puppet_yum_repo
|
500
|
+
<<-INSTALL
|
501
|
+
rhelversion=$(cat /etc/redhat-release | grep 'release 7')
|
502
|
+
# For CentOS7/RHEL7 the rdo release contains puppetlabs repo, creating conflict. Create temp-repo
|
503
|
+
#{sudo_env('curl')} -o /etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs
|
504
|
+
if [ -n "$rhelversion" ]; then
|
505
|
+
echo '[puppettemp-products]
|
506
|
+
name=Puppet Labs Products - \$basearch
|
507
|
+
baseurl=http://yum.puppetlabs.com/el/7/products/\$basearch
|
508
|
+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs
|
509
|
+
enabled=0
|
510
|
+
gpgcheck=1
|
511
|
+
[puppettemp-deps]
|
512
|
+
name=Puppet Labs Dependencies - \$basearch
|
513
|
+
baseurl=http://yum.puppetlabs.com/el/7/dependencies/\$basearch
|
514
|
+
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs
|
515
|
+
enabled=0
|
516
|
+
gpgcheck=1' | sudo tee /etc/yum.repos.d/puppettemp.repo > /dev/null
|
517
|
+
sudo sed -i 's/^[ \t]*//' /etc/yum.repos.d/puppettemp.repo
|
518
|
+
#{update_packages_redhat_cmd}
|
519
|
+
#{sudo_env('yum')} -y --enablerepo=puppettemp-products --enablerepo=puppettemp-deps install puppet#{puppet_redhat_version}
|
520
|
+
# Clean up temporary puppet repo
|
521
|
+
sudo rm -rf /etc/pki/rpm-gpg/RPM-GPG-KEY-puppetlabs
|
522
|
+
sudo rm -rf /etc/yum.repos.d/puppettemp.repo
|
523
|
+
else
|
524
|
+
#{sudo('rpm')} -ivh #{proxy_parm} #{puppet_yum_repo}
|
525
|
+
#{update_packages_redhat_cmd}
|
526
|
+
#{sudo_env('yum')} -y --nogpgcheck install puppet#{puppet_redhat_version}
|
527
|
+
fi
|
528
|
+
INSTALL
|
529
|
+
end
|
530
|
+
|
531
|
+
def custom_pre_install_command
|
532
|
+
<<-INSTALL
|
533
|
+
#{config[:custom_pre_install_command]}
|
534
|
+
INSTALL
|
535
|
+
end
|
536
|
+
|
537
|
+
def custom_install_command
|
538
|
+
<<-INSTALL
|
539
|
+
#{config[:custom_install_command]}
|
540
|
+
INSTALL
|
541
|
+
end
|
542
|
+
|
543
|
+
def init_command
|
544
|
+
todelete = %w[modules manifests files hiera hiera.yaml hiera.global.yaml facter spec enc environment]
|
545
|
+
.map { |dir| File.join(config[:root_path], dir) }
|
546
|
+
todelete += [hiera_data_remote_path,
|
547
|
+
'/etc/hiera.yaml',
|
548
|
+
"#{puppet_dir}/hiera.yaml",
|
549
|
+
spec_files_remote_path.to_s,
|
550
|
+
"#{puppet_dir}/fileserver.conf"]
|
551
|
+
todelete << File.join(puppet_dir, puppet_environment) if puppet_environment
|
552
|
+
todelete << File.join(puppet_environmentpath_remote_path, puppet_environment) if puppet_environment_config && puppet_environment
|
553
|
+
cmd = "#{sudo(rm_command_paths(todelete))};"
|
554
|
+
cmd += " #{mkdir_command} #{config[:root_path]};"
|
555
|
+
cmd += " #{sudo(mkdir_command)} #{puppet_dir}"
|
556
|
+
debug(cmd)
|
557
|
+
cmd
|
558
|
+
end
|
559
|
+
|
560
|
+
def create_sandbox
|
561
|
+
super
|
562
|
+
debug("Creating local sandbox in #{sandbox_path}")
|
563
|
+
yield if block_given?
|
564
|
+
prepare_modules
|
565
|
+
prepare_manifests
|
566
|
+
prepare_files
|
567
|
+
prepare_facter_file
|
568
|
+
prepare_facts
|
569
|
+
prepare_puppet_config
|
570
|
+
prepare_hiera_config
|
571
|
+
prepare_puppet_environment
|
572
|
+
prepare_fileserver_config
|
573
|
+
prepare_hiera_data
|
574
|
+
prepare_enc
|
575
|
+
prepare_spec_files
|
576
|
+
info('Finished Preparing files for transfer')
|
577
|
+
end
|
578
|
+
|
579
|
+
def cleanup_sandbox
|
580
|
+
return if sandbox_path.nil?
|
581
|
+
debug("Cleaning up local sandbox in #{sandbox_path}")
|
582
|
+
FileUtils.rmtree(sandbox_path)
|
583
|
+
return if remove_repo.nil?
|
584
|
+
debug("Cleaning up remote sandbox: #{remove_repo}")
|
585
|
+
instance.remote_exec remove_repo
|
586
|
+
end
|
587
|
+
|
588
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
589
|
+
def prepare_command
|
590
|
+
commands = []
|
591
|
+
if puppet_git_init
|
592
|
+
commands << [
|
593
|
+
sudo('rm -rf'), '/etc/puppet'
|
594
|
+
].join(' ')
|
595
|
+
|
596
|
+
commands << [
|
597
|
+
sudo('git clone'), puppet_git_init, '/etc/puppet'
|
598
|
+
].join(' ')
|
599
|
+
end
|
600
|
+
|
601
|
+
if puppet_git_pr
|
602
|
+
commands << [
|
603
|
+
sudo('git'),
|
604
|
+
'--git-dir=/etc/puppet/.git/',
|
605
|
+
'fetch -f',
|
606
|
+
'origin',
|
607
|
+
"pull/#{puppet_git_pr}/head:pr_#{puppet_git_pr}"
|
608
|
+
].join(' ')
|
609
|
+
|
610
|
+
commands << [
|
611
|
+
sudo('git'),
|
612
|
+
'--git-dir=/etc/puppet/.git/',
|
613
|
+
'--work-tree=/etc/puppet/',
|
614
|
+
'checkout',
|
615
|
+
"pr_#{puppet_git_pr}"
|
616
|
+
].join(' ')
|
617
|
+
end
|
618
|
+
|
619
|
+
if puppet_config
|
620
|
+
commands << [
|
621
|
+
sudo(cp_command),
|
622
|
+
File.join(config[:root_path], 'puppet.conf'),
|
623
|
+
puppet_dir
|
624
|
+
].join(' ')
|
625
|
+
end
|
626
|
+
|
627
|
+
if fileserver_config
|
628
|
+
commands << [
|
629
|
+
sudo(cp_command),
|
630
|
+
File.join(config[:root_path], 'fileserver.conf'),
|
631
|
+
puppet_dir
|
632
|
+
].join(' ')
|
633
|
+
end
|
634
|
+
|
635
|
+
if hiera_data
|
636
|
+
commands << [
|
637
|
+
sudo(mkdir_command), hiera_data_remote_path
|
638
|
+
].join(' ')
|
639
|
+
commands << [
|
640
|
+
sudo("#{cp_command} -r"), File.join(config[:root_path], 'hiera/*'), hiera_data_remote_path
|
641
|
+
].join(' ')
|
642
|
+
end
|
643
|
+
|
644
|
+
if hiera_eyaml
|
645
|
+
commands << [
|
646
|
+
sudo(mkdir_command), hiera_eyaml_key_remote_path
|
647
|
+
].join(' ')
|
648
|
+
commands << [
|
649
|
+
sudo("#{cp_command} -r"), File.join(config[:root_path], 'hiera_keys/*'), hiera_eyaml_key_remote_path
|
650
|
+
].join(' ')
|
651
|
+
end
|
652
|
+
|
653
|
+
if hiera_eyaml_gpg
|
654
|
+
commands << [
|
655
|
+
sudo('mkdir -p'), hiera_eyaml_gpg_remote_path
|
656
|
+
].join(' ')
|
657
|
+
commands << [
|
658
|
+
sudo('cp -r'), File.join(config[:root_path], hiera_eyaml_gpg_recipients), hiera_eyaml_gpg_remote_path
|
659
|
+
].join(' ')
|
660
|
+
commands << [
|
661
|
+
sudo('cp -r'), File.join(config[:root_path], hiera_eyaml_gpg_secring), hiera_eyaml_gpg_remote_path
|
662
|
+
].join(' ')
|
663
|
+
commands << [
|
664
|
+
sudo('cp -r'), File.join(config[:root_path], hiera_eyaml_gpg_pubring), hiera_eyaml_gpg_remote_path
|
665
|
+
].join(' ')
|
666
|
+
end
|
667
|
+
|
668
|
+
if puppet_environment
|
669
|
+
commands << [
|
670
|
+
sudo('ln -s '), config[:root_path], File.join(puppet_dir, puppet_environment)
|
671
|
+
].join(' ')
|
672
|
+
end
|
673
|
+
|
674
|
+
if puppet_environment_config && puppet_environment
|
675
|
+
commands << [
|
676
|
+
sudo(mkdir_command), puppet_environmentpath_remote_path
|
677
|
+
].join(' ')
|
678
|
+
commands << [
|
679
|
+
sudo(mkdir_command), File.join(puppet_environmentpath_remote_path, puppet_environment)
|
680
|
+
].join(' ')
|
681
|
+
commands << [
|
682
|
+
sudo('ln -s '), File.join(config[:root_path], 'modules'), File.join(puppet_environmentpath_remote_path, puppet_environment, puppet_environment_remote_modules_path)
|
683
|
+
].join(' ')
|
684
|
+
commands << [
|
685
|
+
sudo('ln -s '), File.join(config[:root_path], 'manifests'), File.join(puppet_environmentpath_remote_path, puppet_environment, puppet_environment_remote_manifests_path)
|
686
|
+
].join(' ')
|
687
|
+
commands << [
|
688
|
+
sudo('ln -s '), File.join(config[:root_path], 'hiera'), File.join(puppet_environmentpath_remote_path, puppet_environment, puppet_environment_remote_hieradata_path)
|
689
|
+
].join(' ')
|
690
|
+
commands << [
|
691
|
+
sudo('cp'), File.join(config[:root_path], 'environment', 'environment.conf'), File.join(puppet_environmentpath_remote_path, puppet_environment, 'environment.conf')
|
692
|
+
].join(' ')
|
693
|
+
commands << [
|
694
|
+
sudo('cp'), File.join(config[:root_path], 'environment', 'hiera.yaml'), File.join(puppet_environmentpath_remote_path, puppet_environment, 'hiera.yaml')
|
695
|
+
].join(' ')
|
696
|
+
end
|
697
|
+
|
698
|
+
if spec_files_path && spec_files_remote_path
|
699
|
+
commands << [
|
700
|
+
sudo(mkdir_command), spec_files_remote_path
|
701
|
+
].join(' ')
|
702
|
+
commands << [
|
703
|
+
sudo("#{cp_command} -r"), File.join(config[:root_path], 'spec/*'), spec_files_remote_path
|
704
|
+
].join(' ')
|
705
|
+
end
|
706
|
+
|
707
|
+
if config[:puppet_enc]
|
708
|
+
commands << [
|
709
|
+
sudo('chmod 755'), File.join("#{config[:root_path]}/enc", File.basename(config[:puppet_enc]))
|
710
|
+
].join(' ')
|
711
|
+
end
|
712
|
+
|
713
|
+
command = powershell? ? commands.join('; ') : commands.join(' && ')
|
714
|
+
debug(command)
|
715
|
+
command
|
716
|
+
end
|
717
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
718
|
+
|
719
|
+
def run_command
|
720
|
+
return config[:puppet_apply_command] unless config[:puppet_apply_command].nil?
|
721
|
+
result = [
|
722
|
+
facterlib,
|
723
|
+
custom_facts,
|
724
|
+
puppet_manifestdir,
|
725
|
+
puppet_cmd,
|
726
|
+
'apply',
|
727
|
+
File.join(config[:root_path], 'manifests', manifest),
|
728
|
+
"--modulepath=#{File.join(config[:root_path], 'modules')}",
|
729
|
+
"--fileserverconfig=#{File.join(config[:root_path], 'fileserver.conf')}",
|
730
|
+
custom_options,
|
731
|
+
puppet_environment_flag,
|
732
|
+
puppet_noop_flag,
|
733
|
+
puppet_enc_flag,
|
734
|
+
puppet_hiera_flag,
|
735
|
+
puppet_detailed_exitcodes_flag,
|
736
|
+
puppet_verbose_flag,
|
737
|
+
puppet_debug_flag,
|
738
|
+
puppet_logdest_flag,
|
739
|
+
puppet_future_parser_flag,
|
740
|
+
puppet_show_diff_flag,
|
741
|
+
puppet_whitelist_exit_code
|
742
|
+
].join(' ')
|
743
|
+
if config[:custom_post_apply_command]
|
744
|
+
custom_post_apply_trap = <<-TRAP
|
745
|
+
function custom_post_apply_command {
|
746
|
+
#{config[:custom_post_apply_command]}
|
747
|
+
}
|
748
|
+
trap custom_post_apply_command EXIT
|
749
|
+
TRAP
|
750
|
+
end
|
751
|
+
result = <<-RUN
|
752
|
+
#{config[:custom_pre_apply_command]}
|
753
|
+
#{custom_post_apply_trap}
|
754
|
+
#{result}
|
755
|
+
RUN
|
756
|
+
info("Going to invoke puppet apply with: #{result}")
|
757
|
+
result
|
758
|
+
end
|
759
|
+
|
760
|
+
protected
|
761
|
+
|
762
|
+
def load_needed_dependencies!
|
763
|
+
return unless File.exist?(puppetfile)
|
764
|
+
return unless config[:resolve_with_librarian_puppet] || config[:resolve_with_r10k]
|
765
|
+
if config[:resolve_with_librarian_puppet]
|
766
|
+
require 'kitchen/provisioner/puppet/librarian'
|
767
|
+
debug("Puppetfile found at #{puppetfile}, loading Librarian-Puppet")
|
768
|
+
Puppet::Librarian.load!(logger)
|
769
|
+
elsif config[:resolve_with_r10k]
|
770
|
+
require 'kitchen/provisioner/puppet/r10k'
|
771
|
+
debug("Puppetfile found at #{puppetfile}, loading R10K")
|
772
|
+
Puppet::R10K.load!(logger)
|
773
|
+
end
|
774
|
+
end
|
775
|
+
|
776
|
+
def tmpmodules_dir
|
777
|
+
File.join(sandbox_path, 'modules')
|
778
|
+
end
|
779
|
+
|
780
|
+
def puppetfile
|
781
|
+
config[:puppetfile_path] || ''
|
782
|
+
end
|
783
|
+
|
784
|
+
def modulefile
|
785
|
+
config[:modulefile_path] || ''
|
786
|
+
end
|
787
|
+
|
788
|
+
def metadata_json
|
789
|
+
config[:metadata_json_path] || ''
|
790
|
+
end
|
791
|
+
|
792
|
+
def manifest
|
793
|
+
config[:manifest]
|
794
|
+
end
|
795
|
+
|
796
|
+
def manifests
|
797
|
+
config[:manifests_path]
|
798
|
+
end
|
799
|
+
|
800
|
+
def modules
|
801
|
+
config[:modules_path]
|
802
|
+
end
|
803
|
+
|
804
|
+
def files
|
805
|
+
config[:files_path] || 'files'
|
806
|
+
end
|
807
|
+
|
808
|
+
def puppet_config
|
809
|
+
config[:puppet_config_path]
|
810
|
+
end
|
811
|
+
|
812
|
+
def puppet_environment
|
813
|
+
config[:puppet_environment]
|
814
|
+
end
|
815
|
+
|
816
|
+
def puppet_environment_config
|
817
|
+
if config[:puppet_environment_config_path] && !puppet_environment
|
818
|
+
raise("ERROR: found environment config '#{config[:puppet_environment_config_path]}', however no 'puppet_environment' is specified. Please specify 'puppet_environment' or unset 'puppet_environment_config_path' in .kitchen.yml")
|
819
|
+
end
|
820
|
+
config[:puppet_environment_config_path]
|
821
|
+
end
|
822
|
+
|
823
|
+
def puppet_environment_remote_modules_path
|
824
|
+
config[:puppet_environment_remote_modules_path]
|
825
|
+
end
|
826
|
+
|
827
|
+
def puppet_environment_remote_manifests_path
|
828
|
+
config[:puppet_environment_remote_manifests_path]
|
829
|
+
end
|
830
|
+
|
831
|
+
def puppet_environment_remote_hieradata_path
|
832
|
+
config[:puppet_environment_remote_hieradata_path]
|
833
|
+
end
|
834
|
+
|
835
|
+
def puppet_git_init
|
836
|
+
config[:puppet_git_init]
|
837
|
+
end
|
838
|
+
|
839
|
+
def puppet_git_pr
|
840
|
+
config[:puppet_git_pr]
|
841
|
+
end
|
842
|
+
|
843
|
+
def hiera_config
|
844
|
+
config[:hiera_config_path]
|
845
|
+
end
|
846
|
+
|
847
|
+
def puppet_environment_hiera_config
|
848
|
+
config[:puppet_environment_hiera_config_path]
|
849
|
+
end
|
850
|
+
|
851
|
+
def fileserver_config
|
852
|
+
config[:fileserver_config_path]
|
853
|
+
end
|
854
|
+
|
855
|
+
def hiera_data
|
856
|
+
config[:hiera_data_path]
|
857
|
+
end
|
858
|
+
|
859
|
+
def hiera_data_remote_path
|
860
|
+
return config[:hiera_data_remote_path] if config[:hiera_data_remote_path]
|
861
|
+
|
862
|
+
if config[:require_puppet_collections]
|
863
|
+
powershell? ? 'C:/ProgramData/PuppetLabs/code/environments/production/hieradata' : '/etc/puppetlabs/code/environments/production/hieradata'
|
864
|
+
else
|
865
|
+
powershell? ? 'C:/ProgramData/PuppetLabs/hiera/var' : '/var/lib/hiera'
|
866
|
+
end
|
867
|
+
end
|
868
|
+
|
869
|
+
def hiera_writer
|
870
|
+
config[:hiera_writer_files]
|
871
|
+
end
|
872
|
+
|
873
|
+
def hiera_eyaml
|
874
|
+
config[:hiera_eyaml]
|
875
|
+
end
|
876
|
+
|
877
|
+
def hiera_eyaml_gpg
|
878
|
+
config[:hiera_eyaml_gpg]
|
879
|
+
end
|
880
|
+
|
881
|
+
def hiera_eyaml_gpg_recipients
|
882
|
+
config[:hiera_eyaml_gpg_recipients]
|
883
|
+
end
|
884
|
+
|
885
|
+
def hiera_eyaml_gpg_secring
|
886
|
+
config[:hiera_eyaml_gpg_secring]
|
887
|
+
end
|
888
|
+
|
889
|
+
def hiera_eyaml_gpg_pubring
|
890
|
+
config[:hiera_eyaml_gpg_pubring]
|
891
|
+
end
|
892
|
+
|
893
|
+
def hiera_eyaml_gpg_remote_path
|
894
|
+
config[:hiera_eyaml_gpg_remote_path]
|
895
|
+
end
|
896
|
+
|
897
|
+
def hiera_eyaml_key_path
|
898
|
+
config[:hiera_eyaml_key_path]
|
899
|
+
end
|
900
|
+
|
901
|
+
def hiera_eyaml_key_remote_path
|
902
|
+
config[:hiera_eyaml_key_remote_path]
|
903
|
+
end
|
904
|
+
|
905
|
+
def hiera_deep_merge
|
906
|
+
config[:hiera_deep_merge]
|
907
|
+
end
|
908
|
+
|
909
|
+
def librarian_puppet_ssl_file
|
910
|
+
config[:librarian_puppet_ssl_file]
|
911
|
+
end
|
912
|
+
|
913
|
+
def r10k_ssl_file
|
914
|
+
config[:r10k_puppet_ssl_file] || config[:librarian_puppet_ssl_file]
|
915
|
+
end
|
916
|
+
|
917
|
+
def puppet_cmd
|
918
|
+
return '& "C:\Program Files\Puppet Labs\Puppet\bin\puppet"' if powershell?
|
919
|
+
|
920
|
+
puppet_bin = config[:require_puppet_collections] ? "#{config[:puppet_coll_remote_path]}/bin/puppet" : config[:puppet_binary]
|
921
|
+
|
922
|
+
if config[:puppet_no_sudo]
|
923
|
+
puppet_bin
|
924
|
+
else
|
925
|
+
sudo_env(puppet_bin)
|
926
|
+
end
|
927
|
+
end
|
928
|
+
|
929
|
+
def puppet_dir
|
930
|
+
return 'C:/ProgramData/PuppetLabs/puppet/etc' if powershell?
|
931
|
+
config[:require_puppet_collections] ? '/etc/puppetlabs/puppet' : '/etc/puppet'
|
932
|
+
end
|
933
|
+
|
934
|
+
def puppet_environmentpath_remote_path
|
935
|
+
return config[:puppet_environmentpath_remote_path] if config[:puppet_environmentpath_remote_path]
|
936
|
+
if config[:puppet_version] =~ /^3/
|
937
|
+
powershell? ? 'C:/ProgramData/PuppetLabs/puppet/etc' : '/etc/puppet/environments'
|
938
|
+
else
|
939
|
+
powershell? ? 'C:/ProgramData/PuppetLabs/code/environments' : '/etc/puppetlabs/code/environments'
|
940
|
+
end
|
941
|
+
end
|
942
|
+
|
943
|
+
def hiera_config_dir
|
944
|
+
return 'C:/ProgramData/PuppetLabs/puppet/etc' if powershell?
|
945
|
+
config[:require_puppet_collections] ? '/etc/puppetlabs/code' : '/etc/puppet'
|
946
|
+
end
|
947
|
+
|
948
|
+
def puppet_debian_version
|
949
|
+
config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
|
950
|
+
end
|
951
|
+
|
952
|
+
def facter_debian_version
|
953
|
+
config[:facter_version] ? "=#{config[:facter_version]}" : nil
|
954
|
+
end
|
955
|
+
|
956
|
+
def puppet_hiera_debian_version
|
957
|
+
config[:hiera_version] ? "=#{config[:hiera_version]}" : nil
|
958
|
+
end
|
959
|
+
|
960
|
+
def puppet_redhat_version
|
961
|
+
if puppet_platform == 'amazon'
|
962
|
+
config[:puppet_version]
|
963
|
+
else
|
964
|
+
config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
|
965
|
+
end
|
966
|
+
end
|
967
|
+
|
968
|
+
def puppet_windows_version
|
969
|
+
config[:puppet_version] ? config[:puppet_version].to_s : 'latest'
|
970
|
+
end
|
971
|
+
|
972
|
+
def puppet_environment_flag
|
973
|
+
if config[:puppet_version] =~ /^2/
|
974
|
+
config[:puppet_environment] ? "--environment=#{puppet_environment}" : nil
|
975
|
+
else
|
976
|
+
config[:puppet_environment] ? "--environment=#{puppet_environment} --environmentpath=#{puppet_environmentpath_remote_path}" : nil
|
977
|
+
end
|
978
|
+
end
|
979
|
+
|
980
|
+
def puppet_manifestdir
|
981
|
+
return nil if config[:require_puppet_collections]
|
982
|
+
return nil if config[:puppet_environment]
|
983
|
+
return nil if powershell?
|
984
|
+
bash_vars = "export MANIFESTDIR='#{File.join(config[:root_path], 'manifests')}';"
|
985
|
+
debug(bash_vars)
|
986
|
+
bash_vars
|
987
|
+
end
|
988
|
+
|
989
|
+
def custom_options
|
990
|
+
config[:custom_options] || ''
|
991
|
+
end
|
992
|
+
|
993
|
+
def puppet_noop_flag
|
994
|
+
config[:puppet_noop] ? '--noop' : nil
|
995
|
+
end
|
996
|
+
|
997
|
+
def puppet_debug_flag
|
998
|
+
config[:puppet_debug] ? '-d' : nil
|
999
|
+
end
|
1000
|
+
|
1001
|
+
def puppet_verbose_flag
|
1002
|
+
config[:puppet_verbose] ? '-v' : nil
|
1003
|
+
end
|
1004
|
+
|
1005
|
+
def puppet_show_diff_flag
|
1006
|
+
config[:puppet_show_diff] ? '--show_diff' : nil
|
1007
|
+
end
|
1008
|
+
|
1009
|
+
def puppet_future_parser_flag
|
1010
|
+
config[:puppet_future_parser] ? '--parser=future' : nil
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
def puppet_logdest_flag
|
1014
|
+
return nil unless config[:puppet_logdest]
|
1015
|
+
destinations = ''
|
1016
|
+
config[:puppet_logdest].each do |dest|
|
1017
|
+
destinations << "--logdest #{dest} "
|
1018
|
+
end
|
1019
|
+
destinations
|
1020
|
+
end
|
1021
|
+
|
1022
|
+
def puppet_platform
|
1023
|
+
config[:platform].gsub(/-.*/, '')
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
def update_packages_debian_cmd
|
1027
|
+
config[:update_package_repos] ? "#{sudo_env('apt-get')} update" : nil
|
1028
|
+
end
|
1029
|
+
|
1030
|
+
def update_packages_redhat_cmd
|
1031
|
+
# #{sudo('yum')}
|
1032
|
+
config[:update_package_repos] ? "#{sudo_env('yum')} makecache" : nil
|
1033
|
+
end
|
1034
|
+
|
1035
|
+
def sudo_env(pm)
|
1036
|
+
s = https_proxy ? "https_proxy=#{https_proxy}" : nil
|
1037
|
+
p = http_proxy ? "http_proxy=#{http_proxy}" : nil
|
1038
|
+
n = no_proxy ? "no_proxy=#{no_proxy}" : nil
|
1039
|
+
p || s ? "#{sudo('env')} #{p} #{s} #{n} #{pm}" : sudo(pm).to_s
|
1040
|
+
end
|
1041
|
+
|
1042
|
+
def remove_puppet_repo
|
1043
|
+
config[:remove_puppet_repo]
|
1044
|
+
end
|
1045
|
+
|
1046
|
+
def spec_files_path
|
1047
|
+
config[:spec_files_path]
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
def spec_files_remote_path
|
1051
|
+
config[:spec_files_remote_path]
|
1052
|
+
end
|
1053
|
+
|
1054
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
1055
|
+
def facterlib
|
1056
|
+
factpath = nil
|
1057
|
+
factpath = File.join(config[:root_path], 'facter').to_s if config[:install_custom_facts] && config[:custom_facts].any?
|
1058
|
+
factpath = File.join(config[:root_path], 'facter').to_s if config[:facter_file]
|
1059
|
+
factpath = "#{factpath}:" if config[:facterlib] && !factpath.nil?
|
1060
|
+
factpath = "#{factpath}#{config[:facterlib]}" if config[:facterlib]
|
1061
|
+
return nil if factpath.nil?
|
1062
|
+
bash_vars = "export FACTERLIB='#{factpath}';"
|
1063
|
+
debug(bash_vars)
|
1064
|
+
bash_vars
|
1065
|
+
end
|
1066
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
1067
|
+
|
1068
|
+
def custom_facts
|
1069
|
+
return nil if config[:custom_facts].none?
|
1070
|
+
return nil if config[:install_custom_facts]
|
1071
|
+
if powershell?
|
1072
|
+
environment_vars = config[:custom_facts].map { |k, v| "$env:FACTER_#{k}='#{v}'" }.join('; ')
|
1073
|
+
environment_vars = "#{environment_vars};"
|
1074
|
+
else
|
1075
|
+
environment_vars = config[:custom_facts].map { |k, v| "FACTER_#{k}=#{v}" }.join(' ')
|
1076
|
+
environment_vars = "export #{environment_vars};"
|
1077
|
+
end
|
1078
|
+
debug(environment_vars)
|
1079
|
+
environment_vars
|
1080
|
+
end
|
1081
|
+
|
1082
|
+
def puppet_enc_flag
|
1083
|
+
config[:puppet_enc] ? "--node_terminus=exec --external_nodes=#{config[:root_path]}/enc/#{File.basename(config[:puppet_enc])}" : nil
|
1084
|
+
end
|
1085
|
+
|
1086
|
+
def puppet_hiera_flag
|
1087
|
+
hiera_config ? "--hiera_config=#{config[:root_path]}/hiera.global.yaml" : nil
|
1088
|
+
end
|
1089
|
+
|
1090
|
+
def puppet_detailed_exitcodes_flag
|
1091
|
+
config[:puppet_detailed_exitcodes] ? '--detailed-exitcodes' : nil
|
1092
|
+
end
|
1093
|
+
|
1094
|
+
def remove_repo
|
1095
|
+
remove_puppet_repo ? "#{sudo('rm')} -rf /tmp/kitchen #{hiera_data_remote_path} #{hiera_eyaml_key_remote_path} #{puppet_dir}/* " : nil
|
1096
|
+
end
|
1097
|
+
|
1098
|
+
def puppet_whitelist_exit_code
|
1099
|
+
if config[:puppet_whitelist_exit_code].nil?
|
1100
|
+
powershell? ? '; exit $LASTEXITCODE' : nil
|
1101
|
+
elsif powershell?
|
1102
|
+
"; if(@(#{[config[:puppet_whitelist_exit_code]].join(', ')}) -contains $LASTEXITCODE) {exit 0} else {exit $LASTEXITCODE}"
|
1103
|
+
else
|
1104
|
+
'; RC=$?; [ ' + [config[:puppet_whitelist_exit_code]].flatten.map { |x| "\$RC -eq #{x}" }.join(' -o ') + ' ] && exit 0; exit $RC'
|
1105
|
+
end
|
1106
|
+
end
|
1107
|
+
|
1108
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
1109
|
+
def puppet_apt_repo
|
1110
|
+
platform_version = config[:platform].partition('-')[2]
|
1111
|
+
case puppet_platform
|
1112
|
+
when 'ubuntu'
|
1113
|
+
case platform_version
|
1114
|
+
when '14.10'
|
1115
|
+
# Utopic Repo
|
1116
|
+
'https://apt.puppetlabs.com/puppetlabs-release-utopic.deb'
|
1117
|
+
when '14.04'
|
1118
|
+
# Trusty Repo
|
1119
|
+
'https://apt.puppetlabs.com/puppetlabs-release-trusty.deb'
|
1120
|
+
when '12.04'
|
1121
|
+
# Precise Repo
|
1122
|
+
'https://apt.puppetlabs.com/puppetlabs-release-precise.deb'
|
1123
|
+
else
|
1124
|
+
# Configured Repo
|
1125
|
+
config[:puppet_apt_repo]
|
1126
|
+
end
|
1127
|
+
when 'debian'
|
1128
|
+
case platform_version.gsub(/\..*/, '')
|
1129
|
+
when '8'
|
1130
|
+
# Debian Jessie
|
1131
|
+
'https://apt.puppetlabs.com/puppetlabs-release-jessie.deb'
|
1132
|
+
when '7'
|
1133
|
+
# Debian Wheezy
|
1134
|
+
'https://apt.puppetlabs.com/puppetlabs-release-wheezy.deb'
|
1135
|
+
when '6'
|
1136
|
+
# Debian Squeeze
|
1137
|
+
'https://apt.puppetlabs.com/puppetlabs-release-squeeze.deb'
|
1138
|
+
else
|
1139
|
+
# Configured Repo
|
1140
|
+
config[:puppet_apt_repo]
|
1141
|
+
end
|
1142
|
+
else
|
1143
|
+
debug("Apt repo detection failed with platform - #{config[:platform]}")
|
1144
|
+
false
|
1145
|
+
end
|
1146
|
+
end
|
1147
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
1148
|
+
|
1149
|
+
def puppet_apt_repo_file
|
1150
|
+
puppet_apt_repo.split('/').last if puppet_apt_repo
|
1151
|
+
end
|
1152
|
+
|
1153
|
+
def puppet_apt_coll_repo_file
|
1154
|
+
config[:puppet_apt_collections_repo].split('/').last
|
1155
|
+
end
|
1156
|
+
|
1157
|
+
def puppet_yum_repo
|
1158
|
+
config[:puppet_yum_repo]
|
1159
|
+
end
|
1160
|
+
|
1161
|
+
def proxy_parm
|
1162
|
+
http_proxy ? "--httpproxy #{URI.parse(http_proxy).host.downcase} --httpport #{URI.parse(http_proxy).port} " : nil
|
1163
|
+
end
|
1164
|
+
|
1165
|
+
def gem_proxy_parm
|
1166
|
+
p = http_proxy ? "--http-proxy #{http_proxy}" : nil
|
1167
|
+
n = no_proxy ? "--no-http-proxy #{no_proxy}" : nil
|
1168
|
+
p || n ? "#{p} #{n}" : nil
|
1169
|
+
end
|
1170
|
+
|
1171
|
+
def wget_proxy_parm
|
1172
|
+
p = http_proxy ? "-e http_proxy=#{http_proxy}" : nil
|
1173
|
+
s = https_proxy ? "-e https_proxy=#{https_proxy}" : nil
|
1174
|
+
n = no_proxy ? "-e no_proxy=#{no_proxy}" : nil
|
1175
|
+
p || s ? "-e use_proxy=yes #{p} #{s} #{n}" : nil
|
1176
|
+
end
|
1177
|
+
|
1178
|
+
def posh_proxy_parm
|
1179
|
+
http_proxy ? "-Proxy #{http_proxy}" : nil
|
1180
|
+
end
|
1181
|
+
|
1182
|
+
def powershell?
|
1183
|
+
return true if powershell_shell?
|
1184
|
+
return true if puppet_platform =~ /^windows.*/
|
1185
|
+
false
|
1186
|
+
end
|
1187
|
+
|
1188
|
+
def export_http_proxy_parm
|
1189
|
+
http_proxy ? "export http_proxy=#{http_proxy}" : nil
|
1190
|
+
end
|
1191
|
+
|
1192
|
+
def export_https_proxy_parm
|
1193
|
+
https_proxy ? "export https_proxy=#{https_proxy}" : nil
|
1194
|
+
end
|
1195
|
+
|
1196
|
+
def export_no_proxy_parm
|
1197
|
+
no_proxy ? "export no_proxy=#{no_proxy}" : nil
|
1198
|
+
end
|
1199
|
+
|
1200
|
+
def http_proxy
|
1201
|
+
config[:http_proxy]
|
1202
|
+
end
|
1203
|
+
|
1204
|
+
def https_proxy
|
1205
|
+
config[:https_proxy]
|
1206
|
+
end
|
1207
|
+
|
1208
|
+
def no_proxy
|
1209
|
+
config[:no_proxy]
|
1210
|
+
end
|
1211
|
+
|
1212
|
+
def chef_url
|
1213
|
+
config[:chef_bootstrap_url]
|
1214
|
+
end
|
1215
|
+
|
1216
|
+
def prepare_manifests
|
1217
|
+
info('Preparing manifests')
|
1218
|
+
debug("Using manifests from #{manifests}")
|
1219
|
+
|
1220
|
+
tmp_manifests_dir = File.join(sandbox_path, 'manifests')
|
1221
|
+
FileUtils.mkdir_p(tmp_manifests_dir)
|
1222
|
+
FileUtils.cp_r(Dir.glob("#{manifests}/*"), tmp_manifests_dir)
|
1223
|
+
end
|
1224
|
+
|
1225
|
+
def prepare_files
|
1226
|
+
info('Preparing files')
|
1227
|
+
unless File.directory?(files)
|
1228
|
+
info 'nothing to do for files'
|
1229
|
+
return
|
1230
|
+
end
|
1231
|
+
|
1232
|
+
debug("Using files from #{files}")
|
1233
|
+
|
1234
|
+
tmp_files_dir = File.join(sandbox_path, 'files')
|
1235
|
+
FileUtils.mkdir_p(tmp_files_dir)
|
1236
|
+
FileUtils.cp_r(Dir.glob("#{files}/*"), tmp_files_dir)
|
1237
|
+
end
|
1238
|
+
|
1239
|
+
def prepare_facter_file
|
1240
|
+
return unless config[:facter_file]
|
1241
|
+
info 'Copying facter file'
|
1242
|
+
facter_dir = File.join(sandbox_path, 'facter')
|
1243
|
+
FileUtils.mkdir_p(facter_dir)
|
1244
|
+
FileUtils.cp_r(config[:facter_file], facter_dir)
|
1245
|
+
end
|
1246
|
+
|
1247
|
+
def prepare_facts
|
1248
|
+
return unless config[:install_custom_facts]
|
1249
|
+
return unless config[:custom_facts]
|
1250
|
+
info 'Installing custom facts'
|
1251
|
+
facter_dir = File.join(sandbox_path, 'facter')
|
1252
|
+
FileUtils.mkdir_p(facter_dir)
|
1253
|
+
tmp_facter_file = File.join(facter_dir, 'kitchen.rb')
|
1254
|
+
facter_facts = Hash[config[:custom_facts]]
|
1255
|
+
File.open(tmp_facter_file, 'a') do |out|
|
1256
|
+
facter_facts.each do |k, v|
|
1257
|
+
out.write "\nFacter.add(:#{k}) do\n"
|
1258
|
+
out.write " setcode do\n"
|
1259
|
+
if [Array, Hash].include? v.class
|
1260
|
+
out.write " #{v}\n"
|
1261
|
+
else
|
1262
|
+
out.write " \"#{v}\"\n"
|
1263
|
+
end
|
1264
|
+
out.write " end\n"
|
1265
|
+
out.write "end\n"
|
1266
|
+
end
|
1267
|
+
end
|
1268
|
+
end
|
1269
|
+
|
1270
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
1271
|
+
def prepare_modules
|
1272
|
+
info('Preparing modules')
|
1273
|
+
|
1274
|
+
FileUtils.mkdir_p(tmpmodules_dir)
|
1275
|
+
resolve_with_librarian if File.exist?(puppetfile) && config[:resolve_with_librarian_puppet]
|
1276
|
+
resolve_with_r10k if File.exist?(puppetfile) && config[:resolve_with_r10k] && !config[:resolve_with_librarian_puppet]
|
1277
|
+
modules_to_copy = {}
|
1278
|
+
|
1279
|
+
# If root dir (.) is a module, add it for copying
|
1280
|
+
self_name = read_self_module_name
|
1281
|
+
modules_to_copy[self_name] = '.' if self_name
|
1282
|
+
|
1283
|
+
if modules
|
1284
|
+
modules_array = modules.split(':')
|
1285
|
+
modules_array.each do |m_path|
|
1286
|
+
Dir.glob("#{m_path}/*").each do |m|
|
1287
|
+
name = File.basename(m)
|
1288
|
+
if modules_to_copy.include? name
|
1289
|
+
debug("Found duplicated module: #{name}. The path taking precedence: '#{modules_to_copy[name]}', ignoring '#{m}'")
|
1290
|
+
else
|
1291
|
+
modules_to_copy[name] = m
|
1292
|
+
end
|
1293
|
+
end
|
1294
|
+
end
|
1295
|
+
end
|
1296
|
+
|
1297
|
+
if modules_to_copy.empty?
|
1298
|
+
info 'Nothing to do for modules'
|
1299
|
+
else
|
1300
|
+
copy_modules(modules_to_copy, tmpmodules_dir)
|
1301
|
+
end
|
1302
|
+
end
|
1303
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
1304
|
+
|
1305
|
+
def copy_modules(modules, destination)
|
1306
|
+
excluded_paths = %w[modules pkg] + config[:ignored_paths_from_root]
|
1307
|
+
debug("Copying modules to directory: #{destination}")
|
1308
|
+
modules.each do |name, source|
|
1309
|
+
next unless File.directory?(source)
|
1310
|
+
debug("Copying module #{name} from #{source}...")
|
1311
|
+
target = "#{destination}/#{name}"
|
1312
|
+
FileUtils.mkdir_p(target) unless File.exist? target
|
1313
|
+
FileUtils.cp_r(
|
1314
|
+
Dir.glob("#{source}/*").reject { |entry| entry =~ /#{excluded_paths.join('$|')}$/ },
|
1315
|
+
target,
|
1316
|
+
remove_destination: true
|
1317
|
+
)
|
1318
|
+
end
|
1319
|
+
end
|
1320
|
+
|
1321
|
+
def read_self_module_name
|
1322
|
+
if File.exist?(modulefile)
|
1323
|
+
warn('Modulefile found but this is deprecated, ignoring it, see https://tickets.puppetlabs.com/browse/PUP-1188')
|
1324
|
+
end
|
1325
|
+
|
1326
|
+
return unless File.exist?(metadata_json)
|
1327
|
+
module_name = nil
|
1328
|
+
begin
|
1329
|
+
module_name = JSON.parse(IO.read(metadata_json))['name'].split('-').last
|
1330
|
+
rescue JSON::ParserError
|
1331
|
+
error("not able to load or parse #{metadata_json} for the name of the module")
|
1332
|
+
end
|
1333
|
+
|
1334
|
+
module_name
|
1335
|
+
end
|
1336
|
+
|
1337
|
+
def prepare_puppet_config
|
1338
|
+
return unless puppet_config
|
1339
|
+
|
1340
|
+
info('Preparing puppet.conf')
|
1341
|
+
debug("Using puppet config from #{puppet_config}")
|
1342
|
+
|
1343
|
+
FileUtils.cp_r(puppet_config, File.join(sandbox_path, 'puppet.conf'))
|
1344
|
+
end
|
1345
|
+
|
1346
|
+
def prepare_enc
|
1347
|
+
return unless config[:puppet_enc]
|
1348
|
+
info 'Copying enc file'
|
1349
|
+
enc_dir = File.join(sandbox_path, 'enc')
|
1350
|
+
FileUtils.mkdir_p(enc_dir)
|
1351
|
+
FileUtils.cp_r(config[:puppet_enc], File.join(enc_dir, '/'))
|
1352
|
+
end
|
1353
|
+
|
1354
|
+
def prepare_puppet_environment
|
1355
|
+
return unless puppet_environment_config
|
1356
|
+
|
1357
|
+
info('Preparing Environment Config')
|
1358
|
+
environment_dir = File.join(sandbox_path, 'environment')
|
1359
|
+
FileUtils.mkdir_p(environment_dir)
|
1360
|
+
debug("Using Environment Config environment.conf from #{puppet_environment_config}")
|
1361
|
+
FileUtils.cp_r(puppet_environment_config, File.join(environment_dir, 'environment.conf'))
|
1362
|
+
if puppet_environment_hiera_config
|
1363
|
+
debug("Using Environment Hiera Config hiera.yaml from #{puppet_environment_hiera_config}")
|
1364
|
+
FileUtils.cp_r(puppet_environment_hiera_config, File.join(environment_dir, 'hiera.yaml'))
|
1365
|
+
else
|
1366
|
+
info('No Environment hiera.yaml found')
|
1367
|
+
end
|
1368
|
+
end
|
1369
|
+
|
1370
|
+
def prepare_hiera_config
|
1371
|
+
return unless hiera_config
|
1372
|
+
|
1373
|
+
info('Preparing hiera (global layer)')
|
1374
|
+
debug("Using hiera from #{hiera_config}")
|
1375
|
+
|
1376
|
+
FileUtils.cp_r(hiera_config, File.join(sandbox_path, 'hiera.global.yaml'))
|
1377
|
+
end
|
1378
|
+
|
1379
|
+
def prepare_fileserver_config
|
1380
|
+
return unless fileserver_config
|
1381
|
+
|
1382
|
+
info('Preparing fileserver')
|
1383
|
+
debug("Using fileserver config from #{fileserver_config}")
|
1384
|
+
|
1385
|
+
FileUtils.cp_r(fileserver_config, File.join(sandbox_path, 'fileserver.conf'))
|
1386
|
+
end
|
1387
|
+
|
1388
|
+
def prepare_hiera_data
|
1389
|
+
return unless hiera_data
|
1390
|
+
info('Preparing hiera data')
|
1391
|
+
tmp_hiera_dir = File.join(sandbox_path, 'hiera')
|
1392
|
+
debug("Copying hiera data from #{hiera_data} to #{tmp_hiera_dir}")
|
1393
|
+
FileUtils.mkdir_p(tmp_hiera_dir)
|
1394
|
+
FileUtils.cp_r(Dir.glob("#{hiera_data}/*"), tmp_hiera_dir)
|
1395
|
+
if hiera_writer
|
1396
|
+
hiera_writer.each do |file|
|
1397
|
+
file.each do |filename, hiera_hash|
|
1398
|
+
debug("Creating hiera yaml file #{tmp_hiera_dir}/#{filename}")
|
1399
|
+
dir = File.join(tmp_hiera_dir, File.dirname(filename.to_s))
|
1400
|
+
FileUtils.mkdir_p(dir)
|
1401
|
+
output_file = open(File.join(dir, File.basename(filename.to_s)), 'w')
|
1402
|
+
# convert json and back before converting to yaml to recursively convert symbols to strings, heh
|
1403
|
+
output_file.write JSON[hiera_hash.to_json].to_yaml
|
1404
|
+
output_file.close
|
1405
|
+
end
|
1406
|
+
end
|
1407
|
+
end
|
1408
|
+
return unless hiera_eyaml_key_path
|
1409
|
+
tmp_hiera_key_dir = File.join(sandbox_path, 'hiera_keys')
|
1410
|
+
debug("Copying hiera eyaml keys from #{hiera_eyaml_key_path} to #{tmp_hiera_key_dir}")
|
1411
|
+
FileUtils.mkdir_p(tmp_hiera_key_dir)
|
1412
|
+
FileUtils.cp_r(Dir.glob("#{hiera_eyaml_key_path}/*"), tmp_hiera_key_dir)
|
1413
|
+
end
|
1414
|
+
|
1415
|
+
def prepare_spec_files
|
1416
|
+
return unless spec_files_path
|
1417
|
+
info('Preparing spec files')
|
1418
|
+
tmp_spec_dir = File.join(sandbox_path, 'spec')
|
1419
|
+
debug("Copying specs from #{spec_files_path} to #{tmp_spec_dir}")
|
1420
|
+
FileUtils.mkdir_p(tmp_spec_dir)
|
1421
|
+
FileUtils.cp_r(Dir.glob(File.join(spec_files_path, '*')).reject { |entry| entry =~ /fixtures$/ }, tmp_spec_dir) if config[:ignore_spec_fixtures]
|
1422
|
+
FileUtils.cp_r(Dir.glob("#{spec_files_path}/*"), tmp_spec_dir) unless config[:ignore_spec_fixtures]
|
1423
|
+
end
|
1424
|
+
|
1425
|
+
def resolve_with_librarian
|
1426
|
+
require 'kitchen/provisioner/puppet/librarian'
|
1427
|
+
Kitchen.mutex.synchronize do
|
1428
|
+
ENV['SSL_CERT_FILE'] = librarian_puppet_ssl_file if librarian_puppet_ssl_file
|
1429
|
+
Puppet::Librarian.new(puppetfile, tmpmodules_dir, logger).resolve
|
1430
|
+
ENV['SSL_CERT_FILE'] = '' if librarian_puppet_ssl_file
|
1431
|
+
end
|
1432
|
+
end
|
1433
|
+
|
1434
|
+
def resolve_with_r10k
|
1435
|
+
require 'kitchen/provisioner/puppet/r10k'
|
1436
|
+
Kitchen.mutex.synchronize do
|
1437
|
+
ENV['SSL_CERT_FILE'] = r10k_ssl_file if r10k_ssl_file
|
1438
|
+
Puppet::R10K.new(puppetfile, tmpmodules_dir, logger).resolve
|
1439
|
+
ENV['SSL_CERT_FILE'] = '' if r10k_ssl_file
|
1440
|
+
end
|
1441
|
+
end
|
1442
|
+
|
1443
|
+
def cp_command
|
1444
|
+
return 'cp -force' if powershell?
|
1445
|
+
'cp'
|
1446
|
+
end
|
1447
|
+
|
1448
|
+
def rm_command
|
1449
|
+
return 'rm -force -recurse' if powershell?
|
1450
|
+
'rm -rf'
|
1451
|
+
end
|
1452
|
+
|
1453
|
+
def mkdir_command
|
1454
|
+
return 'mkdir -force -path' if powershell?
|
1455
|
+
'mkdir -p'
|
1456
|
+
end
|
1457
|
+
|
1458
|
+
def rm_command_paths(paths)
|
1459
|
+
return :nil if paths.length.zero?
|
1460
|
+
return "#{rm_command} \"#{paths.join('", "')}\"" if powershell?
|
1461
|
+
"#{rm_command} #{paths.join(' ')}"
|
1462
|
+
end
|
1463
|
+
end
|
1464
|
+
end
|
1465
|
+
end
|