2013-04-18 12:41:34 +00:00
|
|
|
require 'json'
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module Salt
|
|
|
|
class Provisioner < Vagrant.plugin("2", :provisioner)
|
2016-10-17 16:35:05 +00:00
|
|
|
|
|
|
|
# Default path values to set within configuration only
|
|
|
|
# if configuration value is unset and local path exists
|
2016-11-10 00:29:36 +00:00
|
|
|
OPTIMISTIC_PATH_DEFAULTS = Hash[*[
|
2016-10-17 16:35:05 +00:00
|
|
|
"minion_config", "salt/minion",
|
|
|
|
"minion_key", "salt/key/minion.key",
|
|
|
|
"minion_pub", "salt/key/minion.pub",
|
|
|
|
"master_config", "salt/master",
|
|
|
|
"master_key", "salt/key/master.key",
|
|
|
|
"master_pub", "salt/key/master.pub"
|
|
|
|
].map(&:freeze)].freeze
|
|
|
|
|
2013-04-18 12:41:34 +00:00
|
|
|
def provision
|
2016-10-17 16:35:05 +00:00
|
|
|
set_default_configs
|
2013-04-18 12:41:34 +00:00
|
|
|
upload_configs
|
|
|
|
upload_keys
|
|
|
|
run_bootstrap_script
|
2013-10-03 19:28:35 +00:00
|
|
|
call_overstate
|
2013-04-18 12:41:34 +00:00
|
|
|
call_highstate
|
2014-08-20 19:04:32 +00:00
|
|
|
call_orchestrate
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Return a list of accepted keys
|
2013-05-18 17:29:36 +00:00
|
|
|
def keys(group='minions')
|
|
|
|
out = @machine.communicate.sudo("salt-key --out json") do |type, output|
|
2013-04-18 12:41:34 +00:00
|
|
|
begin
|
|
|
|
if type == :stdout
|
|
|
|
out = JSON::load(output)
|
2013-05-18 17:29:36 +00:00
|
|
|
break out[group]
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return out
|
|
|
|
end
|
2013-06-19 22:51:44 +00:00
|
|
|
|
2013-04-18 12:41:34 +00:00
|
|
|
## Utilities
|
|
|
|
def expanded_path(rel_path)
|
|
|
|
Pathname.new(rel_path).expand_path(@machine.env.root_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def binaries_found
|
|
|
|
## Determine States, ie: install vs configure
|
|
|
|
desired_binaries = []
|
|
|
|
if !@config.no_minion
|
2014-05-17 00:19:34 +00:00
|
|
|
if @machine.config.vm.communicator == :winrm
|
2015-07-19 02:53:46 +00:00
|
|
|
desired_binaries.push('C:\\salt\\salt-minion.bat')
|
|
|
|
desired_binaries.push('C:\\salt\\salt-call.bat')
|
2014-05-17 00:19:34 +00:00
|
|
|
else
|
|
|
|
desired_binaries.push('salt-minion')
|
|
|
|
desired_binaries.push('salt-call')
|
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if @config.install_master
|
2014-05-17 00:19:34 +00:00
|
|
|
if @machine.config.vm.communicator == :winrm
|
2014-05-19 12:00:46 +00:00
|
|
|
raise Vagrant::Errors::ProvisionerWinRMUnsupported,
|
|
|
|
name: "salt.install_master"
|
2014-05-17 00:19:34 +00:00
|
|
|
else
|
|
|
|
desired_binaries.push('salt-master')
|
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if @config.install_syndic
|
2014-05-17 00:19:34 +00:00
|
|
|
if @machine.config.vm.communicator == :winrm
|
2014-05-19 12:00:46 +00:00
|
|
|
raise Vagrant::Errors::ProvisionerWinRMUnsupported,
|
|
|
|
name: "salt.install_syndic"
|
2014-05-17 00:19:34 +00:00
|
|
|
else
|
|
|
|
desired_binaries.push('salt-syndic')
|
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
found = true
|
|
|
|
for binary in desired_binaries
|
|
|
|
@machine.env.ui.info "Checking if %s is installed" % binary
|
|
|
|
if !@machine.communicate.test("which %s" % binary)
|
|
|
|
@machine.env.ui.info "%s was not found." % binary
|
|
|
|
found = false
|
|
|
|
else
|
|
|
|
@machine.env.ui.info "%s found" % binary
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return found
|
|
|
|
end
|
|
|
|
|
|
|
|
def need_configure
|
2018-01-31 11:41:52 +00:00
|
|
|
@config.minion_config or @config.minion_key or @config.master_config or @config.master_key or @config.grains_config or @config.version or @config.minion_json_config or @config.master_json_config
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def need_install
|
|
|
|
if @config.always_install
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return !binaries_found()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def temp_config_dir
|
2014-05-17 00:19:34 +00:00
|
|
|
if @machine.config.vm.communicator == :winrm
|
|
|
|
return @config.temp_config_dir || "C:\\tmp"
|
|
|
|
else
|
|
|
|
return @config.temp_config_dir || "/tmp"
|
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Generates option string for bootstrap script
|
|
|
|
def bootstrap_options(install, configure, config_dir)
|
|
|
|
options = ""
|
|
|
|
|
2014-03-13 03:04:57 +00:00
|
|
|
# Any extra options passed to bootstrap
|
2014-02-20 04:24:05 +00:00
|
|
|
if @config.bootstrap_options
|
|
|
|
options = "%s %s" % [options, @config.bootstrap_options]
|
|
|
|
end
|
|
|
|
|
2018-01-31 11:41:52 +00:00
|
|
|
if @config.master_json_config && @machine.config.vm.communicator != :winrm
|
|
|
|
config = @config.master_json_config
|
|
|
|
options = "%s -J '#{config}'" % [options]
|
|
|
|
end
|
|
|
|
|
|
|
|
if @config.minion_json_config && @machine.config.vm.communicator != :winrm
|
|
|
|
config = @config.minion_json_config
|
|
|
|
options = "%s -j '#{config}'" % [options]
|
|
|
|
end
|
|
|
|
|
2015-08-03 11:11:32 +00:00
|
|
|
if configure && @machine.config.vm.communicator != :winrm
|
2014-04-24 15:56:54 +00:00
|
|
|
options = "%s -F -c %s" % [options, config_dir]
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
|
2017-08-29 16:38:29 +00:00
|
|
|
if @config.seed_master && @config.install_master && @machine.config.vm.communicator != :winrm
|
2013-05-18 17:29:36 +00:00
|
|
|
seed_dir = "/tmp/minion-seed-keys"
|
|
|
|
@machine.communicate.sudo("mkdir -p -m777 #{seed_dir}")
|
|
|
|
@config.seed_master.each do |name, keyfile|
|
|
|
|
sourcepath = expanded_path(keyfile).to_s
|
2013-10-10 11:04:31 +00:00
|
|
|
dest = "#{seed_dir}/#{name}"
|
2013-06-19 22:51:44 +00:00
|
|
|
@machine.communicate.upload(sourcepath, dest)
|
2013-05-18 17:29:36 +00:00
|
|
|
end
|
2013-06-19 22:51:44 +00:00
|
|
|
options = "#{options} -k #{seed_dir}"
|
2013-05-18 17:29:36 +00:00
|
|
|
end
|
|
|
|
|
2017-08-29 16:38:29 +00:00
|
|
|
if configure && !install && @machine.config.vm.communicator != :winrm
|
2013-04-18 12:41:34 +00:00
|
|
|
options = "%s -C" % options
|
2014-04-27 16:36:01 +00:00
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
|
2017-08-29 16:38:29 +00:00
|
|
|
if @config.install_master && @machine.config.vm.communicator != :winrm
|
2014-04-27 16:29:13 +00:00
|
|
|
options = "%s -M" % options
|
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
|
2017-08-29 16:38:29 +00:00
|
|
|
if @config.install_syndic && @machine.config.vm.communicator != :winrm
|
2014-04-27 16:29:13 +00:00
|
|
|
options = "%s -S" % options
|
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
|
2017-08-29 16:38:29 +00:00
|
|
|
if @config.no_minion && @machine.config.vm.communicator != :winrm
|
2014-04-27 16:29:13 +00:00
|
|
|
options = "%s -N" % options
|
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
|
2017-08-29 16:38:29 +00:00
|
|
|
if @config.install_type && @machine.config.vm.communicator != :winrm
|
2014-04-27 16:29:13 +00:00
|
|
|
options = "%s %s" % [options, @config.install_type]
|
|
|
|
end
|
|
|
|
|
2017-08-29 16:38:29 +00:00
|
|
|
if @config.install_args && @machine.config.vm.communicator != :winrm
|
2014-04-27 16:29:13 +00:00
|
|
|
options = "%s %s" % [options, @config.install_args]
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if @config.verbose
|
|
|
|
@machine.env.ui.info "Using Bootstrap Options: %s" % options
|
|
|
|
end
|
|
|
|
|
|
|
|
return options
|
|
|
|
end
|
|
|
|
|
|
|
|
## Actions
|
2013-05-18 17:29:36 +00:00
|
|
|
# Get pillar string to pass with the salt command
|
|
|
|
def get_pillar
|
|
|
|
" pillar='#{@config.pillar_data.to_json}'" if !@config.pillar_data.empty?
|
|
|
|
end
|
|
|
|
|
2014-05-01 18:07:07 +00:00
|
|
|
# Get colorization option string to pass with the salt command
|
|
|
|
def get_colorize
|
|
|
|
@config.colorize ? " --force-color" : " --no-color"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Get log output level option string to pass with the salt command
|
|
|
|
def get_loglevel
|
|
|
|
log_levels = ["all", "garbage", "trace", "debug", "info", "warning", "error", "quiet"]
|
|
|
|
if log_levels.include? @config.log_level
|
|
|
|
" --log-level=#{@config.log_level}"
|
|
|
|
else
|
|
|
|
" --log-level=debug"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-04 21:10:51 +00:00
|
|
|
# Get command-line options for masterless provisioning
|
|
|
|
def get_masterless
|
|
|
|
options = ""
|
|
|
|
|
|
|
|
if @config.masterless
|
|
|
|
options = " --local"
|
|
|
|
if @config.minion_id
|
|
|
|
options += " --id #{@config.minion_id}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return options
|
|
|
|
end
|
|
|
|
|
2017-08-29 19:57:49 +00:00
|
|
|
# Append additional arguments to the salt command
|
|
|
|
def get_salt_args
|
|
|
|
" " + Array(@config.salt_args).join(" ")
|
|
|
|
end
|
|
|
|
|
2017-08-29 17:24:10 +00:00
|
|
|
# Append additional arguments to the salt-call command
|
|
|
|
def get_call_args
|
2017-08-29 19:57:49 +00:00
|
|
|
" " + Array(@config.salt_call_args).join(" ")
|
2017-08-29 17:24:10 +00:00
|
|
|
end
|
|
|
|
|
2013-04-18 12:41:34 +00:00
|
|
|
# Copy master and minion configs to VM
|
|
|
|
def upload_configs
|
|
|
|
if @config.minion_config
|
|
|
|
@machine.env.ui.info "Copying salt minion config to vm."
|
|
|
|
@machine.communicate.upload(expanded_path(@config.minion_config).to_s, temp_config_dir + "/minion")
|
|
|
|
end
|
|
|
|
|
|
|
|
if @config.master_config
|
|
|
|
@machine.env.ui.info "Copying salt master config to vm."
|
|
|
|
@machine.communicate.upload(expanded_path(@config.master_config).to_s, temp_config_dir + "/master")
|
|
|
|
end
|
2014-12-02 21:25:30 +00:00
|
|
|
|
|
|
|
if @config.grains_config
|
|
|
|
@machine.env.ui.info "Copying salt grains config to vm."
|
|
|
|
@machine.communicate.upload(expanded_path(@config.grains_config).to_s, temp_config_dir + "/grains")
|
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Copy master and minion keys to VM
|
|
|
|
def upload_keys
|
|
|
|
if @config.minion_key and @config.minion_pub
|
|
|
|
@machine.env.ui.info "Uploading minion keys."
|
|
|
|
@machine.communicate.upload(expanded_path(@config.minion_key).to_s, temp_config_dir + "/minion.pem")
|
2014-04-29 14:28:57 +00:00
|
|
|
@machine.communicate.sudo("chmod u+w #{temp_config_dir}/minion.pem")
|
2013-04-18 12:41:34 +00:00
|
|
|
@machine.communicate.upload(expanded_path(@config.minion_pub).to_s, temp_config_dir + "/minion.pub")
|
|
|
|
end
|
|
|
|
|
|
|
|
if @config.master_key and @config.master_pub
|
|
|
|
@machine.env.ui.info "Uploading master keys."
|
|
|
|
@machine.communicate.upload(expanded_path(@config.master_key).to_s, temp_config_dir + "/master.pem")
|
2014-04-29 14:28:57 +00:00
|
|
|
@machine.communicate.sudo("chmod u+w #{temp_config_dir}/master.pem")
|
2013-04-18 12:41:34 +00:00
|
|
|
@machine.communicate.upload(expanded_path(@config.master_pub).to_s, temp_config_dir + "/master.pub")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Get bootstrap file location, bundled or custom
|
|
|
|
def get_bootstrap
|
|
|
|
if @config.bootstrap_script
|
|
|
|
bootstrap_abs_path = expanded_path(@config.bootstrap_script)
|
|
|
|
else
|
2014-05-17 00:19:34 +00:00
|
|
|
if @machine.config.vm.communicator == :winrm
|
|
|
|
bootstrap_abs_path = Pathname.new("../bootstrap-salt.ps1").expand_path(__FILE__)
|
|
|
|
else
|
|
|
|
bootstrap_abs_path = Pathname.new("../bootstrap-salt.sh").expand_path(__FILE__)
|
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
2013-08-30 00:40:59 +00:00
|
|
|
|
2013-04-18 12:41:34 +00:00
|
|
|
return bootstrap_abs_path
|
|
|
|
end
|
|
|
|
|
|
|
|
# Determine if we are configure and/or installing, then do either
|
|
|
|
def run_bootstrap_script
|
|
|
|
install = need_install()
|
|
|
|
configure = need_configure()
|
|
|
|
config_dir = temp_config_dir()
|
|
|
|
options = bootstrap_options(install, configure, config_dir)
|
|
|
|
|
|
|
|
if configure or install
|
|
|
|
if configure and !install
|
|
|
|
@machine.env.ui.info "Salt binaries found. Configuring only."
|
|
|
|
else
|
|
|
|
@machine.env.ui.info "Bootstrapping Salt... (this may take a while)"
|
|
|
|
end
|
|
|
|
|
2013-08-30 00:40:59 +00:00
|
|
|
bootstrap_path = get_bootstrap
|
2014-05-17 00:19:34 +00:00
|
|
|
if @machine.config.vm.communicator == :winrm
|
2015-07-04 07:25:31 +00:00
|
|
|
if @config.version
|
2016-10-17 16:35:05 +00:00
|
|
|
options += " -version %s" % @config.version
|
2015-07-07 06:24:23 +00:00
|
|
|
end
|
2017-08-29 16:38:29 +00:00
|
|
|
if @config.python_version
|
|
|
|
options += " -pythonVersion %s" % @config.python_version
|
|
|
|
end
|
2015-07-07 06:24:23 +00:00
|
|
|
if @config.run_service
|
|
|
|
@machine.env.ui.info "Salt minion will be stopped after installing."
|
2016-10-17 16:35:05 +00:00
|
|
|
options += " -runservice %s" % @config.run_service
|
2015-07-07 06:24:23 +00:00
|
|
|
end
|
|
|
|
if @config.minion_id
|
|
|
|
@machine.env.ui.info "Setting minion to @config.minion_id."
|
2016-10-17 16:35:05 +00:00
|
|
|
options += " -minion %s" % @config.minion_id
|
2015-07-07 06:24:23 +00:00
|
|
|
end
|
|
|
|
if @config.master_id
|
|
|
|
@machine.env.ui.info "Setting master to @config.master_id."
|
2016-10-17 16:35:05 +00:00
|
|
|
options += " -master %s" % @config.master_id
|
2015-07-04 07:25:31 +00:00
|
|
|
end
|
2014-05-17 00:19:34 +00:00
|
|
|
bootstrap_destination = File.join(config_dir, "bootstrap_salt.ps1")
|
|
|
|
else
|
|
|
|
bootstrap_destination = File.join(config_dir, "bootstrap_salt.sh")
|
|
|
|
end
|
2014-08-06 18:05:03 +00:00
|
|
|
|
2014-10-10 10:20:50 +00:00
|
|
|
if @machine.communicate.test("test -f %s" % bootstrap_destination)
|
|
|
|
@machine.communicate.sudo("rm -f %s" % bootstrap_destination)
|
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
@machine.communicate.upload(bootstrap_path.to_s, bootstrap_destination)
|
|
|
|
@machine.communicate.sudo("chmod +x %s" % bootstrap_destination)
|
2014-05-17 00:19:34 +00:00
|
|
|
if @machine.config.vm.communicator == :winrm
|
2017-09-23 01:08:30 +00:00
|
|
|
bootstrap = @machine.communicate.sudo("powershell.exe -NonInteractive -NoProfile -executionpolicy bypass -file %s %s" % [bootstrap_destination, options]) do |type, data|
|
2014-05-17 00:19:34 +00:00
|
|
|
if data[0] == "\n"
|
|
|
|
# Remove any leading newline but not whitespace. If we wanted to
|
|
|
|
# remove newlines and whitespace we would have used data.lstrip
|
|
|
|
data = data[1..-1]
|
|
|
|
end
|
|
|
|
if @config.verbose
|
|
|
|
@machine.env.ui.info(data.rstrip)
|
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
2014-05-17 00:19:34 +00:00
|
|
|
else
|
|
|
|
bootstrap = @machine.communicate.sudo("%s %s" % [bootstrap_destination, options]) do |type, data|
|
|
|
|
if data[0] == "\n"
|
|
|
|
# Remove any leading newline but not whitespace. If we wanted to
|
|
|
|
# remove newlines and whitespace we would have used data.lstrip
|
|
|
|
data = data[1..-1]
|
|
|
|
end
|
|
|
|
if @config.verbose
|
|
|
|
@machine.env.ui.info(data.rstrip)
|
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if !bootstrap
|
|
|
|
raise Salt::Errors::SaltError, :bootstrap_failed
|
|
|
|
end
|
2014-08-06 18:05:03 +00:00
|
|
|
|
2013-04-18 12:41:34 +00:00
|
|
|
if configure and !install
|
|
|
|
@machine.env.ui.info "Salt successfully configured!"
|
|
|
|
elsif configure and install
|
|
|
|
@machine.env.ui.info "Salt successfully configured and installed!"
|
|
|
|
elsif !configure and install
|
|
|
|
@machine.env.ui.info "Salt successfully installed!"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@machine.env.ui.info "Salt did not need installing or configuring."
|
|
|
|
end
|
|
|
|
end
|
2014-08-06 18:05:03 +00:00
|
|
|
|
2013-10-03 19:28:35 +00:00
|
|
|
def call_overstate
|
|
|
|
if @config.run_overstate
|
2017-07-03 17:27:53 +00:00
|
|
|
# If verbose is on, do not duplicate a failed command's output in the error message.
|
|
|
|
ssh_opts = {}
|
|
|
|
if @config.verbose
|
|
|
|
ssh_opts = { error_key: :ssh_bad_exit_status_muted }
|
|
|
|
end
|
2014-05-19 12:00:46 +00:00
|
|
|
if @config.install_master
|
|
|
|
@machine.env.ui.info "Calling state.overstate... (this may take a while)"
|
|
|
|
@machine.communicate.sudo("salt '*' saltutil.sync_all")
|
2017-07-03 17:27:53 +00:00
|
|
|
@machine.communicate.sudo("salt-run state.over", ssh_opts) do |type, data|
|
2014-05-19 12:00:46 +00:00
|
|
|
if @config.verbose
|
|
|
|
@machine.env.ui.info(data)
|
2013-10-03 19:28:35 +00:00
|
|
|
end
|
|
|
|
end
|
2014-05-19 12:00:46 +00:00
|
|
|
else
|
|
|
|
@machine.env.ui.info "run_overstate does not make sense on a minion. Not running state.overstate."
|
|
|
|
end
|
2013-10-03 19:28:35 +00:00
|
|
|
else
|
|
|
|
@machine.env.ui.info "run_overstate set to false. Not running state.overstate."
|
|
|
|
end
|
|
|
|
end
|
2013-06-19 22:51:44 +00:00
|
|
|
|
2013-04-18 12:41:34 +00:00
|
|
|
def call_highstate
|
2016-04-05 15:24:47 +00:00
|
|
|
if @config.run_highstate
|
2017-07-03 17:27:53 +00:00
|
|
|
# If verbose is on, do not duplicate a failed command's output in the error message.
|
|
|
|
ssh_opts = {}
|
|
|
|
if @config.verbose
|
|
|
|
ssh_opts = { error_key: :ssh_bad_exit_status_muted }
|
|
|
|
end
|
|
|
|
|
2013-04-18 12:41:34 +00:00
|
|
|
@machine.env.ui.info "Calling state.highstate... (this may take a while)"
|
|
|
|
if @config.install_master
|
2016-04-05 15:24:47 +00:00
|
|
|
unless @config.masterless?
|
|
|
|
@machine.communicate.sudo("salt '*' saltutil.sync_all")
|
|
|
|
end
|
2017-08-29 19:57:49 +00:00
|
|
|
options = "#{get_masterless}#{get_loglevel}#{get_colorize}#{get_pillar}#{get_salt_args}"
|
|
|
|
@machine.communicate.sudo("salt '*' state.highstate --verbose#{options}", ssh_opts) do |type, data|
|
2016-04-05 15:24:47 +00:00
|
|
|
if @config.verbose
|
2014-12-04 05:48:30 +00:00
|
|
|
@machine.env.ui.info(data.rstrip)
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
2016-04-05 15:24:47 +00:00
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
else
|
2014-05-19 12:10:58 +00:00
|
|
|
if @machine.config.vm.communicator == :winrm
|
2014-05-19 11:14:25 +00:00
|
|
|
opts = { elevated: true }
|
2016-04-05 15:24:47 +00:00
|
|
|
unless @config.masterless?
|
|
|
|
@machine.communicate.execute("C:\\salt\\salt-call.bat saltutil.sync_all", opts)
|
|
|
|
end
|
2017-07-03 17:27:53 +00:00
|
|
|
# TODO: something equivalent to { error_key: :ssh_bad_exit_status_muted }?
|
2017-08-29 19:57:49 +00:00
|
|
|
options = "#{get_masterless}#{get_loglevel}#{get_colorize}#{get_pillar}#{get_call_args}"
|
|
|
|
@machine.communicate.execute("C:\\salt\\salt-call.bat state.highstate --retcode-passthrough#{options}", opts) do |type, data|
|
2014-05-17 00:19:34 +00:00
|
|
|
if @config.verbose
|
2014-12-04 05:48:30 +00:00
|
|
|
@machine.env.ui.info(data.rstrip)
|
2014-05-17 00:19:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
2016-04-05 15:24:47 +00:00
|
|
|
unless @config.masterless?
|
|
|
|
@machine.communicate.sudo("salt-call saltutil.sync_all")
|
|
|
|
end
|
2017-08-29 19:57:49 +00:00
|
|
|
options = "#{get_masterless}#{get_loglevel}#{get_colorize}#{get_pillar}#{get_call_args}"
|
|
|
|
@machine.communicate.sudo("salt-call state.highstate --retcode-passthrough#{options}", ssh_opts) do |type, data|
|
2014-05-17 00:19:34 +00:00
|
|
|
if @config.verbose
|
2014-12-04 05:48:30 +00:00
|
|
|
@machine.env.ui.info(data.rstrip)
|
2014-05-17 00:19:34 +00:00
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@machine.env.ui.info "run_highstate set to false. Not running state.highstate."
|
|
|
|
end
|
|
|
|
end
|
2014-08-20 19:04:32 +00:00
|
|
|
|
|
|
|
def call_orchestrate
|
2015-05-31 17:19:03 +00:00
|
|
|
if !@config.orchestrations
|
2014-08-20 19:04:32 +00:00
|
|
|
@machine.env.ui.info "orchestrate is nil. Not running state.orchestrate."
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-05-31 17:19:03 +00:00
|
|
|
if !@config.install_master
|
|
|
|
@machine.env.ui.info "orchestrate does not make sense on a minion. Not running state.orchestrate."
|
2014-08-20 19:04:32 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
log_output = lambda do |type, data|
|
|
|
|
if @config.verbose
|
|
|
|
@machine.env.ui.info(data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-03 17:27:53 +00:00
|
|
|
# If verbose is on, do not duplicate a failed command's output in the error message.
|
|
|
|
ssh_opts = {}
|
|
|
|
if @config.verbose
|
|
|
|
ssh_opts = { error_key: :ssh_bad_exit_status_muted }
|
|
|
|
end
|
|
|
|
|
2014-08-20 19:04:32 +00:00
|
|
|
@machine.env.ui.info "Running the following orchestrations: #{@config.orchestrations}"
|
|
|
|
@machine.env.ui.info "Running saltutil.sync_all before orchestrating"
|
2017-07-03 17:27:53 +00:00
|
|
|
@machine.communicate.sudo("salt '*' saltutil.sync_all", ssh_opts, &log_output)
|
2014-08-20 19:04:32 +00:00
|
|
|
|
|
|
|
@config.orchestrations.each do |orchestration|
|
|
|
|
cmd = "salt-run -l info state.orchestrate #{orchestration}"
|
|
|
|
@machine.env.ui.info "Calling #{cmd}... (this may take a while)"
|
2017-07-03 17:27:53 +00:00
|
|
|
@machine.communicate.sudo(cmd, ssh_opts, &log_output)
|
2014-08-20 19:04:32 +00:00
|
|
|
end
|
|
|
|
end
|
2016-10-17 16:35:05 +00:00
|
|
|
|
|
|
|
# Sets optimistic default values into config
|
|
|
|
def set_default_configs
|
|
|
|
OPTIMISTIC_PATH_DEFAULTS.each do |config_key, config_default|
|
|
|
|
if config.send(config_key) == Config::UNSET_VALUE
|
|
|
|
config_value = File.exist?(expanded_path(config_default)) ? config_default : nil
|
|
|
|
config.send("#{config_key}=", config_value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|