From c6a49defab61f06569daeeb36840e64b89c1f504 Mon Sep 17 00:00:00 2001 From: Pat O'Shea Date: Mon, 6 Jul 2015 20:36:21 -0600 Subject: [PATCH 1/4] Update salt options Added details about what works for windows and what doesn't, fixed typo, broke runners out from states, added 3 options (version, masterless, and minion_id). --- .../docs/source/v2/provisioning/salt.html.md | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/website/docs/source/v2/provisioning/salt.html.md b/website/docs/source/v2/provisioning/salt.html.md index a34bc4d43..ee9e20371 100644 --- a/website/docs/source/v2/provisioning/salt.html.md +++ b/website/docs/source/v2/provisioning/salt.html.md @@ -46,11 +46,10 @@ masterless setup. ## Install Options - * `install_master` (boolean) - Should vagrant install the salt-master on this machine. Not supported on Windows. -* `no_minion` (boolean) - Don't install the minion, default `false` +* `no_minion` (boolean) - Don't install the minion, default `false`. Not supported on Windows. * `install_syndic` (boolean) - Install the salt-syndic, default `false`. Not supported on Windows. @@ -65,11 +64,13 @@ you can specify a branch, tag, or any treeish. Not supported on Windows. * `always_install` (boolean) - Installs salt binaries even if they are already detected, default `false` -* `bootstrap_script` (string) - Path to your customized salt-bootstrap.sh script. +* `bootstrap_script` (string) - Path to your customized salt-bootstrap.sh script. Not supported on Windows. * `bootstrap_options` (string) - Additional command-line options to pass to the bootstrap script. +* `version` (string, default: "2015.5.2") - Version of minion to be installed. Only supported on Windows. + ## Minion Options These only make sense when `no_minion` is `false`. @@ -78,20 +79,24 @@ a custom salt minion config file. * `minion_key` (string) - Path to your minion key +* `minion_id` (string) - Unique identifier for minion. Used for masterless and preseeding keys. + * `minion_pub` (salt/key/minion.pub) - Path to your minion public key * `grains_config` (string) - Path to a custom salt grains file. +* `masterless` (boolean) - Calls state.highstate in local mode. Uses `minion_id` and `pillar_data` when provided. + ## Master Options -These only make sense when `install_master` is `true`. +These only make sense when `install_master` is `true`. Not supported on Windows. * `master_config` (string, default: "salt/master") - Path to a custom salt master config file + Path to a custom salt master config file. -* `master_key` (salt/key/master.pem) - Path to your master key +* `master_key` (salt/key/master.pem) - Path to your master key. -* `master_pub` (salt/key/master.pub) - Path to your master public key +* `master_pub` (salt/key/master.pub) - Path to your master public key. * `seed_master` (dictionary) - Upload keys to master, thereby pre-seeding it before use. Example: `{minion_name:/path/to/key.pub}` @@ -103,8 +108,16 @@ during provisioning. * `run_highstate` - (boolean) Executes `state.highstate` on vagrant up. Can be applied to any machine. + +## Execute Runners + +Either of the following may be used to actually execute runners +during provisioning. + * `run_overstate` - (boolean) Executes `state.over` on -vagrant up. Can be applied to the master only. +vagrant up. Can be applied to the master only. This is superceded by orchestrate. Not supported on Windows. +* `orchestrations` - (boolean) Executes `state.orchestrate` on +vagrant up. Can be applied to the master only. This is supercedes by run_overstate. Not supported on Windows. ## Output Control @@ -114,7 +127,7 @@ These may be used to control the output of state execution: * `log_level` (string) - The verbosity of the outputs. Defaults to "debug". Can be one of "all", "garbage", "trace", "debug", "info", or - "warning". + "warning". Requires `verbose` to be set to "true". ## Pillar Data @@ -148,7 +161,7 @@ times. The data passed in should only be hashes and lists. Here is an example:: ## Preseeding Keys -Preseeding keys is the recommended way to handle provisiong +Preseeding keys is the recommended way to handle provisioning using a master. On a machine with salt installed, run `salt-key --gen-keys=[minion_id]` to generate the necessary From da67824a53ba0e7c2db1a9b8e19141c1ffd07bfc Mon Sep 17 00:00:00 2001 From: Pat O'Shea Date: Tue, 7 Jul 2015 00:24:23 -0600 Subject: [PATCH 2/4] Adding run_service and minion/master ids for windows --- plugins/provisioners/salt/bootstrap-salt.ps1 | 97 ++++++++++++++------ plugins/provisioners/salt/config.rb | 6 ++ plugins/provisioners/salt/provisioner.rb | 16 +++- 3 files changed, 91 insertions(+), 28 deletions(-) diff --git a/plugins/provisioners/salt/bootstrap-salt.ps1 b/plugins/provisioners/salt/bootstrap-salt.ps1 index 382e1ff81..78f268ea3 100644 --- a/plugins/provisioners/salt/bootstrap-salt.ps1 +++ b/plugins/provisioners/salt/bootstrap-salt.ps1 @@ -1,12 +1,34 @@ Param( - [string]$version + [string]$version, + [string]$runservice, + [string]$minion, + [string]$master ) - -# Salt version to install - default to latest if there is an issue -if ($version -notmatch "201[0-9]\.[0-9]\.[0-9](\-\d{1})?"){ + +# Constants +$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' } +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 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 # 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.pub C:\salt\conf\pki\minion\ } # Detect architecture -if ([IntPtr]::Size -eq 4) { +If ([IntPtr]::Size -eq 4) { $arch = "x86" -} else { +} Else { $arch = "AMD64" } # 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 $url = "https://docs.saltstack.com/downloads/Salt-Minion-$version-$arch-Setup.exe" $file = "C:\tmp\salt.exe" $webclient.DownloadFile($url, $file) + # Install minion silently Write-Host "Installing Salt minion..." #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 -if (Test-Path C:\tmp\minion) { +If (Test-Path C:\tmp\minion) { cp C:\tmp\minion C:\salt\conf\ } @@ -50,24 +88,31 @@ While (!$service) { $service = Get-Service salt-minion -ErrorAction SilentlyContinue } -# Start service -Start-Service -Name "salt-minion" -ErrorAction SilentlyContinue - -# Check if service is started, otherwise retry starting the -# service 4 times. -$try = 0 -While (($service.Status -ne "Running") -and ($try -ne 4)) { +If($runservice) { + # Start service 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 + # Check if service is started, otherwise retry starting the + # service 4 times. + $try = 0 + While (($service.Status -ne "Running") -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 + } +} +Else { + Write-Host "Stopping salt minion" + Set-Service "$ServiceName" -startupType "$startupType" + Stop-Service "$ServiceName" } Write-Host "Salt minion successfully installed" \ No newline at end of file diff --git a/plugins/provisioners/salt/config.rb b/plugins/provisioners/salt/config.rb index 638a07bfb..4e4dc866a 100644 --- a/plugins/provisioners/salt/config.rb +++ b/plugins/provisioners/salt/config.rb @@ -36,6 +36,8 @@ module VagrantPlugins attr_accessor :no_minion attr_accessor :bootstrap_options attr_accessor :version + attr_accessor :run_service + attr_accessor :master_id def initialize @minion_config = UNSET_VALUE @@ -65,6 +67,8 @@ module VagrantPlugins @masterless = UNSET_VALUE @minion_id = UNSET_VALUE @version = UNSET_VALUE + @run_service = UNSET_VALUE + @master_id = UNSET_VALUE end def finalize! @@ -95,6 +99,8 @@ module VagrantPlugins @masterless = false if @masterless == UNSET_VALUE @minion_id = nil if @minion_id == 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 def pillar(data) diff --git a/plugins/provisioners/salt/provisioner.rb b/plugins/provisioners/salt/provisioner.rb index e9f23cd82..1a00f6424 100644 --- a/plugins/provisioners/salt/provisioner.rb +++ b/plugins/provisioners/salt/provisioner.rb @@ -104,7 +104,7 @@ module VagrantPlugins options = "%s %s" % [options, @config.bootstrap_options] end - if configure + if configure && !@machine.config.vm.communicator == :winrm options = "%s -F -c %s" % [options, config_dir] end @@ -238,7 +238,19 @@ module VagrantPlugins bootstrap_path = get_bootstrap if @machine.config.vm.communicator == :winrm 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 bootstrap_destination = File.join(config_dir, "bootstrap_salt.ps1") else From 956bbf011c688d87ac18106c3f2e0a6280fdd8aa Mon Sep 17 00:00:00 2001 From: Pat O'Shea Date: Thu, 16 Jul 2015 18:37:36 -0600 Subject: [PATCH 3/4] Changed minion config path for windows Copy of minion is wrong on windows. Moved to sub-dir, conf. --- plugins/provisioners/salt/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/provisioners/salt/config.rb b/plugins/provisioners/salt/config.rb index 4e4dc866a..4d9550406 100644 --- a/plugins/provisioners/salt/config.rb +++ b/plugins/provisioners/salt/config.rb @@ -113,7 +113,7 @@ module VagrantPlugins # FIXME: there should be a way to do that a bit smarter if guest_type == :windows - return "C:\\salt" + return "C:\\salt\\conf" else return "/etc/salt" end From a4eede0c423e3ebfdead4c785beeb1cd9c386340 Mon Sep 17 00:00:00 2001 From: Pat O'Shea Date: Thu, 16 Jul 2015 18:45:59 -0600 Subject: [PATCH 4/4] fixed typo for config_dir Only exposed when calling highstate with config_dir being set --- plugins/provisioners/salt/provisioner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/provisioners/salt/provisioner.rb b/plugins/provisioners/salt/provisioner.rb index 1a00f6424..fba7fb2db 100644 --- a/plugins/provisioners/salt/provisioner.rb +++ b/plugins/provisioners/salt/provisioner.rb @@ -336,7 +336,7 @@ module VagrantPlugins def call_highstate if @config.minion_config - @machine.env.ui.info "Copying salt minion config to #{@config.config dir}" + @machine.env.ui.info "Copying salt minion config to #{@config.config_dir}" @machine.communicate.upload(expanded_path(@config.minion_config).to_s, @config.config_dir + "/minion") end