(#7836) Introduce salt_call_args option for salt provisioner
This config option for the salt provisioner allows you to pass additional arguments to the salt-call executable.
This commit is contained in:
parent
010c369e32
commit
9a29d7be6b
|
@ -24,6 +24,7 @@ module VagrantPlugins
|
||||||
attr_accessor :log_level
|
attr_accessor :log_level
|
||||||
attr_accessor :masterless
|
attr_accessor :masterless
|
||||||
attr_accessor :minion_id
|
attr_accessor :minion_id
|
||||||
|
attr_accessor :salt_call_args
|
||||||
|
|
||||||
## bootstrap options
|
## bootstrap options
|
||||||
attr_accessor :temp_config_dir
|
attr_accessor :temp_config_dir
|
||||||
|
@ -66,6 +67,7 @@ module VagrantPlugins
|
||||||
@version = UNSET_VALUE
|
@version = UNSET_VALUE
|
||||||
@run_service = UNSET_VALUE
|
@run_service = UNSET_VALUE
|
||||||
@master_id = UNSET_VALUE
|
@master_id = UNSET_VALUE
|
||||||
|
@salt_call_args = UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
def finalize!
|
def finalize!
|
||||||
|
@ -91,6 +93,7 @@ module VagrantPlugins
|
||||||
@version = nil if @version == UNSET_VALUE
|
@version = nil if @version == UNSET_VALUE
|
||||||
@run_service = nil if @run_service == UNSET_VALUE
|
@run_service = nil if @run_service == UNSET_VALUE
|
||||||
@master_id = nil if @master_id == UNSET_VALUE
|
@master_id = nil if @master_id == UNSET_VALUE
|
||||||
|
@salt_call_args = nil if @salt_call_args == UNSET_VALUE
|
||||||
|
|
||||||
# NOTE: Optimistic defaults are set in the provisioner. UNSET_VALUEs
|
# NOTE: Optimistic defaults are set in the provisioner. UNSET_VALUEs
|
||||||
# are converted there to allow proper detection of unset values.
|
# are converted there to allow proper detection of unset values.
|
||||||
|
|
|
@ -198,6 +198,18 @@ module VagrantPlugins
|
||||||
return options
|
return options
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Append additional arguments to the salt-call command
|
||||||
|
def get_call_args
|
||||||
|
options = ""
|
||||||
|
if @config.salt_call_args
|
||||||
|
@config.salt_call_args.each do |opt|
|
||||||
|
options += " #{opt}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return options
|
||||||
|
end
|
||||||
|
|
||||||
# Copy master and minion configs to VM
|
# Copy master and minion configs to VM
|
||||||
def upload_configs
|
def upload_configs
|
||||||
if @config.minion_config
|
if @config.minion_config
|
||||||
|
@ -377,7 +389,7 @@ module VagrantPlugins
|
||||||
@machine.communicate.execute("C:\\salt\\salt-call.bat saltutil.sync_all", opts)
|
@machine.communicate.execute("C:\\salt\\salt-call.bat saltutil.sync_all", opts)
|
||||||
end
|
end
|
||||||
# TODO: something equivalent to { error_key: :ssh_bad_exit_status_muted }?
|
# TODO: something equivalent to { error_key: :ssh_bad_exit_status_muted }?
|
||||||
@machine.communicate.execute("C:\\salt\\salt-call.bat state.highstate --retcode-passthrough#{get_masterless}#{get_loglevel}#{get_colorize}#{get_pillar}", opts) do |type, data|
|
@machine.communicate.execute("C:\\salt\\salt-call.bat state.highstate --retcode-passthrough#{get_masterless}#{get_loglevel}#{get_colorize}#{get_pillar}#{get_call_args}", opts) do |type, data|
|
||||||
if @config.verbose
|
if @config.verbose
|
||||||
@machine.env.ui.info(data.rstrip)
|
@machine.env.ui.info(data.rstrip)
|
||||||
end
|
end
|
||||||
|
@ -386,7 +398,7 @@ module VagrantPlugins
|
||||||
unless @config.masterless?
|
unless @config.masterless?
|
||||||
@machine.communicate.sudo("salt-call saltutil.sync_all")
|
@machine.communicate.sudo("salt-call saltutil.sync_all")
|
||||||
end
|
end
|
||||||
@machine.communicate.sudo("salt-call state.highstate --retcode-passthrough#{get_masterless}#{get_loglevel}#{get_colorize}#{get_pillar}", ssh_opts) do |type, data|
|
@machine.communicate.sudo("salt-call state.highstate --retcode-passthrough#{get_masterless}#{get_loglevel}#{get_colorize}#{get_pillar}#{get_call_args}", ssh_opts) do |type, data|
|
||||||
if @config.verbose
|
if @config.verbose
|
||||||
@machine.env.ui.info(data.rstrip)
|
@machine.env.ui.info(data.rstrip)
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,4 +32,47 @@ describe VagrantPlugins::Salt::Provisioner do
|
||||||
describe "#provision" do
|
describe "#provision" do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#call_highstate" do
|
||||||
|
context "with masterless" do
|
||||||
|
it "passes along extra cli flags" do
|
||||||
|
allow(config).to receive(:run_highstate).and_return(true)
|
||||||
|
allow(config).to receive(:verbose).and_return(true)
|
||||||
|
allow(config).to receive(:masterless?).and_return(true)
|
||||||
|
allow(config).to receive(:masterless).and_return(true)
|
||||||
|
allow(config).to receive(:minion_id).and_return(nil)
|
||||||
|
allow(config).to receive(:log_level).and_return(nil)
|
||||||
|
allow(config).to receive(:colorize).and_return(false)
|
||||||
|
allow(config).to receive(:pillar_data).and_return([])
|
||||||
|
|
||||||
|
allow(config).to receive(:salt_call_args).and_return(["--output-dif"])
|
||||||
|
allow(machine.communicate).to receive(:sudo)
|
||||||
|
allow(machine.config.vm).to receive(:communicator).and_return(:notwinrm)
|
||||||
|
allow(config).to receive(:install_master).and_return(false)
|
||||||
|
|
||||||
|
expect(machine.communicate).to receive(:sudo).with("salt-call state.highstate --retcode-passthrough --local --log-level=debug --no-color --output-dif", {:error_key=>:ssh_bad_exit_status_muted})
|
||||||
|
subject.call_highstate()
|
||||||
|
end
|
||||||
|
|
||||||
|
it "has no additional cli flags if not included" do
|
||||||
|
allow(config).to receive(:run_highstate).and_return(true)
|
||||||
|
allow(config).to receive(:verbose).and_return(true)
|
||||||
|
allow(config).to receive(:masterless?).and_return(true)
|
||||||
|
allow(config).to receive(:masterless).and_return(true)
|
||||||
|
allow(config).to receive(:minion_id).and_return(nil)
|
||||||
|
allow(config).to receive(:log_level).and_return(nil)
|
||||||
|
allow(config).to receive(:colorize).and_return(false)
|
||||||
|
allow(config).to receive(:pillar_data).and_return([])
|
||||||
|
|
||||||
|
allow(config).to receive(:salt_call_args).and_return(nil)
|
||||||
|
allow(machine.communicate).to receive(:sudo)
|
||||||
|
allow(machine.config.vm).to receive(:communicator).and_return(:notwinrm)
|
||||||
|
allow(config).to receive(:install_master).and_return(false)
|
||||||
|
|
||||||
|
expect(machine.communicate).to receive(:sudo).with("salt-call state.highstate --retcode-passthrough --local --log-level=debug --no-color", {:error_key=>:ssh_bad_exit_status_muted})
|
||||||
|
subject.call_highstate()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -94,6 +94,8 @@ public key
|
||||||
|
|
||||||
* `masterless` (boolean) - Calls state.highstate in local mode. Uses `minion_id` and `pillar_data` when provided.
|
* `masterless` (boolean) - Calls state.highstate in local mode. Uses `minion_id` and `pillar_data` when provided.
|
||||||
|
|
||||||
|
* `salt_call_args` (array) - An array of additional command line flag arguments to be passed to the `salt-call` command when provisioning with masterless.
|
||||||
|
|
||||||
## Master Options
|
## Master Options
|
||||||
These only make sense when `install_master` is `true`. Not supported on Windows guest machines.
|
These only make sense when `install_master` is `true`. Not supported on Windows guest machines.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue