Merge branch 'shell-provisioner-remote-script' of https://github.com/fgrehm/vagrant into fgrehm-shell-provisioner-remote-script

Conflicts:
	CHANGELOG.md
This commit is contained in:
Mitchell Hashimoto 2013-09-03 10:40:24 -07:00
commit c752c37586
3 changed files with 20 additions and 3 deletions

View File

@ -37,6 +37,7 @@ FEATURES:
- Static IP can now be set on public networks. [GH-1745] - Static IP can now be set on public networks. [GH-1745]
- Add `Vagrant.has_plugin?` method for use in Vagrantfile to check - Add `Vagrant.has_plugin?` method for use in Vagrantfile to check
if a plugin is installed. [GH-1736] if a plugin is installed. [GH-1736]
- Support for remote shell provisioning scripts [GH-1787]
IMPROVEMENTS: IMPROVEMENTS:

View File

@ -1,3 +1,5 @@
require 'uri'
module VagrantPlugins module VagrantPlugins
module Shell module Shell
class Config < Vagrant.plugin("2", :config) class Config < Vagrant.plugin("2", :config)
@ -33,8 +35,8 @@ module VagrantPlugins
errors << I18n.t("vagrant.provisioners.shell.no_path_or_inline") errors << I18n.t("vagrant.provisioners.shell.no_path_or_inline")
end end
# Validate the existence of a script to upload # If it is not an URL, we validate the existence of a script to upload
if path if path && ! remote?
expanded_path = Pathname.new(path).expand_path(machine.env.root_path) expanded_path = Pathname.new(path).expand_path(machine.env.root_path)
if !expanded_path.file? if !expanded_path.file?
errors << I18n.t("vagrant.provisioners.shell.path_invalid", errors << I18n.t("vagrant.provisioners.shell.path_invalid",
@ -54,6 +56,10 @@ module VagrantPlugins
{ "shell provisioner" => errors } { "shell provisioner" => errors }
end end
def remote?
path =~ URI::regexp(["ftp", "http", "https"])
end
end end
end end
end end

View File

@ -1,6 +1,8 @@
require "pathname" require "pathname"
require "tempfile" require "tempfile"
require "vagrant/util/downloader"
module VagrantPlugins module VagrantPlugins
module Shell module Shell
class Provisioner < Vagrant.plugin("2", :provisioner) class Provisioner < Vagrant.plugin("2", :provisioner)
@ -52,7 +54,15 @@ module VagrantPlugins
def with_script_file def with_script_file
script = nil script = nil
if config.path if config.remote?
download_path = @machine.env.tmp_path.join("#{@machine.id}-remote-script")
download_path.delete if download_path.file?
Vagrant::Util::Downloader.new(config.path, download_path).download!
script = download_path.read
download_path.delete
elsif config.path
# Just yield the path to that file... # Just yield the path to that file...
root_path = @machine.env.root_path root_path = @machine.env.root_path
script = Pathname.new(config.path).expand_path(root_path).read script = Pathname.new(config.path).expand_path(root_path).read