Merge pull request #4896 from analyzere/salt-grains-config

Issue #4895: Support grains config for salt
This commit is contained in:
Seth Vargo 2014-12-14 23:48:02 -05:00
commit 8c8a92c4be
5 changed files with 38 additions and 2 deletions

View File

@ -12,6 +12,7 @@ module VagrantPlugins
attr_accessor :master_config
attr_accessor :master_key
attr_accessor :master_pub
attr_accessor :grains_config
attr_accessor :run_highstate
attr_accessor :run_overstate
attr_accessor :always_install
@ -38,6 +39,7 @@ module VagrantPlugins
@master_config = UNSET_VALUE
@master_key = UNSET_VALUE
@master_pub = UNSET_VALUE
@grains_config = UNSET_VALUE
@run_highstate = UNSET_VALUE
@run_overstate = UNSET_VALUE
@always_install = UNSET_VALUE
@ -63,6 +65,7 @@ module VagrantPlugins
@master_config = nil if @master_config == UNSET_VALUE
@master_key = nil if @master_key == UNSET_VALUE
@master_pub = nil if @master_pub == UNSET_VALUE
@grains_config = nil if @grains_config == UNSET_VALUE
@run_highstate = nil if @run_highstate == UNSET_VALUE
@run_overstate = nil if @run_overstate == UNSET_VALUE
@always_install = nil if @always_install == UNSET_VALUE
@ -115,6 +118,13 @@ module VagrantPlugins
end
end
if @grains_config
expanded = Pathname.new(@grains_config).expand_path(machine.env.root_path)
if !expanded.file?
errors << I18n.t("vagrant.provisioners.salt.grains_config_nonexist")
end
end
if @install_master && !@no_minion && !@seed_master && @run_highstate
errors << I18n.t("vagrant.provisioners.salt.must_accept_keys")
end

View File

@ -75,7 +75,7 @@ module VagrantPlugins
end
def need_configure
@config.minion_config or @config.minion_key or @config.master_config or @config.master_key
@config.minion_config or @config.minion_key or @config.master_config or @config.master_key or @config.grains_config
end
def need_install
@ -181,6 +181,11 @@ module VagrantPlugins
@machine.env.ui.info "Copying salt master config to vm."
@machine.communicate.upload(expanded_path(@config.master_config).to_s, temp_config_dir + "/master")
end
if @config.grains_config
@machine.env.ui.info "Copying salt grains config to vm."
@machine.communicate.upload(expanded_path(@config.grains_config).to_s, temp_config_dir + "/grains")
end
end
# Copy master and minion keys to VM

View File

@ -1909,6 +1909,8 @@ en:
The specified minion_config file could not be found.
master_config_nonexist: |-
The specified master_config file could not be found.
grains_config_nonexist: |-
The specified grains_config file could not be found.
missing_key: |-
You must include both public and private keys.
must_accept_keys: |-

View File

@ -60,5 +60,23 @@ describe VagrantPlugins::Salt::Config do
expect(result[error_key]).to be_empty
end
end
context "grains_config" do
it "fails if grains_config is set and missing" do
subject.grains_config = "/nope/still/not/here"
subject.finalize!
result = subject.validate(machine)
expect(result[error_key]).to_not be_empty
end
it "is valid if is set and not missing" do
subject.grains_config = File.expand_path(__FILE__)
subject.finalize!
result = subject.validate(machine)
expect(result[error_key]).to be_empty
end
end
end
end

View File

@ -56,7 +56,7 @@ on this machine. Not supported on Windows.
`false`. Not supported on Windows.
* `install_type` (stable | git | daily | testing) - Whether to install from a
distribution's stable package manager, git tree-ish, daily ppa, or testing repository.
distribution's stable package manager, git tree-ish, daily ppa, or testing repository.
Not supported on Windows.
* `install_args` (develop) - When performing a git install,
@ -77,6 +77,7 @@ a custom salt minion config file.
* `minion_pub` (salt/key/minion.pub) - Path to your minion
public key
* `grains_config` (string) - Path to a custom salt grains file.
## Master Options
These only make sense when `install_master` is `true`.