(#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:
Brian Cain 2017-08-29 10:24:10 -07:00
parent 010c369e32
commit 9a29d7be6b
4 changed files with 62 additions and 2 deletions

View File

@ -24,6 +24,7 @@ module VagrantPlugins
attr_accessor :log_level
attr_accessor :masterless
attr_accessor :minion_id
attr_accessor :salt_call_args
## bootstrap options
attr_accessor :temp_config_dir
@ -66,6 +67,7 @@ module VagrantPlugins
@version = UNSET_VALUE
@run_service = UNSET_VALUE
@master_id = UNSET_VALUE
@salt_call_args = UNSET_VALUE
end
def finalize!
@ -91,6 +93,7 @@ module VagrantPlugins
@version = nil if @version == UNSET_VALUE
@run_service = nil if @run_service == 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
# are converted there to allow proper detection of unset values.

View File

@ -198,6 +198,18 @@ module VagrantPlugins
return options
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
def upload_configs
if @config.minion_config
@ -377,7 +389,7 @@ module VagrantPlugins
@machine.communicate.execute("C:\\salt\\salt-call.bat saltutil.sync_all", opts)
end
# 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
@machine.env.ui.info(data.rstrip)
end
@ -386,7 +398,7 @@ module VagrantPlugins
unless @config.masterless?
@machine.communicate.sudo("salt-call saltutil.sync_all")
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
@machine.env.ui.info(data.rstrip)
end

View File

@ -32,4 +32,47 @@ describe VagrantPlugins::Salt::Provisioner do
describe "#provision" do
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

View File

@ -94,6 +94,8 @@ public key
* `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
These only make sense when `install_master` is `true`. Not supported on Windows guest machines.