vagrant/plugins/provisioners/salt/bootstrap-salt.ps1

46 lines
1.4 KiB
PowerShell
Raw Normal View History

# Copy minion keys to correct location
New-Item c:\salt\conf\pki\minion\ -ItemType directory | out-null
cp C:\tmp\minion.pem C:\salt\conf\pki\minion\
cp C:\tmp\minion.pub C:\salt\conf\pki\minion\
# Detect architecture
if ([IntPtr]::Size -eq 4) {
$arch = "win32"
} else {
$arch = "AMD64"
}
# Download minion setup file
Write-Host "Downloading Salt minion installer ($arch)..."
$webclient = New-Object System.Net.WebClient
$url = "https://docs.saltstack.com/downloads/Salt-Minion-2014.1.3-1-$arch-Setup.exe"
$file = "C:\tmp\salt.exe"
$webclient.DownloadFile($url, $file)
# Install minion silently
Write-Host "Installing Salt minion..."
C:\tmp\salt.exe /S
# 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"