From bd51c16700e31ad42f01641af843c3795005cdda Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 12 Apr 2014 14:35:27 -0700 Subject: [PATCH] provisioners/puppet: execute properly with WinRM --- plugins/communicators/ssh/communicator.rb | 7 +++- .../provisioners/puppet/provisioner/puppet.rb | 39 ++++++++++++++++--- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/plugins/communicators/ssh/communicator.rb b/plugins/communicators/ssh/communicator.rb index f13f055e0..daa6333b8 100644 --- a/plugins/communicators/ssh/communicator.rb +++ b/plugins/communicators/ssh/communicator.rb @@ -158,11 +158,14 @@ module VagrantPlugins :error_check => true, :error_class => Vagrant::Errors::VagrantError, :error_key => :ssh_bad_exit_status, + :good_exit => 0, :command => command, :shell => nil, - :sudo => false + :sudo => false, }.merge(opts || {}) + opts[:good_exit] = Array(opts[:good_exit]) + # Connect via SSH and execute the command in the shell. stdout = "" stderr = "" @@ -179,7 +182,7 @@ module VagrantPlugins end # 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, # but that makes for an ugly configuration parameter, so we # set it here from `error_key` diff --git a/plugins/provisioners/puppet/provisioner/puppet.rb b/plugins/provisioners/puppet/provisioner/puppet.rb index 7dd429f31..b950da451 100644 --- a/plugins/provisioners/puppet/provisioner/puppet.rb +++ b/plugins/provisioners/puppet/provisioner/puppet.rb @@ -101,11 +101,24 @@ module VagrantPlugins end 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 module_paths = @module_paths.map { |_, to| to } if !@module_paths.empty? # 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 options << "--modulepath '#{module_paths.join(':')}'" @@ -132,18 +145,28 @@ module VagrantPlugins facts << "FACTER_#{key}='#{value}'" end + # If we're on Windows, we need to use the PowerShell style + if windows? + facts.map! { |v| "$env:#{v}" } + end + facter = "#{facts.join(" ")} " end - command = "#{facter}puppet apply #{options} || [ $? -eq 2 ]" + command = "#{facter}puppet apply #{options}" 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 - @machine.env.ui.info I18n.t("vagrant.provisioners.puppet.running_puppet", - :manifest => config.manifest_file) + @machine.env.ui.info(I18n.t( + "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? @machine.env.ui.info(data, :new_line => false, :prefix => false) end @@ -158,6 +181,10 @@ module VagrantPlugins end end end + + def windows? + @machine.config.vm.communicator == :winrm + end end end end