Adding run_service and minion/master ids for windows
This commit is contained in:
parent
eab702da83
commit
da67824a53
|
@ -1,12 +1,34 @@
|
||||||
Param(
|
Param(
|
||||||
[string]$version
|
[string]$version,
|
||||||
|
[string]$runservice,
|
||||||
|
[string]$minion,
|
||||||
|
[string]$master
|
||||||
)
|
)
|
||||||
|
|
||||||
# Salt version to install - default to latest if there is an issue
|
# Constants
|
||||||
if ($version -notmatch "201[0-9]\.[0-9]\.[0-9](\-\d{1})?"){
|
$ServiceName = "salt-minion"
|
||||||
|
$startupType = "Manual"
|
||||||
|
|
||||||
|
# Version to install - default to latest if there is an issue
|
||||||
|
If ($version -notmatch "201[0-9]\.[0-9]\.[0-9](\-\d{1})?"){
|
||||||
$version = '2015.5.2'
|
$version = '2015.5.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
If ($runservice.ToLower() -eq "true"){
|
||||||
|
Write-Host "Service is set to run."
|
||||||
|
[bool]$runservice = $True
|
||||||
|
}
|
||||||
|
ElseIf ($runservice.ToLower() -eq "false"){
|
||||||
|
Write-Host "Service will be stopped and set to manual."
|
||||||
|
[bool]$runservice = $False
|
||||||
|
}
|
||||||
|
Else {
|
||||||
|
# Param passed in wasn't clear so defaulting to true.
|
||||||
|
Write-Host "Service defaulting to run."
|
||||||
|
[bool]$runservice = $True
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Create C:\tmp\ - if Vagrant doesn't upload keys and/or config it might not exist
|
# Create C:\tmp\ - if Vagrant doesn't upload keys and/or config it might not exist
|
||||||
New-Item C:\tmp\ -ItemType directory -force | out-null
|
New-Item C:\tmp\ -ItemType directory -force | out-null
|
||||||
|
|
||||||
|
@ -14,32 +36,48 @@ New-Item C:\tmp\ -ItemType directory -force | out-null
|
||||||
New-Item C:\salt\conf\pki\minion\ -ItemType directory -force | out-null
|
New-Item C:\salt\conf\pki\minion\ -ItemType directory -force | out-null
|
||||||
|
|
||||||
# Check if minion keys have been uploaded
|
# Check if minion keys have been uploaded
|
||||||
if (Test-Path C:\tmp\minion.pem) {
|
If (Test-Path C:\tmp\minion.pem) {
|
||||||
cp C:\tmp\minion.pem C:\salt\conf\pki\minion\
|
cp C:\tmp\minion.pem C:\salt\conf\pki\minion\
|
||||||
cp C:\tmp\minion.pub C:\salt\conf\pki\minion\
|
cp C:\tmp\minion.pub C:\salt\conf\pki\minion\
|
||||||
}
|
}
|
||||||
|
|
||||||
# Detect architecture
|
# Detect architecture
|
||||||
if ([IntPtr]::Size -eq 4) {
|
If ([IntPtr]::Size -eq 4) {
|
||||||
$arch = "x86"
|
$arch = "x86"
|
||||||
} else {
|
} Else {
|
||||||
$arch = "AMD64"
|
$arch = "AMD64"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download minion setup file
|
# Download minion setup file
|
||||||
Write-Host "Downloading Salt minion installer $version-$arch..."
|
Write-Host "Downloading Salt minion installer Salt-Minion-$version-$arch-Setup.exe"
|
||||||
$webclient = New-Object System.Net.WebClient
|
$webclient = New-Object System.Net.WebClient
|
||||||
$url = "https://docs.saltstack.com/downloads/Salt-Minion-$version-$arch-Setup.exe"
|
$url = "https://docs.saltstack.com/downloads/Salt-Minion-$version-$arch-Setup.exe"
|
||||||
$file = "C:\tmp\salt.exe"
|
$file = "C:\tmp\salt.exe"
|
||||||
$webclient.DownloadFile($url, $file)
|
$webclient.DownloadFile($url, $file)
|
||||||
|
|
||||||
|
|
||||||
# Install minion silently
|
# Install minion silently
|
||||||
Write-Host "Installing Salt minion..."
|
Write-Host "Installing Salt minion..."
|
||||||
#Wait for process to exit before continuing...
|
#Wait for process to exit before continuing...
|
||||||
C:\tmp\salt.exe /S | Out-Null
|
If($PSBoundParameters.ContainsKey('minion') -and $PSBoundParameters.ContainsKey('master')) {
|
||||||
|
C:\tmp\salt.exe /S /minion-name=$minion /master=$master | Out-Null
|
||||||
|
Write-Host C:\tmp\salt.exe /S /minion-name=$minion /master=$master | Out-Null
|
||||||
|
}
|
||||||
|
ElseIf($PSBoundParameters.ContainsKey('minion') -and !$PSBoundParameters.ContainsKey('master')) {
|
||||||
|
C:\tmp\salt.exe /S /minion-name=$minion | Out-Null
|
||||||
|
Write-Host C:\tmp\salt.exe /S /minion-name=$minion | Out-Null
|
||||||
|
}
|
||||||
|
ElseIf(!$PSBoundParameters.ContainsKey('minion') -and $PSBoundParameters.ContainsKey('master')) {
|
||||||
|
C:\tmp\salt.exe /S /master=$master | Out-Null
|
||||||
|
Write-Host C:\tmp\salt.exe /S /master=$master | Out-Null
|
||||||
|
}
|
||||||
|
Else {
|
||||||
|
C:\tmp\salt.exe /S | Out-Null
|
||||||
|
Write-Host C:\tmp\salt.exe /S | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
# Check if minion config has been uploaded
|
# Check if minion config has been uploaded
|
||||||
if (Test-Path C:\tmp\minion) {
|
If (Test-Path C:\tmp\minion) {
|
||||||
cp C:\tmp\minion C:\salt\conf\
|
cp C:\tmp\minion C:\salt\conf\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,24 +88,31 @@ While (!$service) {
|
||||||
$service = Get-Service salt-minion -ErrorAction SilentlyContinue
|
$service = Get-Service salt-minion -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
# Start service
|
If($runservice) {
|
||||||
Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue
|
# Start service
|
||||||
|
Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
# Check if service is started, otherwise retry starting the
|
# Check if service is started, otherwise retry starting the
|
||||||
# service 4 times.
|
# service 4 times.
|
||||||
$try = 0
|
$try = 0
|
||||||
While (($service.Status -ne "Running") -and ($try -ne 4)) {
|
While (($service.Status -ne "Running") -and ($try -ne 4)) {
|
||||||
Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue
|
Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue
|
||||||
$service = Get-Service salt-minion -ErrorAction SilentlyContinue
|
$service = Get-Service salt-minion -ErrorAction SilentlyContinue
|
||||||
Start-Sleep -s 2
|
Start-Sleep -s 2
|
||||||
$try += 1
|
$try += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# If the salt-minion service is still not running, something probably
|
# If the salt-minion service is still not running, something probably
|
||||||
# went wrong and user intervention is required - report failure.
|
# went wrong and user intervention is required - report failure.
|
||||||
if ($service.Status -eq "Stopped") {
|
If ($service.Status -eq "Stopped") {
|
||||||
Write-Host "Failed to start Salt minion"
|
Write-Host "Failed to start Salt minion"
|
||||||
exit 1
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Else {
|
||||||
|
Write-Host "Stopping salt minion"
|
||||||
|
Set-Service "$ServiceName" -startupType "$startupType"
|
||||||
|
Stop-Service "$ServiceName"
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Salt minion successfully installed"
|
Write-Host "Salt minion successfully installed"
|
|
@ -36,6 +36,8 @@ module VagrantPlugins
|
||||||
attr_accessor :no_minion
|
attr_accessor :no_minion
|
||||||
attr_accessor :bootstrap_options
|
attr_accessor :bootstrap_options
|
||||||
attr_accessor :version
|
attr_accessor :version
|
||||||
|
attr_accessor :run_service
|
||||||
|
attr_accessor :master_id
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@minion_config = UNSET_VALUE
|
@minion_config = UNSET_VALUE
|
||||||
|
@ -65,6 +67,8 @@ module VagrantPlugins
|
||||||
@masterless = UNSET_VALUE
|
@masterless = UNSET_VALUE
|
||||||
@minion_id = UNSET_VALUE
|
@minion_id = UNSET_VALUE
|
||||||
@version = UNSET_VALUE
|
@version = UNSET_VALUE
|
||||||
|
@run_service = UNSET_VALUE
|
||||||
|
@master_id = UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
def finalize!
|
def finalize!
|
||||||
|
@ -95,6 +99,8 @@ module VagrantPlugins
|
||||||
@masterless = false if @masterless == UNSET_VALUE
|
@masterless = false if @masterless == UNSET_VALUE
|
||||||
@minion_id = nil if @minion_id == UNSET_VALUE
|
@minion_id = nil if @minion_id == UNSET_VALUE
|
||||||
@version = nil if @version == UNSET_VALUE
|
@version = nil if @version == UNSET_VALUE
|
||||||
|
@run_service = nil if @run_service == UNSET_VALUE
|
||||||
|
@master_id = nil if @master_id == UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
def pillar(data)
|
def pillar(data)
|
||||||
|
|
|
@ -104,7 +104,7 @@ module VagrantPlugins
|
||||||
options = "%s %s" % [options, @config.bootstrap_options]
|
options = "%s %s" % [options, @config.bootstrap_options]
|
||||||
end
|
end
|
||||||
|
|
||||||
if configure
|
if configure && !@machine.config.vm.communicator == :winrm
|
||||||
options = "%s -F -c %s" % [options, config_dir]
|
options = "%s -F -c %s" % [options, config_dir]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -238,7 +238,19 @@ module VagrantPlugins
|
||||||
bootstrap_path = get_bootstrap
|
bootstrap_path = get_bootstrap
|
||||||
if @machine.config.vm.communicator == :winrm
|
if @machine.config.vm.communicator == :winrm
|
||||||
if @config.version
|
if @config.version
|
||||||
options = "-version %s" % @config.version
|
options += " -version %s" % @config.version
|
||||||
|
end
|
||||||
|
if @config.run_service
|
||||||
|
@machine.env.ui.info "Salt minion will be stopped after installing."
|
||||||
|
options += " -runservice %s" % @config.run_service
|
||||||
|
end
|
||||||
|
if @config.minion_id
|
||||||
|
@machine.env.ui.info "Setting minion to @config.minion_id."
|
||||||
|
options += " -minion %s" % @config.minion_id
|
||||||
|
end
|
||||||
|
if @config.master_id
|
||||||
|
@machine.env.ui.info "Setting master to @config.master_id."
|
||||||
|
options += " -master %s" % @config.master_id
|
||||||
end
|
end
|
||||||
bootstrap_destination = File.join(config_dir, "bootstrap_salt.ps1")
|
bootstrap_destination = File.join(config_dir, "bootstrap_salt.ps1")
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue