lib/vagrant-salt/provisioner.rb in vagrant-salt-0.1.4 vs lib/vagrant-salt/provisioner.rb in vagrant-salt-0.2.0
- old
+ new
@@ -1,87 +1,53 @@
module VagrantSalt
class Provisioner < Vagrant::Provisioners::Base
class Config < Vagrant::Config::Base
attr_accessor :minion_config
+ attr_accessor :temp_config_dir
attr_accessor :minion_key
attr_accessor :minion_pub
- attr_accessor :master
attr_accessor :run_highstate
- attr_accessor :salt_file_root_path
- attr_accessor :salt_file_root_guest_path
- attr_accessor :salt_pillar_root_path
- attr_accessor :salt_pillar_root_guest_path
attr_accessor :salt_install_type
attr_accessor :salt_install_args
def minion_config; @minion_config || "salt/minion.conf"; end
+ def temp_config_dir; @temp_config_dir || "/tmp/"; end
def minion_key; @minion_key || false; end
def minion_pub; @minion_pub || false; end
- def master; @master || false; end
def run_highstate; @run_highstate || false; end
- def salt_file_root_path; @salt_file_root_path || "salt/roots/salt"; end
- def salt_file_root_guest_path; @salt_file_root_guest_path || "/srv/salt"; end
- def salt_pillar_root_path; @salt_pillar_root_path || "salt/roots/pillar"; end
- def salt_pillar_root_guest_path; @salt_pillar_root_guest_path || "/srv/pillar"; end
def salt_install_type; @salt_install_type || ''; end
def salt_install_args; @salt_install_args || ''; end
def expanded_path(root_path, rel_path)
Pathname.new(rel_path).expand_path(root_path)
end
def bootstrap_options
- '%s %s' % [salt_install_type, salt_install_args]
+ options = ''
+ if temp_config_dir
+ options = options + '-c %s' % temp_config_dir
+ end
+ options = options + ' %s %s' % [salt_install_type, salt_install_args]
+ return options
end
end
def self.config_class
Config
end
def prepare
# Calculate the paths we're going to use based on the environment
@expanded_minion_config_path = config.expanded_path(env[:root_path], config.minion_config)
- if !config.master
- env[:ui].info "Adding state tree folders."
- @expanded_salt_file_root_path = config.expanded_path(env[:root_path], config.salt_file_root_path)
- @expanded_salt_pillar_root_path = config.expanded_path(env[:root_path], config.salt_pillar_root_path)
- check_salt_file_root_path
- check_salt_pillar_root_path
- share_salt_file_root_path
- share_salt_pillar_root_path
- end
if config.minion_key
@expanded_minion_key_path = config.expanded_path(env[:root_path], config.minion_key)
@expanded_minion_pub_path = config.expanded_path(env[:root_path], config.minion_pub)
end
end
- def check_salt_file_root_path
- if !File.directory?(@expanded_salt_file_root_path)
- raise "Salt file root path does not exist: #{@expanded_salt_file_root_path}"
- end
- end
-
- def check_salt_pillar_root_path
- if !File.directory?(@expanded_salt_pillar_root_path)
- raise "Salt pillar root path does not exist: #{@expanded_salt_pillar_root_path}"
- end
- end
-
- def share_salt_file_root_path
- env[:ui].info "Sharing file root folder."
- env[:vm].config.vm.share_folder("salt_file_root", config.salt_file_root_guest_path, @expanded_salt_file_root_path)
- end
-
- def share_salt_pillar_root_path
- env[:ui].info "Sharing pillar root path."
- env[:vm].config.vm.share_folder("salt_pillar_root", config.salt_pillar_root_guest_path, @expanded_salt_pillar_root_path)
- end
-
def salt_exists
env[:ui].info "Checking for salt binaries..."
if env[:vm].channel.test("which salt-call") and
env[:vm].channel.test("which salt-minion")
return true
@@ -95,12 +61,13 @@
@expanded_bootstrap_script_path = config.expanded_path(__FILE__, "../../../scripts/bootstrap-salt-minion.sh")
env[:vm].channel.upload(@expanded_bootstrap_script_path.to_s, "/tmp/bootstrap-salt-minion.sh")
env[:vm].channel.sudo("chmod +x /tmp/bootstrap-salt-minion.sh")
bootstrap = env[:vm].channel.sudo("/tmp/bootstrap-salt-minion.sh %s" % config.bootstrap_options) do |type, data|
if data[0] == "\n"
- # Remove any leading newline but not whitespace, for that one would use data.lstrip
- data = data[1..-1]
+ # 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
env[:ui].info(data.rstrip)
end
if !bootstrap
raise "Failed to bootstrap salt-minion on VM, see /var/log/bootstrap-salt-minion.log on VM."
@@ -125,38 +92,31 @@
end
end
def upload_minion_config
env[:ui].info "Copying salt minion config to vm."
- env[:vm].channel.upload(@expanded_minion_config_path.to_s, "/tmp/minion")
- env[:vm].channel.sudo("mv /tmp/minion /etc/salt/minion")
+ env[:vm].channel.upload(@expanded_minion_config_path.to_s, config.temp_config_dir + "minion")
end
def upload_minion_keys
env[:ui].info "Uploading minion key."
- env[:vm].channel.upload(@expanded_minion_key_path.to_s, "/tmp/minion.pem")
- env[:vm].channel.sudo("mv /tmp/minion.pem /etc/salt/pki/minion.pem")
- env[:vm].channel.upload(@expanded_minion_pub_path.to_s, "/tmp/minion.pub")
- env[:vm].channel.sudo("mv /tmp/minion.pub /etc/salt/pki/minion.pub")
+ env[:vm].channel.upload(@expanded_minion_key_path.to_s, config.temp_config_dir + "minion.pem")
+ env[:vm].channel.upload(@expanded_minion_pub_path.to_s, config.temp_config_dir + "minion.pub")
end
def provision!
- if !config.master
- verify_shared_folders([config.salt_file_root_guest_path, config.salt_pillar_root_guest_path])
- end
-
- if !salt_exists
- bootstrap_salt_minion
- end
-
upload_minion_config
if config.minion_key
upload_minion_keys
end
+ if !salt_exists
+ bootstrap_salt_minion
+ end
+
call_highstate
end
def verify_shared_folders(folders)
folders.each do |folder|
@@ -166,6 +126,9 @@
raise "Missing folder #{folder}"
end
end
end
end
+
end
+
+# vim: fenc=utf-8 spell spl=en cc=80 sts=2 sw=2 et