diff --git a/CHANGELOG.md b/CHANGELOG.md index bc193e1de..7ec0e5639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ FEATURES: - Static IP can now be set on public networks. [GH-1745] - Add `Vagrant.has_plugin?` method for use in Vagrantfile to check if a plugin is installed. [GH-1736] + - 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