Class: VagrantSalt::Provisioner
- Inherits:
-
Vagrant::Provisioners::Base
- Object
- Vagrant::Provisioners::Base
- VagrantSalt::Provisioner
- Defined in:
- lib/vagrant-salt/provisioner.rb
Defined Under Namespace
Classes: Config
Class Method Summary collapse
Instance Method Summary collapse
- #accept_minion_key ⇒ Object
- #bootstrap_salt_minion ⇒ Object
- #call_highstate ⇒ Object
- #prepare ⇒ Object
- #provision! ⇒ Object
- #salt_exists ⇒ Object
- #upload_minion_config ⇒ Object
- #upload_minion_keys ⇒ Object
- #verify_shared_folders(folders) ⇒ Object
Class Method Details
.config_class ⇒ Object
35 36 37 |
# File 'lib/vagrant-salt/provisioner.rb', line 35 def self.config_class Config end |
Instance Method Details
#accept_minion_key ⇒ Object
78 79 80 81 |
# File 'lib/vagrant-salt/provisioner.rb', line 78 def accept_minion_key env[:ui].info "Accepting minion key." env[:vm].channel.sudo("salt-key -A") end |
#bootstrap_salt_minion ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/vagrant-salt/provisioner.rb', line 59 def bootstrap_salt_minion env[:ui].info "Bootstrapping salt-minion on VM..." @expanded_bootstrap_script_path = config.(__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.) 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 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 |
#call_highstate ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/vagrant-salt/provisioner.rb', line 83 def call_highstate if config.run_highstate env[:ui].info "Calling state.highstate" env[:vm].channel.sudo("salt-call saltutil.sync_all") env[:vm].channel.sudo("salt-call state.highstate") do |type, data| env[:ui].info(data) end else env[:ui].info "run_highstate set to false. Not running state.highstate." end end |
#prepare ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/vagrant-salt/provisioner.rb', line 39 def prepare # Calculate the paths we're going to use based on the environment @expanded_minion_config_path = config.(env[:root_path], config.minion_config) if config.minion_key @expanded_minion_key_path = config.(env[:root_path], config.minion_key) @expanded_minion_pub_path = config.(env[:root_path], config.minion_pub) end end |
#provision! ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/vagrant-salt/provisioner.rb', line 106 def provision! upload_minion_config if config.minion_key upload_minion_keys end if !salt_exists bootstrap_salt_minion end call_highstate end |
#salt_exists ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/vagrant-salt/provisioner.rb', line 49 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 end env[:ui].info "Salt binaries not found." return false end |
#upload_minion_config ⇒ Object
95 96 97 98 |
# File 'lib/vagrant-salt/provisioner.rb', line 95 def upload_minion_config env[:ui].info "Copying salt minion config to vm." env[:vm].channel.upload(@expanded_minion_config_path.to_s, config.temp_config_dir + "minion") end |
#upload_minion_keys ⇒ Object
100 101 102 103 104 |
# File 'lib/vagrant-salt/provisioner.rb', line 100 def upload_minion_keys env[:ui].info "Uploading minion key." 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 |
#verify_shared_folders(folders) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/vagrant-salt/provisioner.rb', line 121 def verify_shared_folders(folders) folders.each do |folder| # @logger.debug("Checking for shared folder: #{folder}") env[:ui].info "Checking shared folder #{folder}" if !env[:vm].channel.test("test -d #{folder}") raise "Missing folder #{folder}" end end end |