diff --git a/plugins/provisioners/salt/bootstrap-salt.ps1 b/plugins/provisioners/salt/bootstrap-salt.ps1 index f8e256e6c..6f284a426 100644 --- a/plugins/provisioners/salt/bootstrap-salt.ps1 +++ b/plugins/provisioners/salt/bootstrap-salt.ps1 @@ -21,7 +21,25 @@ $webclient.DownloadFile($url, $file) Write-Host "Installing Salt minion..." C:\tmp\salt.exe /S -# Wait a bit -Start-Sleep -s 10 -net start salt-minion +# Try starting the Salt minion service +Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue +$service = Get-Service salt-minion -ErrorAction SilentlyContinue +$try = 0 +# Retry starting the service 4 times if it's not running +# and wait 2 seconds between each try +While (($service.Status -eq "Stopped") -and ($try -ne 4)) { + Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue + $service = Get-Service salt-minion -ErrorAction SilentlyContinue + Start-Sleep -s 2 + $try += 1 +} + +# If the salt-minion service is still not running, something probably +# went wrong and user intervention is required - report failure. +if ($service.Status -eq "Stopped") { + Write-Host "Failed to start Salt minion" + exit 1 +} + +Write-Host "Salt minion successfully installed" diff --git a/plugins/provisioners/salt/provisioner.rb b/plugins/provisioners/salt/provisioner.rb index fa14d3a6c..6d403093c 100644 --- a/plugins/provisioners/salt/provisioner.rb +++ b/plugins/provisioners/salt/provisioner.rb @@ -282,8 +282,9 @@ module VagrantPlugins if @config.install_master @machine.env.ui.info "Calling state.overstate... (this may take a while)" if @machine.config.vm.communicator == :winrm - @machine.communicate.execute("C:\\salt\\salt.exe '*' saltutil.sync_all") - @machine.communicate.execute("C:\\salt\\salt-run.exe state.over") do |type, data| + opts = { elevated: true } + @machine.communicate.execute("C:\\salt\\salt.exe '*' saltutil.sync_all", opts) + @machine.communicate.execute("C:\\salt\\salt-run.exe state.over", opts) do |type, data| if @config.verbose @machine.env.ui.info(data) end @@ -309,8 +310,9 @@ module VagrantPlugins @machine.env.ui.info "Calling state.highstate... (this may take a while)" if @config.install_master if @machine.config.vm.communicator == :winrm - @machine.communicate.execute("C:\\salt\\salt.exe '*' saltutil.sync_all") - @machine.communicate.execute("C:\\salt\\salt.exe '*' state.highstate --verbose#{get_loglevel}#{get_colorize}#{get_pillar}") do |type, data| + opts = { elevated: true } + @machine.communicate.execute("C:\\salt\\salt.exe '*' saltutil.sync_all", opts) + @machine.communicate.execute("C:\\salt\\salt.exe '*' state.highstate --verbose#{get_loglevel}#{get_colorize}#{get_pillar}", opts) do |type, data| if @config.verbose @machine.env.ui.info(data) end @@ -325,8 +327,9 @@ module VagrantPlugins end else if @machine.config.vm.communicator == :winrm - @machine.communicate.execute("C:\\salt\\salt-call.exe saltutil.sync_all") - @machine.communicate.execute("C:\\salt\\salt-call.exe state.highstate #{get_loglevel}#{get_colorize}#{get_pillar}") do |type, data| + opts = { elevated: true } + @machine.communicate.execute("C:\\salt\\salt-call.exe saltutil.sync_all", opts) + @machine.communicate.execute("C:\\salt\\salt-call.exe state.highstate #{get_loglevel}#{get_colorize}#{get_pillar}", opts) do |type, data| if @config.verbose @machine.env.ui.info(data) end