Class: Vagrant::Provisioners::Shell
- Defined in:
- lib/vagrant/provisioners/shell.rb
Defined Under Namespace
Classes: Config
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
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, #initialize, #prepare
Constructor Details
This class inherits a constructor from Vagrant::Provisioners::Base
Class Method Details
permalink .config_class ⇒ Object
[View source]
45 46 47 |
# File 'lib/vagrant/provisioners/shell.rb', line 45 def self.config_class Config end |
Instance Method Details
permalink #provision! ⇒ Object
[View source]
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/vagrant/provisioners/shell.rb', line 79 def provision! args = "" args = " #{config.args}" if config.args command = "chmod +x #{config.upload_path} && #{config.upload_path}#{args}" with_script_file do |path| # Upload the script to the VM env[:vm].channel.upload(path.to_s, config.upload_path) # Execute it with sudo env[:vm].channel.sudo(command) do |type, data| if [:stderr, :stdout].include?(type) # Output the data with the proper color based on the stream. color = type == :stdout ? :green : :red # Note: Be sure to chomp the data to avoid the newlines that the # Chef outputs. env[:ui].info(data.chomp, :color => color, :prefix => false) end end end end |
permalink #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.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/vagrant/provisioners/shell.rb', line 52 def with_script_file if config.path # Just yield the path to that file... yield Pathname.new(config.path).(env[:root_path]) return end # Otherwise we have an inline script, we need to Tempfile it, # and handle it specially... file = Tempfile.new('vagrant-shell') # Unless you set binmode, on a Windows host the shell script will # have CRLF line endings instead of LF line endings, causing havoc # when the guest executes it file.binmode begin file.write(config.inline) file.fsync file.close yield file.path ensure file.close file.unlink end end |