2013-04-18 12:41:34 +00:00
|
|
|
require "vagrant"
|
2014-03-07 17:18:34 +00:00
|
|
|
require "vagrant/util/deep_merge"
|
2013-04-18 12:41:34 +00:00
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module Salt
|
|
|
|
class Config < Vagrant.plugin("2", :config)
|
|
|
|
## salty-vagrant options
|
|
|
|
attr_accessor :minion_config
|
|
|
|
attr_accessor :minion_key
|
|
|
|
attr_accessor :minion_pub
|
|
|
|
attr_accessor :master_config
|
|
|
|
attr_accessor :master_key
|
|
|
|
attr_accessor :master_pub
|
2014-12-02 21:25:30 +00:00
|
|
|
attr_accessor :grains_config
|
2013-04-18 12:41:34 +00:00
|
|
|
attr_accessor :run_highstate
|
2013-10-03 19:28:35 +00:00
|
|
|
attr_accessor :run_overstate
|
2014-08-20 19:04:32 +00:00
|
|
|
attr_accessor :orchestrations
|
2013-04-18 12:41:34 +00:00
|
|
|
attr_accessor :always_install
|
|
|
|
attr_accessor :bootstrap_script
|
|
|
|
attr_accessor :verbose
|
|
|
|
attr_accessor :seed_master
|
2013-05-18 17:29:36 +00:00
|
|
|
attr_reader :pillar_data
|
2014-05-01 18:07:07 +00:00
|
|
|
attr_accessor :colorize
|
|
|
|
attr_accessor :log_level
|
2014-03-15 20:56:24 +00:00
|
|
|
attr_accessor :masterless
|
|
|
|
attr_accessor :minion_id
|
2017-08-29 17:24:10 +00:00
|
|
|
attr_accessor :salt_call_args
|
2013-04-18 12:41:34 +00:00
|
|
|
|
|
|
|
## bootstrap options
|
|
|
|
attr_accessor :temp_config_dir
|
|
|
|
attr_accessor :install_type
|
|
|
|
attr_accessor :install_args
|
|
|
|
attr_accessor :install_master
|
|
|
|
attr_accessor :install_syndic
|
|
|
|
attr_accessor :no_minion
|
|
|
|
attr_accessor :bootstrap_options
|
2015-07-04 07:25:31 +00:00
|
|
|
attr_accessor :version
|
2015-07-07 06:24:23 +00:00
|
|
|
attr_accessor :run_service
|
|
|
|
attr_accessor :master_id
|
2013-04-18 12:41:34 +00:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
@minion_config = UNSET_VALUE
|
|
|
|
@minion_key = UNSET_VALUE
|
|
|
|
@minion_pub = UNSET_VALUE
|
|
|
|
@master_config = UNSET_VALUE
|
|
|
|
@master_key = UNSET_VALUE
|
|
|
|
@master_pub = UNSET_VALUE
|
2014-12-02 21:25:30 +00:00
|
|
|
@grains_config = UNSET_VALUE
|
2013-04-18 12:41:34 +00:00
|
|
|
@run_highstate = UNSET_VALUE
|
2013-10-03 19:28:35 +00:00
|
|
|
@run_overstate = UNSET_VALUE
|
2013-04-18 12:41:34 +00:00
|
|
|
@always_install = UNSET_VALUE
|
|
|
|
@bootstrap_script = UNSET_VALUE
|
|
|
|
@verbose = UNSET_VALUE
|
|
|
|
@seed_master = UNSET_VALUE
|
2013-05-18 17:29:36 +00:00
|
|
|
@pillar_data = UNSET_VALUE
|
2014-05-01 18:07:07 +00:00
|
|
|
@colorize = UNSET_VALUE
|
|
|
|
@log_level = UNSET_VALUE
|
2013-04-18 12:41:34 +00:00
|
|
|
@temp_config_dir = UNSET_VALUE
|
|
|
|
@install_type = UNSET_VALUE
|
|
|
|
@install_args = UNSET_VALUE
|
|
|
|
@install_master = UNSET_VALUE
|
|
|
|
@install_syndic = UNSET_VALUE
|
|
|
|
@no_minion = UNSET_VALUE
|
|
|
|
@bootstrap_options = UNSET_VALUE
|
2014-03-15 20:56:24 +00:00
|
|
|
@masterless = UNSET_VALUE
|
|
|
|
@minion_id = UNSET_VALUE
|
2015-07-04 07:25:31 +00:00
|
|
|
@version = UNSET_VALUE
|
2015-07-07 06:24:23 +00:00
|
|
|
@run_service = UNSET_VALUE
|
|
|
|
@master_id = UNSET_VALUE
|
2017-08-29 17:24:10 +00:00
|
|
|
@salt_call_args = UNSET_VALUE
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def finalize!
|
2014-12-02 21:25:30 +00:00
|
|
|
@grains_config = nil if @grains_config == UNSET_VALUE
|
2013-04-18 12:41:34 +00:00
|
|
|
@run_highstate = nil if @run_highstate == UNSET_VALUE
|
2013-10-03 19:28:35 +00:00
|
|
|
@run_overstate = nil if @run_overstate == UNSET_VALUE
|
2013-04-18 12:41:34 +00:00
|
|
|
@always_install = nil if @always_install == UNSET_VALUE
|
|
|
|
@bootstrap_script = nil if @bootstrap_script == UNSET_VALUE
|
|
|
|
@verbose = nil if @verbose == UNSET_VALUE
|
|
|
|
@seed_master = nil if @seed_master == UNSET_VALUE
|
2013-05-18 17:29:36 +00:00
|
|
|
@pillar_data = {} if @pillar_data == UNSET_VALUE
|
2014-05-01 18:07:07 +00:00
|
|
|
@colorize = nil if @colorize == UNSET_VALUE
|
|
|
|
@log_level = nil if @log_level == UNSET_VALUE
|
2013-04-18 12:41:34 +00:00
|
|
|
@temp_config_dir = nil if @temp_config_dir == UNSET_VALUE
|
|
|
|
@install_type = nil if @install_type == UNSET_VALUE
|
|
|
|
@install_args = nil if @install_args == UNSET_VALUE
|
|
|
|
@install_master = nil if @install_master == UNSET_VALUE
|
|
|
|
@install_syndic = nil if @install_syndic == UNSET_VALUE
|
|
|
|
@no_minion = nil if @no_minion == UNSET_VALUE
|
|
|
|
@bootstrap_options = nil if @bootstrap_options == UNSET_VALUE
|
2015-07-04 07:25:31 +00:00
|
|
|
@masterless = false if @masterless == UNSET_VALUE
|
|
|
|
@minion_id = nil if @minion_id == UNSET_VALUE
|
|
|
|
@version = nil if @version == UNSET_VALUE
|
2015-07-07 06:24:23 +00:00
|
|
|
@run_service = nil if @run_service == UNSET_VALUE
|
|
|
|
@master_id = nil if @master_id == UNSET_VALUE
|
2017-08-29 17:24:10 +00:00
|
|
|
@salt_call_args = nil if @salt_call_args == UNSET_VALUE
|
2016-10-17 16:35:05 +00:00
|
|
|
|
|
|
|
# NOTE: Optimistic defaults are set in the provisioner. UNSET_VALUEs
|
|
|
|
# are converted there to allow proper detection of unset values.
|
|
|
|
# @minion_config = nil if @minion_config == UNSET_VALUE
|
|
|
|
# @minion_key = nil if @minion_key == UNSET_VALUE
|
|
|
|
# @minion_pub = nil if @minion_pub == UNSET_VALUE
|
|
|
|
# @master_config = nil if @master_config == UNSET_VALUE
|
|
|
|
# @master_key = nil if @master_key == UNSET_VALUE
|
|
|
|
# @master_pub = nil if @master_pub == UNSET_VALUE
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
|
2013-05-18 17:29:36 +00:00
|
|
|
def pillar(data)
|
|
|
|
@pillar_data = {} if @pillar_data == UNSET_VALUE
|
2014-03-07 17:18:34 +00:00
|
|
|
@pillar_data = Vagrant::Util::DeepMerge.deep_merge(@pillar_data, data)
|
2013-05-18 17:29:36 +00:00
|
|
|
end
|
|
|
|
|
2013-04-18 12:41:34 +00:00
|
|
|
def validate(machine)
|
2013-09-04 23:56:45 +00:00
|
|
|
errors = _detected_errors
|
2016-10-17 16:35:05 +00:00
|
|
|
if @minion_config && @minion_config != UNSET_VALUE
|
2014-02-24 15:58:12 +00:00
|
|
|
expanded = Pathname.new(@minion_config).expand_path(machine.env.root_path)
|
|
|
|
if !expanded.file?
|
2015-04-26 18:34:34 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.salt.minion_config_nonexist", missing_config_file: expanded)
|
2014-02-24 15:58:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-17 16:35:05 +00:00
|
|
|
if @master_config && @master_config != UNSET_VALUE
|
2014-04-19 21:24:30 +00:00
|
|
|
expanded = Pathname.new(@master_config).expand_path(machine.env.root_path)
|
|
|
|
if !expanded.file?
|
2015-04-26 18:34:34 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.salt.master_config_nonexist", missing_config_file: expanded)
|
2014-04-19 21:24:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-18 12:41:34 +00:00
|
|
|
if @minion_key || @minion_pub
|
|
|
|
if !@minion_key || !@minion_pub
|
2014-01-08 17:11:11 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.salt.missing_key")
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-08 17:11:11 +00:00
|
|
|
if @master_key || @master_pub
|
|
|
|
if !@master_key || !@master_pub
|
2013-12-28 03:37:54 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.salt.missing_key")
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-12-02 21:25:30 +00:00
|
|
|
if @grains_config
|
|
|
|
expanded = Pathname.new(@grains_config).expand_path(machine.env.root_path)
|
|
|
|
if !expanded.file?
|
|
|
|
errors << I18n.t("vagrant.provisioners.salt.grains_config_nonexist")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-30 00:26:52 +00:00
|
|
|
if @install_master && !@no_minion && !@seed_master && @run_highstate
|
2013-12-28 03:37:54 +00:00
|
|
|
errors << I18n.t("vagrant.provisioners.salt.must_accept_keys")
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
|
2013-12-28 03:37:54 +00:00
|
|
|
return {"salt provisioner" => errors}
|
2013-04-18 12:41:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|