provisioners/puppet: execute properly with WinRM

This commit is contained in:
Mitchell Hashimoto 2014-04-12 14:35:27 -07:00
parent 1a0cb9b4c1
commit bd51c16700
2 changed files with 38 additions and 8 deletions

View File

@ -158,11 +158,14 @@ module VagrantPlugins
:error_check => true, :error_check => true,
:error_class => Vagrant::Errors::VagrantError, :error_class => Vagrant::Errors::VagrantError,
:error_key => :ssh_bad_exit_status, :error_key => :ssh_bad_exit_status,
:good_exit => 0,
:command => command, :command => command,
:shell => nil, :shell => nil,
:sudo => false :sudo => false,
}.merge(opts || {}) }.merge(opts || {})
opts[:good_exit] = Array(opts[:good_exit])
# Connect via SSH and execute the command in the shell. # Connect via SSH and execute the command in the shell.
stdout = "" stdout = ""
stderr = "" stderr = ""
@ -179,7 +182,7 @@ module VagrantPlugins
end end
# Check for any errors # Check for any errors
if opts[:error_check] && exit_status != 0 if opts[:error_check] && !opts[:good_exit].include?(exit_status)
# The error classes expect the translation key to be _key, # The error classes expect the translation key to be _key,
# but that makes for an ugly configuration parameter, so we # but that makes for an ugly configuration parameter, so we
# set it here from `error_key` # set it here from `error_key`

View File

@ -101,11 +101,24 @@ module VagrantPlugins
end end
def run_puppet_apply def run_puppet_apply
if windows?
# This re-establishes our symbolic links if they were
# created between now and a reboot
@machine.communicate.execute(
"& net use a-non-existant-share",
error_check: false)
end
default_module_path = "/etc/puppet/modules"
if windows?
default_module_path = "/ProgramData/PuppetLabs/puppet/etc/modules"
end
options = [config.options].flatten options = [config.options].flatten
module_paths = @module_paths.map { |_, to| to } module_paths = @module_paths.map { |_, to| to }
if !@module_paths.empty? if !@module_paths.empty?
# Append the default module path # Append the default module path
module_paths << "/etc/puppet/modules" module_paths << default_module_path
# Add the command line switch to add the module path # Add the command line switch to add the module path
options << "--modulepath '#{module_paths.join(':')}'" options << "--modulepath '#{module_paths.join(':')}'"
@ -132,18 +145,28 @@ module VagrantPlugins
facts << "FACTER_#{key}='#{value}'" facts << "FACTER_#{key}='#{value}'"
end end
# If we're on Windows, we need to use the PowerShell style
if windows?
facts.map! { |v| "$env:#{v}" }
end
facter = "#{facts.join(" ")} " facter = "#{facts.join(" ")} "
end end
command = "#{facter}puppet apply #{options} || [ $? -eq 2 ]" command = "#{facter}puppet apply #{options}"
if config.working_directory if config.working_directory
command = "cd #{config.working_directory} && #{command}" if windows?
command = "cd #{config.working_directory}; if ($?) \{ #{command} \}"
else
command = "cd #{config.working_directory} && #{command}"
end
end end
@machine.env.ui.info I18n.t("vagrant.provisioners.puppet.running_puppet", @machine.env.ui.info(I18n.t(
:manifest => config.manifest_file) "vagrant.provisioners.puppet.running_puppet",
:manifest => config.manifest_file))
@machine.communicate.sudo(command) do |type, data| @machine.communicate.sudo(command, good_exit: [0,2]) do |type, data|
if !data.empty? if !data.empty?
@machine.env.ui.info(data, :new_line => false, :prefix => false) @machine.env.ui.info(data, :new_line => false, :prefix => false)
end end
@ -158,6 +181,10 @@ module VagrantPlugins
end end
end end
end end
def windows?
@machine.config.vm.communicator == :winrm
end
end end
end end
end end