diff --git a/plugins/provisioners/salt/config.rb b/plugins/provisioners/salt/config.rb index 0a99d3fc8..4d97d942c 100644 --- a/plugins/provisioners/salt/config.rb +++ b/plugins/provisioners/salt/config.rb @@ -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 diff --git a/plugins/provisioners/salt/provisioner.rb b/plugins/provisioners/salt/provisioner.rb index a47bce2a6..87af7cc7d 100644 --- a/plugins/provisioners/salt/provisioner.rb +++ b/plugins/provisioners/salt/provisioner.rb @@ -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 diff --git a/templates/locales/en.yml b/templates/locales/en.yml index e28106a20..9b2f273fe 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -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: |- diff --git a/test/unit/plugins/provisioners/salt/config_test.rb b/test/unit/plugins/provisioners/salt/config_test.rb index c640a7497..24bf24796 100644 --- a/test/unit/plugins/provisioners/salt/config_test.rb +++ b/test/unit/plugins/provisioners/salt/config_test.rb @@ -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 diff --git a/website/docs/source/v2/provisioning/salt.html.md b/website/docs/source/v2/provisioning/salt.html.md index f66ac7c60..ddc81fa90 100644 --- a/website/docs/source/v2/provisioning/salt.html.md +++ b/website/docs/source/v2/provisioning/salt.html.md @@ -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`.