diff --git a/plugins/provisioners/salt/bootstrap-salt.ps1 b/plugins/provisioners/salt/bootstrap-salt.ps1 index 0a05d6517..0b8355860 100644 --- a/plugins/provisioners/salt/bootstrap-salt.ps1 +++ b/plugins/provisioners/salt/bootstrap-salt.ps1 @@ -1,5 +1,6 @@ Param( [string]$version, + [string]$pythonVersion = "2", [string]$runservice, [string]$minion, [string]$master @@ -11,7 +12,12 @@ $startupType = "Manual" # Version to install - default to latest if there is an issue If ($version -notmatch "2\d{3}\.\d{1,2}\.\d+(\-\d{1})?"){ - $version = '2016.11.3' + $version = '2017.7.1' +} + +If ($pythonVersion -notmatch "\d+") { + $pythonVersion = "2" + Write-Host "Defaulting to minion Python version $pythonVersion" } If ($runservice.ToLower() -eq "true"){ @@ -49,9 +55,15 @@ If ([IntPtr]::Size -eq 4) { } # Download minion setup file -Write-Host "Downloading Salt minion installer Salt-Minion-$version-$arch-Setup.exe" +$minionFilename = "Salt-Minion-$version-$arch-Setup.exe" +$versionYear = [regex]::Match($version, "\d+").Value +If ([convert]::ToInt32($versionYear) -ge 2017) +{ + $minionFilename = "Salt-Minion-$version-Py$pythonVersion-$arch-Setup.exe" +} +Write-Host "Downloading Salt minion installer $minionFilename" $webclient = New-Object System.Net.WebClient -$url = "https://repo.saltstack.com/windows/Salt-Minion-$version-$arch-Setup.exe" +$url = "https://repo.saltstack.com/windows/$minionFilename" $file = "C:\tmp\salt.exe" $webclient.DownloadFile($url, $file) diff --git a/plugins/provisioners/salt/config.rb b/plugins/provisioners/salt/config.rb index 2a8169312..c4af8933b 100644 --- a/plugins/provisioners/salt/config.rb +++ b/plugins/provisioners/salt/config.rb @@ -36,6 +36,7 @@ module VagrantPlugins attr_accessor :no_minion attr_accessor :bootstrap_options attr_accessor :version + attr_accessor :python_version attr_accessor :run_service attr_accessor :master_id @@ -66,6 +67,7 @@ module VagrantPlugins @masterless = UNSET_VALUE @minion_id = UNSET_VALUE @version = UNSET_VALUE + @python_version = UNSET_VALUE @run_service = UNSET_VALUE @master_id = UNSET_VALUE @salt_call_args = UNSET_VALUE @@ -93,6 +95,7 @@ module VagrantPlugins @masterless = false if @masterless == UNSET_VALUE @minion_id = nil if @minion_id == UNSET_VALUE @version = nil if @version == UNSET_VALUE + @python_version = nil if @python_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 @@ -160,6 +163,14 @@ module VagrantPlugins errors << I18n.t("vagrant.provisioners.salt.args_array") end + if @python_version && @python_version.is_a?(String) && !@python_version.scan(/\D/).empty? + errors << I18n.t("vagrant.provisioners.salt.python_version") + end + + if @python_version && !(@python_version.is_a?(Integer) || @python_version.is_a?(String)) + errors << I18n.t("vagrant.provisioners.salt.python_version") + end + return {"salt provisioner" => errors} end end diff --git a/plugins/provisioners/salt/provisioner.rb b/plugins/provisioners/salt/provisioner.rb index 2f55099eb..c703c4cc1 100644 --- a/plugins/provisioners/salt/provisioner.rb +++ b/plugins/provisioners/salt/provisioner.rb @@ -121,7 +121,7 @@ module VagrantPlugins options = "%s -F -c %s" % [options, config_dir] end - if @config.seed_master && @config.install_master + if @config.seed_master && @config.install_master && @machine.config.vm.communicator != :winrm seed_dir = "/tmp/minion-seed-keys" @machine.communicate.sudo("mkdir -p -m777 #{seed_dir}") @config.seed_master.each do |name, keyfile| @@ -132,27 +132,27 @@ module VagrantPlugins options = "#{options} -k #{seed_dir}" end - if configure && !install + if configure && !install && @machine.config.vm.communicator != :winrm options = "%s -C" % options end - if @config.install_master + if @config.install_master && @machine.config.vm.communicator != :winrm options = "%s -M" % options end - if @config.install_syndic + if @config.install_syndic && @machine.config.vm.communicator != :winrm options = "%s -S" % options end - if @config.no_minion + if @config.no_minion && @machine.config.vm.communicator != :winrm options = "%s -N" % options end - if @config.install_type + if @config.install_type && @machine.config.vm.communicator != :winrm options = "%s %s" % [options, @config.install_type] end - if @config.install_args + if @config.install_args && @machine.config.vm.communicator != :winrm options = "%s %s" % [options, @config.install_args] end @@ -277,6 +277,9 @@ module VagrantPlugins if @config.version options += " -version %s" % @config.version end + if @config.python_version + options += " -pythonVersion %s" % @config.python_version + end if @config.run_service @machine.env.ui.info "Salt minion will be stopped after installing." options += " -runservice %s" % @config.run_service diff --git a/templates/locales/en.yml b/templates/locales/en.yml index a953478c8..98193171e 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -2444,6 +2444,8 @@ en: You must accept keys when running highstate with master! args_array: |- You must set this value as an array. + python_version: |- + You must set this as an integer or string that represents an integer. pushes: file: diff --git a/test/unit/plugins/provisioners/salt/config_test.rb b/test/unit/plugins/provisioners/salt/config_test.rb index 2571bdbb2..fb9e10b69 100644 --- a/test/unit/plugins/provisioners/salt/config_test.rb +++ b/test/unit/plugins/provisioners/salt/config_test.rb @@ -114,5 +114,47 @@ describe VagrantPlugins::Salt::Config do expect(result[error_key]).to be_empty end end + + context "python_version" do + it "is valid if is set and not missing" do + subject.python_version = "2" + subject.finalize! + + result = subject.validate(machine) + expect(result[error_key]).to be_empty + end + + it "can be a string" do + subject.python_version = "2" + subject.finalize! + + result = subject.validate(machine) + expect(result[error_key]).to be_empty + end + + it "can be an integer" do + subject.python_version = 2 + subject.finalize! + + result = subject.validate(machine) + expect(result[error_key]).to be_empty + end + + it "is not a number that is not an integer" do + subject.python_version = 2.7 + subject.finalize! + + result = subject.validate(machine) + expect(result[error_key]).to_not be_empty + end + + it "is not a string that does not parse to an integer" do + subject.python_version = '2.7' + subject.finalize! + + result = subject.validate(machine) + expect(result[error_key]).to_not be_empty + end + end end end diff --git a/test/unit/plugins/provisioners/salt/provisioner_test.rb b/test/unit/plugins/provisioners/salt/provisioner_test.rb index 8ebf3b846..0cbd7b38c 100644 --- a/test/unit/plugins/provisioners/salt/provisioner_test.rb +++ b/test/unit/plugins/provisioners/salt/provisioner_test.rb @@ -30,7 +30,22 @@ describe VagrantPlugins::Salt::Provisioner do end describe "#provision" do - + context "minion" do + it "does not add linux-only bootstrap flags when on windows" do + additional_windows_options = "-only -these options -should -remain" + allow(config).to receive(:seed_master).and_return(true) + allow(config).to receive(:install_master).and_return(true) + allow(config).to receive(:install_syndic).and_return(true) + allow(config).to receive(:no_minion).and_return(true) + allow(config).to receive(:install_type).and_return('stable') + allow(config).to receive(:install_args).and_return('develop') + allow(config).to receive(:verbose).and_return(true) + allow(machine.config.vm).to receive(:communicator).and_return(:winrm) + allow(config).to receive(:bootstrap_options).and_return(additional_windows_options) + result = subject.bootstrap_options(true, true, "C:\\salttmp") + expect(result.strip).to eq(additional_windows_options) + end + end end describe "#call_highstate" do diff --git a/website/source/docs/provisioning/salt.html.md b/website/source/docs/provisioning/salt.html.md index c32c13924..f84633305 100644 --- a/website/source/docs/provisioning/salt.html.md +++ b/website/source/docs/provisioning/salt.html.md @@ -63,7 +63,7 @@ on this machine. Not supported on Windows guest machines. `false`. Not supported on Windows guest machines. * `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 guest machines. * `install_args` (string, default: "develop") - When performing a git install, you can specify a branch, tag, or any treeish. Not supported on Windows. @@ -75,7 +75,9 @@ distribution's stable package manager, git tree-ish, daily ppa, or testing repos * `bootstrap_options` (string) - Additional command-line options to pass to the bootstrap script. -* `version` (string, default: "2016.11.3") - Version of minion to be installed. Only supported on Windows guest machines. +* `version` (string, default: "2017.7.1") - Version of minion to be installed. Only supported on Windows guest machines. + +* `python_version` (string, default: "2") - Major Python version of minion to be installed. Only valid for minion versions >= 2017.7.0. Only supported on Windows guest machines. ## Minion Options These only make sense when `no_minion` is `false`.