Add option to shell provisioner to reset communicator

This commit is contained in:
Chris Roberts 2018-11-12 15:34:10 -08:00
parent afc138478d
commit 29880ccd1f
2 changed files with 10 additions and 1 deletions

View File

@ -17,6 +17,7 @@ module VagrantPlugins
attr_accessor :sensitive attr_accessor :sensitive
attr_accessor :powershell_args attr_accessor :powershell_args
attr_accessor :powershell_elevated_interactive attr_accessor :powershell_elevated_interactive
attr_accessor :reset
def initialize def initialize
@args = UNSET_VALUE @args = UNSET_VALUE
@ -31,6 +32,7 @@ module VagrantPlugins
@keep_color = UNSET_VALUE @keep_color = UNSET_VALUE
@name = UNSET_VALUE @name = UNSET_VALUE
@sensitive = UNSET_VALUE @sensitive = UNSET_VALUE
@reset = UNSET_VALUE
@powershell_args = UNSET_VALUE @powershell_args = UNSET_VALUE
@powershell_elevated_interactive = UNSET_VALUE @powershell_elevated_interactive = UNSET_VALUE
end end
@ -48,6 +50,7 @@ module VagrantPlugins
@keep_color = false if @keep_color == UNSET_VALUE @keep_color = false if @keep_color == UNSET_VALUE
@name = nil if @name == UNSET_VALUE @name = nil if @name == UNSET_VALUE
@sensitive = false if @sensitive == UNSET_VALUE @sensitive = false if @sensitive == UNSET_VALUE
@reset = false if @reset == UNSET_VALUE
@powershell_args = "-ExecutionPolicy Bypass" if @powershell_args == UNSET_VALUE @powershell_args = "-ExecutionPolicy Bypass" if @powershell_args == UNSET_VALUE
@powershell_elevated_interactive = false if @powershell_elevated_interactive == UNSET_VALUE @powershell_elevated_interactive = false if @powershell_elevated_interactive == UNSET_VALUE
@ -68,7 +71,7 @@ module VagrantPlugins
# Validate that the parameters are properly set # Validate that the parameters are properly set
if path && inline if path && inline
errors << I18n.t("vagrant.provisioners.shell.path_and_inline_set") errors << I18n.t("vagrant.provisioners.shell.path_and_inline_set")
elsif !path && !inline elsif !path && !inline && !reset
errors << I18n.t("vagrant.provisioners.shell.no_path_or_inline") errors << I18n.t("vagrant.provisioners.shell.no_path_or_inline")
end end

View File

@ -18,6 +18,10 @@ module VagrantPlugins
args = " #{args.join(" ")}" args = " #{args.join(" ")}"
end end
# In cases where the connection is just being reset
# bail out before attempting to do any actual provisioning
return if !config.path && !config.inline
case @machine.config.vm.communicator case @machine.config.vm.communicator
when :winrm when :winrm
provision_winrm(args) provision_winrm(args)
@ -26,6 +30,8 @@ module VagrantPlugins
else else
provision_ssh(args) provision_ssh(args)
end end
ensure
@machine.communicate.reset! if config.reset
end end
protected protected