From 47594036b4d926c84b25345a8e64528b295b1673 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Fri, 12 Jul 2013 10:40:41 -0300 Subject: [PATCH] Add support for remote shell provisioner script --- CHANGELOG.md | 1 + plugins/provisioners/shell/config.rb | 10 ++++++++-- plugins/provisioners/shell/provisioner.rb | 12 +++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4999c037..23878c4e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ FEATURES: `knife` if configured to do so. - `vagrant up` has a `--no-destroy-on-error` flag that will not destroy the VM if a fatal error occurs. [GH-2011] + - Support for remote shell provisioning scripts [GH-1787] IMPROVEMENTS: diff --git a/plugins/provisioners/shell/config.rb b/plugins/provisioners/shell/config.rb index c88d1ec52..1e1db2270 100644 --- a/plugins/provisioners/shell/config.rb +++ b/plugins/provisioners/shell/config.rb @@ -1,3 +1,5 @@ +require 'uri' + module VagrantPlugins module Shell class Config < Vagrant.plugin("2", :config) @@ -33,8 +35,8 @@ module VagrantPlugins errors << I18n.t("vagrant.provisioners.shell.no_path_or_inline") end - # Validate the existence of a script to upload - if path + # If it is not an URL, we validate the existence of a script to upload + if path && ! remote? expanded_path = Pathname.new(path).expand_path(machine.env.root_path) if !expanded_path.file? errors << I18n.t("vagrant.provisioners.shell.path_invalid", @@ -54,6 +56,10 @@ module VagrantPlugins { "shell provisioner" => errors } end + + def remote? + path =~ URI::regexp(["ftp", "http", "https"]) + end end end end diff --git a/plugins/provisioners/shell/provisioner.rb b/plugins/provisioners/shell/provisioner.rb index be9323784..8c288ee27 100644 --- a/plugins/provisioners/shell/provisioner.rb +++ b/plugins/provisioners/shell/provisioner.rb @@ -1,6 +1,8 @@ require "pathname" require "tempfile" +require "vagrant/util/downloader" + module VagrantPlugins module Shell class Provisioner < Vagrant.plugin("2", :provisioner) @@ -52,7 +54,15 @@ module VagrantPlugins def with_script_file 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... root_path = @machine.env.root_path script = Pathname.new(config.path).expand_path(root_path).read