vagrant-puppetfile 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vagrant/puppetfile/version.rb +2 -2
- data/lib/vagrant/puppetfile.rb +160 -61
- data/lib/vagrant-puppetfile.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d630dfea4265619b7d7011cc3ca686893bd92159
|
4
|
+
data.tar.gz: ce55251db0c8d90e18aefb0cb01d43c465ba7e95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb7211571ab50f91db3b13ced038517a6b90c8e7844edaa0d327e13867b5d16fe07635bb8eedde310c3d59c1a562d3005a8d3479c79bf3643f470542906e05eb
|
7
|
+
data.tar.gz: 2979bf2e51e9ac37773a55c13d9b17b32553957939290f87b8ef8f1daf7048eeef40849b3192596028d2b65f7106f1cbc783d5852271256369d7af861e0709d3
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright (c) 2016 Catalyst.net Ltd
|
2
|
+
# Copyright (c) 2016-2017 Catalyst.net Ltd
|
3
3
|
#
|
4
4
|
# This file is part of vagrant-puppetfile.
|
5
5
|
#
|
@@ -21,6 +21,6 @@
|
|
21
21
|
module Vagrant
|
22
22
|
module Puppetfile
|
23
23
|
NAME = 'vagrant-puppetfile'
|
24
|
-
VERSION = '0.
|
24
|
+
VERSION = '0.4.0'
|
25
25
|
end
|
26
26
|
end
|
data/lib/vagrant/puppetfile.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#
|
2
|
-
# Copyright (c) 2016 Catalyst.net Ltd
|
2
|
+
# Copyright (c) 2016-2017 Catalyst.net Ltd
|
3
3
|
#
|
4
4
|
# This file is part of vagrant-puppetfile.
|
5
5
|
#
|
@@ -25,13 +25,17 @@ require 'shellwords'
|
|
25
25
|
|
26
26
|
module Vagrant
|
27
27
|
module Puppetfile
|
28
|
+
DEFAULT_PUPPETFILE_PATH = 'Puppetfile'
|
29
|
+
DEFAULT_PUPPETFILE_EVALUATOR = 'autodetect'
|
30
|
+
|
28
31
|
class Provisioner < Vagrant.plugin('2', :provisioner)
|
29
|
-
def initialize(machine,
|
32
|
+
def initialize(machine, config)
|
33
|
+
@config = config
|
30
34
|
@logger = Vagrant::UI::Prefixed.new(machine.env.ui, machine.name)
|
31
35
|
end
|
32
36
|
|
33
37
|
def provision
|
34
|
-
Puppetfile.new.
|
38
|
+
Puppetfile.new(@config.path).evaluator(@config.evaluator, @logger).install!
|
35
39
|
rescue Exception => e
|
36
40
|
@logger.error("Failed to evaluate Puppetfile: #{e.message}")
|
37
41
|
end
|
@@ -39,25 +43,29 @@ module Vagrant
|
|
39
43
|
|
40
44
|
class Command < Vagrant.plugin('2', :command)
|
41
45
|
def execute
|
42
|
-
|
43
|
-
|
44
|
-
stderr = Logger.new(STDERR)
|
46
|
+
puppetfile = DEFAULT_PUPPETFILE_PATH
|
47
|
+
evaluator = DEFAULT_PUPPETFILE_EVALUATOR
|
45
48
|
|
46
49
|
options = OptionParser.new do |o|
|
47
50
|
o.banner = 'Usage: vagrant puppetfile install'
|
48
51
|
o.separator ''
|
49
52
|
o.separator 'Options:'
|
50
53
|
o.on('-h', '--help', 'Print this help') do
|
51
|
-
return
|
54
|
+
return @env.ui.info(o.help)
|
55
|
+
end
|
56
|
+
o.on('-e', '--evaluator TYPE', 'Specify the Puppetfile evaluator') do |type|
|
57
|
+
evaluator = type
|
58
|
+
end
|
59
|
+
o.on('-f', '--file PUPPETFILE', 'Specify an alternative Puppetfile') do |path|
|
60
|
+
puppetfile = path
|
52
61
|
end
|
53
62
|
end
|
54
63
|
|
55
64
|
case parse_options(options)
|
56
65
|
when ['install']
|
57
|
-
|
58
|
-
Puppetfile.new.eval(stdout)
|
66
|
+
Puppetfile.new(puppetfile).evaluator(evaluator, @env.ui).install!
|
59
67
|
else
|
60
|
-
|
68
|
+
@env.ui.warn(options.help)
|
61
69
|
exit 1
|
62
70
|
end
|
63
71
|
end
|
@@ -67,88 +75,179 @@ module Vagrant
|
|
67
75
|
end
|
68
76
|
end
|
69
77
|
|
78
|
+
class Config < Vagrant.plugin('2', :config)
|
79
|
+
attr_accessor :path
|
80
|
+
attr_accessor :evaluator
|
81
|
+
|
82
|
+
def initialize
|
83
|
+
@path = UNSET_VALUE
|
84
|
+
@evaluator = UNSET_VALUE
|
85
|
+
end
|
86
|
+
|
87
|
+
def validate(*_)
|
88
|
+
errors = _detected_errors
|
89
|
+
errors << 'path must be a String' unless @path.is_a? String
|
90
|
+
errors << 'evaluator must be a String' unless @evaluator.is_a? String
|
91
|
+
Hash[Vagrant::Puppetfile::Plugin.name => errors]
|
92
|
+
end
|
93
|
+
|
94
|
+
def finalize!
|
95
|
+
@path = DEFAULT_PUPPETFILE_PATH if @path == UNSET_VALUE
|
96
|
+
@evaluator = DEFAULT_PUPPETFILE_EVALUATOR if @evaluator == UNSET_VALUE
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
70
100
|
class Plugin < Vagrant.plugin('2')
|
71
101
|
name 'puppetfile'
|
72
|
-
|
73
|
-
command(
|
102
|
+
config(:puppetfile, :provisioner) { Config }
|
103
|
+
command(:puppetfile) { Command }
|
104
|
+
provisioner(:puppetfile) { Provisioner }
|
74
105
|
end
|
75
106
|
|
76
107
|
class Puppetfile < File
|
77
|
-
def
|
78
|
-
|
108
|
+
def evaluator(type, logger)
|
109
|
+
case File.basename(type)
|
110
|
+
when 'librarian-puppet'
|
111
|
+
Evaluators::Librarian.new(type, path, logger)
|
112
|
+
when 'r10k'
|
113
|
+
Evaluators::R10k.new(type, path, logger)
|
114
|
+
when 'puppet'
|
115
|
+
Evaluators::Puppet.new(type, path, logger)
|
116
|
+
when 'autodetect'
|
117
|
+
evaluator('librarian-puppet', logger) rescue
|
118
|
+
evaluator('r10k', logger) rescue
|
119
|
+
evaluator('puppet', logger)
|
120
|
+
else
|
121
|
+
fail Evaluators::ConfigurationError, type
|
122
|
+
end
|
79
123
|
end
|
124
|
+
end
|
80
125
|
|
81
|
-
|
82
|
-
|
126
|
+
module Evaluators
|
127
|
+
class InstallationError < Vagrant::Errors::VagrantError
|
128
|
+
def error_message
|
129
|
+
'Puppetfile module installation failed'
|
130
|
+
end
|
83
131
|
end
|
84
|
-
end
|
85
132
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
self.formatter = Proc.new { |_, _, _, message| message }
|
133
|
+
class ConfigurationError < Vagrant::Errors::VagrantError
|
134
|
+
def error_message
|
135
|
+
'Invalid vagrant-puppetfile plugin configuration'
|
136
|
+
end
|
91
137
|
end
|
92
138
|
|
93
|
-
|
94
|
-
|
139
|
+
class NoEvaluatorError < Vagrant::Errors::VagrantError
|
140
|
+
def error_message
|
141
|
+
'No Puppetfile evaluator was found'
|
142
|
+
end
|
95
143
|
end
|
96
|
-
end
|
97
144
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
145
|
+
class Base
|
146
|
+
attr_reader :logger
|
147
|
+
attr_reader :path
|
148
|
+
attr_reader :puppetfile
|
149
|
+
|
150
|
+
ENV_CLEAN_KEYS = %w(GEM_HOME GEM_PATH)
|
151
|
+
|
152
|
+
def initialize(path, puppetfile, logger)
|
153
|
+
@logger = logger
|
154
|
+
@path = path
|
155
|
+
@puppetfile = puppetfile
|
156
|
+
fail NoEvaluatorError, path unless available?
|
157
|
+
end
|
158
|
+
|
159
|
+
def command(*args)
|
160
|
+
::Bundler.with_clean_env do
|
161
|
+
ENV_CLEAN_KEYS.each { |k| ENV.delete(k) }
|
162
|
+
Open3.capture2e(path, *args.map(&:shellescape))
|
103
163
|
end
|
104
164
|
end
|
105
|
-
end
|
106
165
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
166
|
+
def run(*args)
|
167
|
+
output, status = command(*args)
|
168
|
+
if status.success?
|
169
|
+
output.lines.each { |l| logger.detail(l.chomp) }
|
170
|
+
else
|
171
|
+
output.lines.each { |l| logger.error(l.chomp) }
|
172
|
+
fail InstallationError, output
|
173
|
+
end
|
174
|
+
end
|
112
175
|
end
|
113
176
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
177
|
+
class R10k < Base
|
178
|
+
def available?
|
179
|
+
command('version').last.success?
|
180
|
+
rescue
|
181
|
+
false
|
182
|
+
end
|
118
183
|
|
119
|
-
|
120
|
-
|
184
|
+
def install!
|
185
|
+
run('puppetfile', 'install', '--verbose')
|
186
|
+
end
|
121
187
|
end
|
122
188
|
|
123
|
-
|
124
|
-
|
189
|
+
class Librarian < Base
|
190
|
+
def available?
|
191
|
+
command('version').last.success?
|
192
|
+
rescue
|
193
|
+
false
|
194
|
+
end
|
195
|
+
|
196
|
+
def install!
|
197
|
+
run('install', '--verbose')
|
198
|
+
end
|
125
199
|
end
|
126
200
|
|
127
|
-
|
128
|
-
|
129
|
-
|
201
|
+
class Puppet < Base
|
202
|
+
def initialize(path, puppetlabs, logger)
|
203
|
+
super
|
204
|
+
@moduledir = 'modules'
|
205
|
+
end
|
206
|
+
|
207
|
+
def available?
|
208
|
+
command('--version').last.success?
|
209
|
+
rescue
|
210
|
+
false
|
211
|
+
end
|
212
|
+
|
213
|
+
def install!
|
214
|
+
logger.detail("Notice: Evaluating #{puppetfile} ...")
|
215
|
+
instance_eval(File.read(puppetfile))
|
130
216
|
end
|
131
217
|
|
132
|
-
|
133
|
-
|
218
|
+
def unsupported(option, method, *args)
|
219
|
+
option = option.inspect
|
220
|
+
args = args.map(&:inspect).join(', ')
|
221
|
+
logger.error("Unsupported option #{option} in `#{method} #{args}'")
|
222
|
+
fail InstallationError, path
|
134
223
|
end
|
135
224
|
|
136
|
-
|
137
|
-
|
225
|
+
def moduledir(moduledir)
|
226
|
+
@moduledir = moduledir
|
138
227
|
end
|
139
228
|
|
140
|
-
|
141
|
-
|
142
|
-
|
229
|
+
def forge(forge)
|
230
|
+
@forge = forge
|
231
|
+
end
|
143
232
|
|
144
|
-
|
145
|
-
|
233
|
+
def mod(name, version = :latest, options = {})
|
234
|
+
if version.is_a?(Hash)
|
235
|
+
options, version = version, :latest
|
236
|
+
end
|
146
237
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
238
|
+
unless options.is_a?(Hash) and options.empty?
|
239
|
+
unsupported(options, 'mod', name, version, options)
|
240
|
+
end
|
241
|
+
|
242
|
+
unless version.is_a?(String) or version == :latest
|
243
|
+
unsupported(version, 'mod', name, version)
|
244
|
+
end
|
245
|
+
|
246
|
+
module_option = '--target-dir', @moduledir
|
247
|
+
forge_option = '--module_repository', @forge if @forge.is_a? String
|
248
|
+
version_option = '--version', version if version.is_a? String
|
249
|
+
|
250
|
+
run('module', 'install', '--verbose', name, *module_option, *forge_option, *version_option)
|
152
251
|
end
|
153
252
|
end
|
154
253
|
end
|
data/lib/vagrant-puppetfile.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-puppetfile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Hanson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Automatically installs puppet modules from a Puppetfile during Vagrant
|
14
14
|
provisioning
|
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
version: '0'
|
41
41
|
requirements: []
|
42
42
|
rubyforge_project:
|
43
|
-
rubygems_version: 2.
|
43
|
+
rubygems_version: 2.5.1
|
44
44
|
signing_key:
|
45
45
|
specification_version: 4
|
46
46
|
summary: Puppetfile provisioner
|