Class: Vagrant::Provisioners::Shell
- Defined in:
- lib/vagrant/provisioners/shell.rb
Defined Under Namespace
Classes: Config
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #provision! ⇒ Object
-
#with_script_file ⇒ Object
This method yields the path to a script to upload and execute on the remote server.
Methods inherited from Base
#cleanup, #env, #initialize, #prepare, register, registered, #vm
Constructor Details
This class inherits a constructor from Vagrant::Provisioners::Base
Instance Method Details
#provision! ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/vagrant/provisioners/shell.rb', line 73 def provision! args = "" args = " #{config.args}" if config.args commands = ["chmod +x #{config.upload_path}", "#{config.upload_path}#{args}"] with_script_file do |path| # Upload the script to the VM vm.ssh.upload!(path.to_s, config.upload_path) # Execute it with sudo vm.ssh.execute do |ssh| ssh.sudo!(commands) do |ch, type, data| if type == :exit_status ssh.check_exit_status(data, commands) else env.ui.info(data) end end end end end |
#with_script_file ⇒ Object
This method yields the path to a script to upload and execute on the remote server. This method will properly clean up the script file if needed.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vagrant/provisioners/shell.rb', line 53 def with_script_file if config.path # Just yield the path to that file... yield config. return end # Otherwise we have an inline script, we need to Tempfile it, # and handle it specially... file = Tempfile.new('vagrant-shell') begin file.write(config.inline) file.fsync yield file.path ensure file.close file.unlink end end |