lib/vagrant-salt/provisioner.rb in vagrant-salt-0.1.2 vs lib/vagrant-salt/provisioner.rb in vagrant-salt-0.1.4
- old
+ new
@@ -8,24 +8,33 @@
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 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]
+ end
end
def self.config_class
Config
end
@@ -35,20 +44,34 @@
@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
@@ -65,23 +88,28 @@
end
env[:ui].info "Salt binaries not found."
return false
end
- def add_salt_repo
- env[:ui].info "Adding salt repository."
- env[:vm].channel.sudo("apt-get update")
- env[:vm].channel.sudo("apt-get -q -y install python-software-properties")
- env[:vm].channel.sudo("add-apt-repository -y ppa:saltstack/salt")
- env[:vm].channel.sudo("apt-get -q -y update")
+ def bootstrap_salt_minion
+ env[:ui].info "Bootstrapping salt-minion on VM..."
+ @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]
+ 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."
+ end
+ env[:ui].info "Salt binaries installed on VM."
end
- def install_salt_minion
- env[:ui].info "Installing salt binaries."
- env[:vm].channel.sudo("apt-get -q -y install salt-minion")
- end
-
def accept_minion_key
env[:ui].info "Accepting minion key."
env[:vm].channel.sudo("salt-key -A")
end
@@ -116,12 +144,11 @@
if !config.master
verify_shared_folders([config.salt_file_root_guest_path, config.salt_pillar_root_guest_path])
end
if !salt_exists
- add_salt_repo
- install_salt_minion
+ bootstrap_salt_minion
end
upload_minion_config
if config.minion_key
@@ -139,6 +166,6 @@
raise "Missing folder #{folder}"
end
end
end
end
-end
\ No newline at end of file
+end