lib/vagrant-windows/monkey_patches/plugins/provisioners/puppet/provisioner/puppet.rb in vagrant-windows-1.3.0.pre.3 vs lib/vagrant-windows/monkey_patches/plugins/provisioners/puppet/provisioner/puppet.rb in vagrant-windows-1.3.0

- old
+ new

@@ -1,8 +1,9 @@ require "#{Vagrant::source_root}/plugins/provisioners/puppet/provisioner/puppet" require_relative '../../../../../windows_machine' require_relative '../../../../../helper' +require_relative '../../../../../errors' module VagrantPlugins module Puppet module Provisioner class Puppet < Vagrant.plugin("2", :provisioner) @@ -31,11 +32,11 @@ def run_puppet_apply_on_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) - options = [config.options].flatten + options = [@config.options].flatten module_paths = @module_paths.map { |_, to| to } if !@module_paths.empty? # Prepend the default module path module_paths.unshift("/ProgramData/PuppetLabs/puppet/etc/modules") @@ -56,32 +57,40 @@ options << @manifest_file options = options.join(" ") # Build up the custom facts if we have any facter = "" - if !config.facter.empty? + if !@config.facter.empty? facts = [] - config.facter.each do |key, value| + @config.facter.each do |key, value| facts << "$env:FACTER_#{key}='#{value}';" end facter = "#{facts.join(" ")} " end command = "#{facter} puppet apply #{options}" - if config.working_directory - command = "cd #{config.working_directory}; if($?) \{ #{command} \}" + if @config.working_directory + command = "cd #{@config.working_directory}; if($?) \{ #{command} \}" end @machine.env.ui.info I18n.t("vagrant.provisioners.puppet.running_puppet", :manifest => @manifest_file) - @machine.communicate.sudo(command) do |type, data| + exit_status = @machine.communicate.sudo(command, :error_check => false) do |type, data| if !data.empty? @machine.env.ui.info(data, :new_line => false, :prefix => false) end end + + # Puppet returns 0 or 2 for success with --detailed-exitcodes + if ![0,2].include?(exit_status) + raise ::VagrantWindows::Errors::WinRMExecutionError, + :shell => :powershell, + :command => command, + :message => "Puppet failed with an exit code of #{exit_status}" + end end def configure_on_windows(root_config) # Calculate the paths we're going to use based on the environment root_path = @machine.env.root_path @@ -90,10 +99,10 @@ @manifest_file = File.join(manifests_guest_path, @config.manifest_file) # Setup the module paths @module_paths = [] @expanded_module_paths.each_with_index do |path, i| - @module_paths << [path, File.join(config.temp_dir, "modules-#{i}")] + @module_paths << [path, File.join(@config.temp_dir, "modules-#{i}")] end @logger.debug("Syncing folders from puppet configure") @logger.debug("manifests_guest_path = #{manifests_guest_path}") @logger.debug("expanded_manifests_path = #{@expanded_manifests_path}")