kernel/v2: support overriding provisioner settings
This commit is contained in:
parent
debc14f883
commit
10d5416a90
|
@ -221,8 +221,21 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def provision(name, options=nil, &block)
|
def provision(name, **options, &block)
|
||||||
@provisioners << VagrantConfigProvisioner.new(name.to_sym, options, &block)
|
options[:id] = options[:id].to_s if options[:id]
|
||||||
|
|
||||||
|
prov = nil
|
||||||
|
if options[:id]
|
||||||
|
prov = @provisioners.find { |p| p.id == options[:id] }
|
||||||
|
end
|
||||||
|
|
||||||
|
if !prov
|
||||||
|
prov = VagrantConfigProvisioner.new(options[:id], name.to_sym)
|
||||||
|
@provisioners << prov
|
||||||
|
end
|
||||||
|
|
||||||
|
prov.add_config(options, &block)
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def defined_vms
|
def defined_vms
|
||||||
|
|
|
@ -4,6 +4,11 @@ module VagrantPlugins
|
||||||
module Kernel_V2
|
module Kernel_V2
|
||||||
# Represents a single configured provisioner for a VM.
|
# Represents a single configured provisioner for a VM.
|
||||||
class VagrantConfigProvisioner
|
class VagrantConfigProvisioner
|
||||||
|
# Unique ID name for this provisioner
|
||||||
|
#
|
||||||
|
# @return [String]
|
||||||
|
attr_reader :id
|
||||||
|
|
||||||
# The name of the provisioner that should be registered
|
# The name of the provisioner that should be registered
|
||||||
# as a plugin.
|
# as a plugin.
|
||||||
#
|
#
|
||||||
|
@ -15,11 +20,12 @@ module VagrantPlugins
|
||||||
# @return [Object]
|
# @return [Object]
|
||||||
attr_reader :config
|
attr_reader :config
|
||||||
|
|
||||||
def initialize(name, options=nil, &block)
|
def initialize(id, name)
|
||||||
@logger = Log4r::Logger.new("vagrant::config::vm::provisioner")
|
@logger = Log4r::Logger.new("vagrant::config::vm::provisioner")
|
||||||
@logger.debug("Provisioner defined: #{name}")
|
@logger.debug("Provisioner defined: #{name}")
|
||||||
|
|
||||||
@config = nil
|
@config = nil
|
||||||
|
@id = id
|
||||||
@invalid = false
|
@invalid = false
|
||||||
@name = name
|
@name = name
|
||||||
|
|
||||||
|
@ -31,15 +37,27 @@ module VagrantPlugins
|
||||||
|
|
||||||
# Attempt to find the configuration class for this provider
|
# Attempt to find the configuration class for this provider
|
||||||
# if it exists and load the configuration.
|
# if it exists and load the configuration.
|
||||||
config_class = Vagrant.plugin("2").manager.provisioner_configs[@name]
|
@config_class = Vagrant.plugin("2").manager.
|
||||||
if !config_class
|
provisioner_configs[@name]
|
||||||
@logger.info("Provisioner config for '#{@name}' not found. Ignoring config.")
|
if !@config_class
|
||||||
return
|
@logger.info(
|
||||||
|
"Provisioner config for '#{@name}' not found. Ignoring config.")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@config = config_class.new
|
def add_config(**options, &block)
|
||||||
@config.set_options(options) if options
|
return if invalid?
|
||||||
block.call(@config) if block
|
|
||||||
|
current = @config_class.new
|
||||||
|
current.set_options(options) if options
|
||||||
|
current.call(@config) if block
|
||||||
|
current = @config.merge(current) if @config
|
||||||
|
@config = current
|
||||||
|
end
|
||||||
|
|
||||||
|
def finalize!
|
||||||
|
return if invalid?
|
||||||
|
|
||||||
@config.finalize!
|
@config.finalize!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,17 @@ describe VagrantPlugins::Kernel_V2::VMConfig do
|
||||||
expect(r[1].config.inline).to eql("bar")
|
expect(r[1].config.inline).to eql("bar")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "allows provisioner settings to be overriden" do
|
||||||
|
subject.provision("shell", path: "foo", inline: "foo", id: "s")
|
||||||
|
subject.provision("shell", inline: "bar", id: "s")
|
||||||
|
subject.finalize!
|
||||||
|
|
||||||
|
r = subject.provisioners
|
||||||
|
expect(r.length).to eql(1)
|
||||||
|
expect(r[0].config.inline).to eql("bar")
|
||||||
|
expect(r[0].config.path).to eql("foo")
|
||||||
|
end
|
||||||
|
|
||||||
it "marks as invalid if a bad name" do
|
it "marks as invalid if a bad name" do
|
||||||
subject.provision("nope", inline: "foo")
|
subject.provision("nope", inline: "foo")
|
||||||
subject.finalize!
|
subject.finalize!
|
||||||
|
|
Loading…
Reference in New Issue