kitchen-puppet 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +15 -0
- data/kitchen-puppet.gemspec +29 -0
- data/lib/kitchen-puppet/version.rb +5 -0
- data/lib/kitchen/provisioner/puppet/librarian.rb +82 -0
- data/lib/kitchen/provisioner/puppet_apply.rb +385 -0
- data/lib/kitchen/provisioner/puppet_apply_spec.rb +33 -0
- data/provisioner_options.md +68 -0
- metadata +64 -0
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# kitchen-puppet
|
2
|
+
A Test Kitchen Provisioner for Puppet
|
3
|
+
|
4
|
+
The provider works by passing the puppet repository based on attributes in .kitchen.yml & calling puppet apply.
|
5
|
+
|
6
|
+
This provider has been tested against the Ubuntu 1204 and Centos 6.5 boxes running in vagrant/virtualbox.
|
7
|
+
|
8
|
+
## Requirements
|
9
|
+
You'll need a driver box without a chef installation so puppet can be installed. Puppet have one at http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box or http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box.
|
10
|
+
|
11
|
+
|
12
|
+
## Installation & Setup
|
13
|
+
You'll need the test-kitchen & kitchen-puppet gem's installed in your system, along with kitchen-vagrant or some ther suitable driver for test-kitchen.
|
14
|
+
|
15
|
+
Please see the Provisioner Options (https://github.com/neillturner/kitchen-puppet/blob/master/provisioner_options.md).
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$:.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
require 'kitchen-puppet/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "kitchen-puppet"
|
8
|
+
s.version = Kitchen::Puppet::VERSION
|
9
|
+
s.authors = ["Neill Turner"]
|
10
|
+
s.email = ["neillwturner@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/neillturner/kitchen-puppet"
|
12
|
+
s.summary = "puppet provisioner for test-kitchen"
|
13
|
+
candidates = Dir.glob("{lib}/**/*") + ['README.md', 'provisioner_options.md', 'kitchen-puppet.gemspec']
|
14
|
+
s.files = candidates.sort
|
15
|
+
s.platform = Gem::Platform::RUBY
|
16
|
+
s.require_paths = ['lib']
|
17
|
+
s.rubyforge_project = '[none]'
|
18
|
+
s.description = <<-EOF
|
19
|
+
== DESCRIPTION:
|
20
|
+
|
21
|
+
Puppet Provisioner for Test Kitchen
|
22
|
+
|
23
|
+
== FEATURES:
|
24
|
+
|
25
|
+
Supports puppet apply, hiera and custom facts
|
26
|
+
|
27
|
+
EOF
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Author:: Fletcher Nichol (<fnichol@nichol.ca>) Neill Turner (<neillwturner@gmail.com>)
|
4
|
+
#
|
5
|
+
# Copyright (C) 2013, Fletcher Nichol, Neill Turner
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
|
19
|
+
require 'kitchen/errors'
|
20
|
+
require 'kitchen/logging'
|
21
|
+
|
22
|
+
module Kitchen
|
23
|
+
|
24
|
+
module Provisioner
|
25
|
+
|
26
|
+
module Puppet
|
27
|
+
|
28
|
+
# Puppet module resolver that uses Librarian-Puppet and a Puppetfile to
|
29
|
+
# calculate # dependencies.
|
30
|
+
#
|
31
|
+
class Librarian
|
32
|
+
|
33
|
+
include Logging
|
34
|
+
|
35
|
+
|
36
|
+
def initialize(puppetfile, path, logger = Kitchen.logger)
|
37
|
+
@puppetfile = puppetfile
|
38
|
+
@path = path
|
39
|
+
@logger = logger
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.load!(logger = Kitchen.logger)
|
43
|
+
load_librarian!(logger)
|
44
|
+
end
|
45
|
+
|
46
|
+
def resolve
|
47
|
+
version = ::Librarian::Puppet::VERSION
|
48
|
+
info("Resolving module dependencies with Librarian-Puppet #{version}...")
|
49
|
+
debug("Using Puppetfile from #{puppetfile}")
|
50
|
+
|
51
|
+
env = ::Librarian::Puppet::Environment.new(
|
52
|
+
:project_path => File.dirname(puppetfile))
|
53
|
+
env.config_db.local["path"] = path
|
54
|
+
::Librarian::Action::Resolve.new(env).run
|
55
|
+
::Librarian::Action::Install.new(env).run
|
56
|
+
end
|
57
|
+
|
58
|
+
attr_reader :puppetfile, :path, :logger
|
59
|
+
|
60
|
+
def self.load_librarian!(logger)
|
61
|
+
first_load = require 'librarian/puppet/environment'
|
62
|
+
require 'librarian/action/resolve'
|
63
|
+
require 'librarian/action/install'
|
64
|
+
|
65
|
+
version = ::Librarian::Puppet::VERSION
|
66
|
+
if first_load
|
67
|
+
logger.debug("Librarian-Puppet #{version} library loaded")
|
68
|
+
else
|
69
|
+
logger.debug("Librarian-Puppet #{version} previously loaded")
|
70
|
+
end
|
71
|
+
rescue LoadError => e
|
72
|
+
logger.fatal("The `librarian-puppet' gem is missing and must be installed" +
|
73
|
+
" or cannot be properly activated. Run" +
|
74
|
+
" `gem install librarian-puppet` or add the following to your" +
|
75
|
+
" Gemfile if you are using Bundler: `gem 'librarian-puppet'`.")
|
76
|
+
raise UserError,
|
77
|
+
"Could not load or activate Librarian-Puppet (#{e.message})"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,385 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Author:: Chris Lundquist (<chris.lundquist@github.com>) Neill Turner (<neillwturner@gmail.com>)
|
4
|
+
#
|
5
|
+
# Copyright (C) 2013,2014 Chris Lundquist, Neill Turner
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
# See https://github.com/neillturner/kitchen-puppet/blob/master/provisioner_options.md
|
20
|
+
# for documentation configuration parameters with puppet_apply provisioner.
|
21
|
+
#
|
22
|
+
|
23
|
+
require 'kitchen/provisioner/base'
|
24
|
+
require 'kitchen/provisioner/puppet/librarian'
|
25
|
+
|
26
|
+
module Kitchen
|
27
|
+
|
28
|
+
module Provisioner
|
29
|
+
#
|
30
|
+
# Puppet Apply provisioner.
|
31
|
+
#
|
32
|
+
class PuppetApply < Base
|
33
|
+
attr_accessor :tmp_dir
|
34
|
+
|
35
|
+
default_config :require_puppet_omnibus, false
|
36
|
+
# TODO use something like https://github.com/fnichol/omnibus-puppet
|
37
|
+
default_config :puppet_omnibus_url, nil
|
38
|
+
default_config :puppet_omnibus_remote_path, '/opt/puppet'
|
39
|
+
default_config :puppet_version, nil
|
40
|
+
default_config :require_puppet_repo, true
|
41
|
+
default_config :puppet_apt_repo, "http://apt.puppetlabs.com/puppetlabs-release-precise.deb"
|
42
|
+
default_config :puppet_yum_repo, "https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm"
|
43
|
+
default_config :chef_bootstrap_url, "https://www.getchef.com/chef/install.sh"
|
44
|
+
|
45
|
+
default_config :hiera_data_remote_path, '/var/lib/hiera'
|
46
|
+
default_config :manifest, 'site.pp'
|
47
|
+
|
48
|
+
default_config :manifests_path do |provisioner|
|
49
|
+
provisioner.calculate_path('manifests') or
|
50
|
+
raise 'No manifests_path detected. Please specify one in .kitchen.yml'
|
51
|
+
end
|
52
|
+
|
53
|
+
default_config :modules_path do |provisioner|
|
54
|
+
provisioner.calculate_path('modules') or
|
55
|
+
raise 'No modules_path detected. Please specify one in .kitchen.yml'
|
56
|
+
end
|
57
|
+
|
58
|
+
default_config :hiera_data_path do |provisioner|
|
59
|
+
provisioner.calculate_path('hiera')
|
60
|
+
end
|
61
|
+
|
62
|
+
default_config :hiera_config_path do |provisioner|
|
63
|
+
provisioner.calculate_path('hiera.yaml', :file)
|
64
|
+
end
|
65
|
+
|
66
|
+
default_config :puppetfile_path do |provisioner|
|
67
|
+
provisioner.calculate_path('Puppetfile', :file)
|
68
|
+
end
|
69
|
+
|
70
|
+
default_config :puppet_debug, false
|
71
|
+
default_config :puppet_verbose, false
|
72
|
+
default_config :puppet_noop, false
|
73
|
+
default_config :puppet_platform, ''
|
74
|
+
default_config :update_package_repos, true
|
75
|
+
default_config :custom_facts, {}
|
76
|
+
|
77
|
+
def calculate_path(path, type = :directory)
|
78
|
+
base = File.join(config[:kitchen_root], 'puppet')
|
79
|
+
candidates = []
|
80
|
+
candidates << File.join(base, instance.suite.name, path)
|
81
|
+
candidates << File.join(base, path)
|
82
|
+
candidates << File.join(Dir.pwd, path)
|
83
|
+
|
84
|
+
candidates.find do |c|
|
85
|
+
type == :directory ? File.directory?(c) : File.file?(c)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def install_command
|
90
|
+
return unless config[:require_puppet_omnibus] or config[:require_puppet_repo]
|
91
|
+
if config[:require_puppet_omnibus]
|
92
|
+
info("Installing puppet using puppet omnibus")
|
93
|
+
version = if !config[:puppet_version].nil?
|
94
|
+
"-v #{config[:puppet_version]}"
|
95
|
+
else
|
96
|
+
""
|
97
|
+
end
|
98
|
+
<<-INSTALL
|
99
|
+
if [ ! -d "#{config[:puppet_omnibus_remote_path]}" ]; then
|
100
|
+
echo "-----> Installing Puppet Omnibus"
|
101
|
+
curl -o /tmp/puppet_install.sh #{config[:puppet_omnibus_url]}
|
102
|
+
#{sudo('sh')} /tmp/puppet_install.sh #{version}
|
103
|
+
fi
|
104
|
+
#{install_busser}
|
105
|
+
INSTALL
|
106
|
+
else
|
107
|
+
case puppet_platform
|
108
|
+
when "debian", "ubuntu"
|
109
|
+
info("Installing puppet on #{puppet_platform}")
|
110
|
+
<<-INSTALL
|
111
|
+
if [ ! $(which puppet) ]; then
|
112
|
+
#{sudo('wget')} #{puppet_apt_repo}
|
113
|
+
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
114
|
+
#{update_packages_debian_cmd}
|
115
|
+
#{sudo('apt-get')} -y install puppet#{puppet_debian_version}
|
116
|
+
fi
|
117
|
+
#{install_busser}
|
118
|
+
INSTALL
|
119
|
+
when "redhat", "centos", "fedora"
|
120
|
+
info("Installing puppet on #{puppet_platform}")
|
121
|
+
<<-INSTALL
|
122
|
+
if [ ! $(which puppet) ]; then
|
123
|
+
#{sudo('rpm')} -ivh #{puppet_yum_repo}
|
124
|
+
#{update_packages_redhat_cmd}
|
125
|
+
#{sudo('yum')} -y install puppet#{puppet_redhat_version}
|
126
|
+
fi
|
127
|
+
#{install_busser}
|
128
|
+
INSTALL
|
129
|
+
else
|
130
|
+
info("Installing puppet, will try to determine platform os")
|
131
|
+
<<-INSTALL
|
132
|
+
if [ ! $(which puppet) ]; then
|
133
|
+
if [ -f /etc/centos-release ] || [ -f /etc/redhat-release ]; then
|
134
|
+
#{sudo('rpm')} -ivh #{puppet_yum_repo}
|
135
|
+
#{update_packages_redhat_cmd}
|
136
|
+
#{sudo('yum')} -y install puppet#{puppet_redhat_version}
|
137
|
+
else
|
138
|
+
#{sudo('wget')} #{puppet_apt_repo}
|
139
|
+
#{sudo('dpkg')} -i #{puppet_apt_repo_file}
|
140
|
+
#{update_packages_debian_cmd}
|
141
|
+
#{sudo('apt-get')} -y install puppet#{puppet_debian_version}
|
142
|
+
fi
|
143
|
+
fi
|
144
|
+
#{install_busser}
|
145
|
+
INSTALL
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def install_busser
|
151
|
+
<<-INSTALL
|
152
|
+
# install chef omnibus so that busser works as this is needed to run tests :(
|
153
|
+
# TODO: work out how to install enough ruby
|
154
|
+
# and set busser: { :ruby_bindir => '/usr/bin/ruby' } so that we dont need the
|
155
|
+
# whole chef client
|
156
|
+
if [ ! -d "/opt/chef" ]
|
157
|
+
then
|
158
|
+
echo "-----> Installing Chef Omnibus to install busser to run tests"
|
159
|
+
curl -o /tmp/install.sh #{chef_url}
|
160
|
+
#{sudo('sh')} /tmp/install.sh
|
161
|
+
fi
|
162
|
+
INSTALL
|
163
|
+
end
|
164
|
+
|
165
|
+
def init_command
|
166
|
+
dirs = %w{modules manifests hiera hiera.yaml}.
|
167
|
+
map { |dir| File.join(config[:root_path], dir) }.join(" ")
|
168
|
+
cmd = "#{sudo('rm')} -rf #{dirs} #{hiera_data_remote_path} /etc/hiera.yaml /etc/puppet/hiera.yaml;"
|
169
|
+
cmd = cmd+" mkdir -p #{config[:root_path]}"
|
170
|
+
debug(cmd)
|
171
|
+
cmd
|
172
|
+
end
|
173
|
+
|
174
|
+
def create_sandbox
|
175
|
+
super
|
176
|
+
debug("Creating local sandbox in #{sandbox_path}")
|
177
|
+
|
178
|
+
yield if block_given?
|
179
|
+
|
180
|
+
prepare_modules
|
181
|
+
prepare_manifests
|
182
|
+
prepare_hiera_config
|
183
|
+
prepare_hiera_data
|
184
|
+
info('Finished Preparing files for transfer')
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
def cleanup_sandbox
|
189
|
+
return if sandbox_path.nil?
|
190
|
+
debug("Cleaning up local sandbox in #{sandbox_path}")
|
191
|
+
FileUtils.rmtree(sandbox_path)
|
192
|
+
end
|
193
|
+
|
194
|
+
def prepare_command
|
195
|
+
commands = []
|
196
|
+
|
197
|
+
if hiera_config
|
198
|
+
commands << [
|
199
|
+
sudo('cp'), File.join(config[:root_path],'hiera.yaml'), '/etc/',
|
200
|
+
].join(' ')
|
201
|
+
|
202
|
+
commands << [
|
203
|
+
sudo('cp'), File.join(config[:root_path],'hiera.yaml'), '/etc/puppet/',
|
204
|
+
].join(' ')
|
205
|
+
end
|
206
|
+
|
207
|
+
if hiera_data and hiera_data_remote_path == '/var/lib/hiera'
|
208
|
+
commands << [
|
209
|
+
sudo('cp -r'), File.join(config[:root_path], 'hiera'), '/var/lib/'
|
210
|
+
].join(' ')
|
211
|
+
end
|
212
|
+
|
213
|
+
if hiera_data and hiera_data_remote_path != '/var/lib/hiera'
|
214
|
+
commands << [
|
215
|
+
sudo('mkdir -p'), hiera_data_remote_path
|
216
|
+
].join(' ')
|
217
|
+
commands << [
|
218
|
+
sudo('cp -r'), File.join(config[:root_path], 'hiera/*'), hiera_data_remote_path
|
219
|
+
].join(' ')
|
220
|
+
end
|
221
|
+
|
222
|
+
command = commands.join(' && ')
|
223
|
+
debug(command)
|
224
|
+
command
|
225
|
+
end
|
226
|
+
|
227
|
+
def run_command
|
228
|
+
[
|
229
|
+
custom_facts,
|
230
|
+
sudo('puppet'),
|
231
|
+
'apply',
|
232
|
+
File.join(config[:root_path], 'manifests', manifest),
|
233
|
+
"--modulepath=#{File.join(config[:root_path], 'modules')}",
|
234
|
+
"--manifestdir=#{File.join(config[:root_path], 'manifests')}",
|
235
|
+
puppet_noop_flag,
|
236
|
+
puppet_verbose_flag,
|
237
|
+
puppet_debug_flag,
|
238
|
+
].join(" ")
|
239
|
+
end
|
240
|
+
|
241
|
+
protected
|
242
|
+
|
243
|
+
def load_needed_dependencies!
|
244
|
+
if File.exists?(puppetfile)
|
245
|
+
debug("Puppetfile found at #{puppetfile}, loading Librarian-Puppet")
|
246
|
+
Puppet::Librarian.load!(logger)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
def tmpmodules_dir
|
251
|
+
File.join(sandbox_path, 'modules')
|
252
|
+
end
|
253
|
+
|
254
|
+
def puppetfile
|
255
|
+
config[:puppetfile_path] or ''
|
256
|
+
end
|
257
|
+
|
258
|
+
def manifest
|
259
|
+
config[:manifest]
|
260
|
+
end
|
261
|
+
|
262
|
+
def manifests
|
263
|
+
config[:manifests_path]
|
264
|
+
end
|
265
|
+
|
266
|
+
def modules
|
267
|
+
config[:modules_path]
|
268
|
+
end
|
269
|
+
|
270
|
+
def hiera_config
|
271
|
+
config[:hiera_config_path]
|
272
|
+
end
|
273
|
+
|
274
|
+
def hiera_data
|
275
|
+
config[:hiera_data_path]
|
276
|
+
end
|
277
|
+
|
278
|
+
def hiera_data_remote_path
|
279
|
+
config[:hiera_data_remote_path]
|
280
|
+
end
|
281
|
+
|
282
|
+
def puppet_debian_version
|
283
|
+
config[:puppet_version] ? "=#{config[:puppet_version]}" : nil
|
284
|
+
end
|
285
|
+
|
286
|
+
def puppet_redhat_version
|
287
|
+
config[:puppet_version] ? "-#{config[:puppet_version]}" : nil
|
288
|
+
end
|
289
|
+
|
290
|
+
def puppet_noop_flag
|
291
|
+
config[:puppet_noop] ? '--noop' : nil
|
292
|
+
end
|
293
|
+
|
294
|
+
def puppet_debug_flag
|
295
|
+
config[:puppet_debug] ? '-d' : nil
|
296
|
+
end
|
297
|
+
|
298
|
+
def puppet_verbose_flag
|
299
|
+
config[:puppet_verbose] ? '-v' : nil
|
300
|
+
end
|
301
|
+
|
302
|
+
def puppet_platform
|
303
|
+
config[:puppet_platform].to_s.downcase
|
304
|
+
end
|
305
|
+
|
306
|
+
def update_packages_debian_cmd
|
307
|
+
config[:update_package_repos] ? "#{sudo('apt-get')} update" : nil
|
308
|
+
end
|
309
|
+
|
310
|
+
def update_packages_redhat_cmd
|
311
|
+
config[:update_package_repos] ? "#{sudo('yum')} makecache" : nil
|
312
|
+
end
|
313
|
+
|
314
|
+
def custom_facts
|
315
|
+
return nil if config[:custom_facts].none?
|
316
|
+
bash_vars = config[:custom_facts].map { |k,v| "FACTER_#{k}=#{v}" }.join(" ")
|
317
|
+
bash_vars = "export #{bash_vars};"
|
318
|
+
debug(bash_vars)
|
319
|
+
bash_vars
|
320
|
+
end
|
321
|
+
|
322
|
+
def puppet_apt_repo
|
323
|
+
config[:puppet_apt_repo]
|
324
|
+
end
|
325
|
+
|
326
|
+
def puppet_apt_repo_file
|
327
|
+
config[:puppet_apt_repo].split('/').last
|
328
|
+
end
|
329
|
+
|
330
|
+
def puppet_yum_repo
|
331
|
+
config[:puppet_yum_repo]
|
332
|
+
end
|
333
|
+
|
334
|
+
def chef_url
|
335
|
+
config[:chef_bootstrap_url]
|
336
|
+
end
|
337
|
+
|
338
|
+
def prepare_manifests
|
339
|
+
info('Preparing manifests')
|
340
|
+
debug("Using manifests from #{manifests}")
|
341
|
+
|
342
|
+
tmp_manifests_dir = File.join(sandbox_path, 'manifests')
|
343
|
+
FileUtils.mkdir_p(tmp_manifests_dir)
|
344
|
+
FileUtils.cp_r(Dir.glob("#{manifests}/*"), tmp_manifests_dir)
|
345
|
+
end
|
346
|
+
|
347
|
+
def prepare_modules
|
348
|
+
info('Preparing modules')
|
349
|
+
if File.exists?(puppetfile)
|
350
|
+
resolve_with_librarian
|
351
|
+
end
|
352
|
+
debug("Using modules from #{modules}")
|
353
|
+
|
354
|
+
tmp_modules_dir = File.join(sandbox_path, 'modules')
|
355
|
+
FileUtils.mkdir_p(tmp_modules_dir)
|
356
|
+
FileUtils.cp_r(Dir.glob("#{modules}/*"), tmp_modules_dir)
|
357
|
+
end
|
358
|
+
|
359
|
+
def prepare_hiera_config
|
360
|
+
return unless hiera_config
|
361
|
+
|
362
|
+
info('Preparing hiera')
|
363
|
+
debug("Using hiera from #{hiera_config}")
|
364
|
+
|
365
|
+
FileUtils.cp_r(hiera_config, File.join(sandbox_path, 'hiera.yaml'))
|
366
|
+
end
|
367
|
+
|
368
|
+
def prepare_hiera_data
|
369
|
+
return unless hiera_data
|
370
|
+
info('Preparing hiera data')
|
371
|
+
debug("Using hiera data from #{hiera_data}")
|
372
|
+
|
373
|
+
tmp_hiera_dir = File.join(sandbox_path, 'hiera')
|
374
|
+
FileUtils.mkdir_p(tmp_hiera_dir)
|
375
|
+
FileUtils.cp_r(Dir.glob("#{hiera_data}/*"), tmp_hiera_dir)
|
376
|
+
end
|
377
|
+
|
378
|
+
def resolve_with_librarian
|
379
|
+
Kitchen.mutex.synchronize do
|
380
|
+
Puppet::Librarian.new(puppetfile, tmpmodules_dir, logger).resolve
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Author:: Chris Lundquist (<chris.lundquist@github.com>) Neill Turner (<neillwturner@gmail.com>)
|
4
|
+
#
|
5
|
+
# Copyright (C) 2013,2014 Chris Lundquist, Neill Turner
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
|
19
|
+
require_relative '../../spec_helper'
|
20
|
+
require 'kitchen'
|
21
|
+
|
22
|
+
# Work around for lazy loading
|
23
|
+
require 'kitchen/provisioner/puppet_apply'
|
24
|
+
|
25
|
+
describe Kitchen::Provisioner::PuppetApply do
|
26
|
+
let(:provisioner) do
|
27
|
+
Kitchen::Provisioner.for_plugin("puppet_apply", {})
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should give a sane run_command" do
|
31
|
+
provisioner.run_command.must_match /puppet apply/
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
# Provisioner Options
|
3
|
+
|
4
|
+
key | default value | Notes
|
5
|
+
----|---------------|--------
|
6
|
+
puppet_version | "latest"| desired version, affects apt installs
|
7
|
+
puppet_platform | naively tries to determine | OS platform of server
|
8
|
+
require_puppet_repo | true | Set if using a puppet install from yum or apt repo
|
9
|
+
puppet_apt_repo | "http://apt.puppetlabs.com/puppetlabs-release-precise.deb"| apt repo
|
10
|
+
puppet_yum_repo | "https://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm"| yum repo
|
11
|
+
require_puppet_omnibus | false | Set if using omnibus puppet install
|
12
|
+
puppet_omnibus_url | | omnibus puppet install location.
|
13
|
+
puppet_omnibus_remote_path | "/opt/puppet" | Server Installation location of an omnibus puppet install.
|
14
|
+
manifests_path | | puppet repo manifests directory
|
15
|
+
manifest | 'site.pp' | manifest for puppet apply to run
|
16
|
+
modules_path | | puppet repo manifests directory
|
17
|
+
hiera_data_path | | puppet repo hiera data directory
|
18
|
+
hiera_data_remote_path | "/var/lib/hiera" | Hiera data directory on server
|
19
|
+
puppet_debug| false| Enable full debugging logging
|
20
|
+
puppet_verbose| false| Extra information logging
|
21
|
+
puppet_noop| false| puppet runs in a no-op or dry-run mode
|
22
|
+
update_package_repos| true| update OS repository metadata
|
23
|
+
custom_facts| Hash.new | Hash to set the puppet facts before running puppet apply
|
24
|
+
chef_bootstrap_url |"https://www.getchef.com/chef/install.sh"| the chef (needed for busser to run tests)
|
25
|
+
puppetfile_path | | Path to Puppetfile
|
26
|
+
|
27
|
+
## Configuring Provisioner Options
|
28
|
+
|
29
|
+
The provisioner can be configured globally or per suite, global settings act as defaults for all suites, you can then customise per suite, for example:
|
30
|
+
|
31
|
+
---
|
32
|
+
driver:
|
33
|
+
name: vagrant
|
34
|
+
|
35
|
+
provisioner:
|
36
|
+
name: puppet_apply
|
37
|
+
manifests_path: /repository/puppet_repo/manifests
|
38
|
+
modules_path: /repository/puppet_repo/modules-mycompany
|
39
|
+
hiera_data_path: /repository/puppet_repo/hieradata
|
40
|
+
|
41
|
+
platforms:
|
42
|
+
- name: nocm_ubuntu-12.04
|
43
|
+
driver_plugin: vagrant
|
44
|
+
driver_config:
|
45
|
+
box: nocm_ubuntu-12.04
|
46
|
+
box_url: http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
|
47
|
+
|
48
|
+
suites:
|
49
|
+
- name: default
|
50
|
+
|
51
|
+
|
52
|
+
in this example, vagrant will download a box for ubuntu 1204 with no configuration management installed, then install the latest puppet and puppet apply against a puppet repo from the /repository/puppet_repo directory using the defailt manifest site.pp
|
53
|
+
|
54
|
+
To override a setting at the suite-level, specify the setting name under the suite:
|
55
|
+
|
56
|
+
suites:
|
57
|
+
- name: default
|
58
|
+
manifest: foobar.pp
|
59
|
+
|
60
|
+
### Per-suite Structure
|
61
|
+
|
62
|
+
It can be beneficial to keep different Puppet layouts for different suites. Rather than having to specify the manifest, modules, etc for each suite, you can create the following directory structure and they will automatically be found:
|
63
|
+
|
64
|
+
$kitchen_root/puppet/$suite_name/manifests
|
65
|
+
$kitchen_root/puppet/$suite_name/modules
|
66
|
+
$kitchen_root/puppet/$suite_name/hiera
|
67
|
+
$kitchen_root/puppet/$suite_name/hiera.yaml
|
68
|
+
$kitchen_root/puppet/$suite_name/Puppetfile
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kitchen-puppet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Neill Turner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-25 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! '== DESCRIPTION:
|
15
|
+
|
16
|
+
|
17
|
+
Puppet Provisioner for Test Kitchen
|
18
|
+
|
19
|
+
|
20
|
+
== FEATURES:
|
21
|
+
|
22
|
+
|
23
|
+
Supports puppet apply, hiera and custom facts
|
24
|
+
|
25
|
+
|
26
|
+
'
|
27
|
+
email:
|
28
|
+
- neillwturner@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- README.md
|
34
|
+
- kitchen-puppet.gemspec
|
35
|
+
- lib/kitchen-puppet/version.rb
|
36
|
+
- lib/kitchen/provisioner/puppet/librarian.rb
|
37
|
+
- lib/kitchen/provisioner/puppet_apply.rb
|
38
|
+
- lib/kitchen/provisioner/puppet_apply_spec.rb
|
39
|
+
- provisioner_options.md
|
40
|
+
homepage: https://github.com/neillturner/kitchen-puppet
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project: ! '[none]'
|
60
|
+
rubygems_version: 1.8.28
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: puppet provisioner for test-kitchen
|
64
|
+
test_files: []
|