vagrant-puppetfile 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 362c96b5711e8e8cd60b0f651938daeeb7128ace
4
- data.tar.gz: e2dc0ec31dc197649d8e0ffb61b8cc80b47d8e6d
3
+ metadata.gz: bbff97cdeedbea9bc71c7460ee98e8d921d671a7
4
+ data.tar.gz: ec287ee9e5ffb598b8e60f0b3c42b0ddd7a2aac2
5
5
  SHA512:
6
- metadata.gz: 94763c4eac04534b5013f08d36a1f38eb75c0a93bd799f5efed5ae257cae9f7aa063b48a9b2e3b86d51642d5e6adde83f935099572fa36acfb135e39082adb75
7
- data.tar.gz: 6a83f7e8f390f93b40eb83bb5e1cdfc6e2a5a553b556b20a8469be8c3b3966752851bfa434c71afdfea5486e07a79f4583eb7492728aba0e7e714bd3f62514fe
6
+ metadata.gz: 9137331c54d4c2266c215fb906cfbe599c1c09e59fa3c3089fcfaf656b4968e6fa31044de38353fbf3957e28b2df19f032a6821c40a8b22556a6d32106695efb
7
+ data.tar.gz: 017386ab77bb35275814eee91a9e4b51f784afadcc628f93a325fff3ece3c1bff7971694e9b8b6f395c46bd0dc4a3645e166ebe0fcefc527b33e5918b61166f4
@@ -21,6 +21,6 @@
21
21
  module Vagrant
22
22
  module Puppetfile
23
23
  NAME = 'vagrant-puppetfile'
24
- VERSION = '0.4.2'
24
+ VERSION = '0.4.3'
25
25
  end
26
26
  end
@@ -35,7 +35,7 @@ module Vagrant
35
35
  end
36
36
 
37
37
  def provision
38
- Puppetfile.new(@config.path).evaluator(@config.evaluator, @logger).install!
38
+ Evaluator.create(@config.evaluator, @logger).install(@config.path)
39
39
  rescue Exception => e
40
40
  @logger.error("Failed to evaluate Puppetfile: #{e.message}")
41
41
  end
@@ -63,7 +63,7 @@ module Vagrant
63
63
 
64
64
  case parse_options(options)
65
65
  when ['install']
66
- Puppetfile.new(puppetfile).evaluator(evaluator, @env.ui).install!
66
+ Evaluator.create(evaluator, @env.ui).install(puppetfile)
67
67
  else
68
68
  @env.ui.warn(options.help)
69
69
  exit 1
@@ -104,32 +104,9 @@ module Vagrant
104
104
  provisioner(:puppetfile) { Provisioner }
105
105
  end
106
106
 
107
- class Puppetfile
108
- attr_reader :path
107
+ module Evaluator
108
+ EVALUATORS = %w(librarian-puppet r10k puppet)
109
109
 
110
- def initialize(path)
111
- @path = path
112
- end
113
-
114
- def evaluator(type, logger)
115
- case File.basename(type)
116
- when 'librarian-puppet'
117
- Evaluators::Librarian.new(type, path, logger)
118
- when 'r10k'
119
- Evaluators::R10k.new(type, path, logger)
120
- when 'puppet'
121
- Evaluators::Puppet.new(type, path, logger)
122
- when 'autodetect'
123
- evaluator('librarian-puppet', logger) rescue
124
- evaluator('r10k', logger) rescue
125
- evaluator('puppet', logger)
126
- else
127
- fail Evaluators::ConfigurationError, type
128
- end
129
- end
130
- end
131
-
132
- module Evaluators
133
110
  class InstallationError < Vagrant::Errors::VagrantError
134
111
  def error_message
135
112
  'Puppetfile module installation failed'
@@ -142,33 +119,58 @@ module Vagrant
142
119
  end
143
120
  end
144
121
 
145
- class NoEvaluatorError < Vagrant::Errors::VagrantError
122
+ class EvaluatorError < Vagrant::Errors::VagrantError
146
123
  def error_message
147
124
  'No Puppetfile evaluator was found'
148
125
  end
149
126
  end
150
127
 
128
+ def Evaluator.create(type, logger)
129
+ case File.basename(type)
130
+ when 'librarian-puppet'
131
+ Librarian.new(type, logger)
132
+ when 'r10k'
133
+ R10k.new(type, logger)
134
+ when 'puppet'
135
+ Puppet.new(type, logger)
136
+ when 'autodetect'
137
+ autodetect(logger) or fail ConfigurationError
138
+ else
139
+ logger.warn("Invalid evaluator: #{type}")
140
+ fail ConfigurationError, type
141
+ end
142
+ end
143
+
144
+ def Evaluator.autodetect(logger)
145
+ EVALUATORS.detect do |type|
146
+ begin
147
+ return create(type, logger)
148
+ rescue EvaluatorError => e
149
+ nil
150
+ end
151
+ end
152
+ end
153
+
151
154
  class Base
152
155
  attr_reader :logger
153
156
  attr_reader :path
154
- attr_reader :puppetfile
155
157
 
156
158
  ENV_CLEAN_KEYS = %w(GEM_HOME GEM_PATH)
157
159
 
158
- def initialize(path, puppetfile, logger)
160
+ def initialize(path, logger)
159
161
  @logger = logger
160
162
  @path = path
161
- @puppetfile = puppetfile
162
-
163
163
  # Make sure the evaluator actually exists and can be called.
164
164
  unless available?
165
- logger.error("Unable to find command: #{path}")
166
- fail NoEvaluatorError, path
165
+ logger.warn("Unable to find command: #{path}")
166
+ fail EvaluatorError, path
167
167
  end
168
+ end
168
169
 
170
+ def validate(puppetfile)
169
171
  # Check for the puppetfile and bomb if it doesn't exist.
170
172
  unless File.readable?(puppetfile)
171
- logger.error("Unable to read puppetfile: #{puppetfile}")
173
+ logger.warn("Unable to read puppetfile: #{puppetfile}")
172
174
  fail ConfigurationError, puppetfile
173
175
  end
174
176
  end
@@ -208,7 +210,8 @@ module Vagrant
208
210
  false
209
211
  end
210
212
 
211
- def install!
213
+ def install(puppetfile)
214
+ validate(puppetfile)
212
215
  run('puppetfile', 'install', '--verbose')
213
216
  end
214
217
  end
@@ -216,7 +219,7 @@ module Vagrant
216
219
  class Librarian < Base
217
220
  SUPPORTED_PUPPETFILE_NAMES = %w{Puppetfile Modulefile metadata.json}
218
221
 
219
- def initialize(path, puppetfile, logger)
222
+ def validate(puppetfile)
220
223
  super
221
224
  unless SUPPORTED_PUPPETFILE_NAMES.include? File.basename(puppetfile)
222
225
  logger.error("The 'librarian-puppet' evaluator cannot install from a file named #{puppetfile.inspect}")
@@ -231,7 +234,8 @@ module Vagrant
231
234
  false
232
235
  end
233
236
 
234
- def install!
237
+ def install(puppetfile)
238
+ validate(puppetfile)
235
239
  dir = File.dirname(puppetfile)
236
240
  Dir.chdir(dir) do
237
241
  run('install', '--verbose')
@@ -240,7 +244,7 @@ module Vagrant
240
244
  end
241
245
 
242
246
  class Puppet < Base
243
- def initialize(path, puppetfile, logger)
247
+ def initialize(path, logger)
244
248
  super
245
249
  @moduledir = 'modules'
246
250
  end
@@ -251,7 +255,8 @@ module Vagrant
251
255
  false
252
256
  end
253
257
 
254
- def install!
258
+ def install(puppetfile)
259
+ validate(puppetfile)
255
260
  logger.detail("Notice: Evaluating #{puppetfile} ...")
256
261
  instance_eval(File.read(puppetfile))
257
262
  end
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.2
4
+ version: 0.4.3
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-05-17 00:00:00.000000000 Z
11
+ date: 2017-05-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Automatically installs puppet modules from a Puppetfile during Vagrant
14
14
  provisioning