diff --git a/plugins/provisioners/puppet/config/puppet.rb b/plugins/provisioners/puppet/config/puppet.rb index eccd5f780..0e4fabaeb 100644 --- a/plugins/provisioners/puppet/config/puppet.rb +++ b/plugins/provisioners/puppet/config/puppet.rb @@ -1,7 +1,12 @@ module VagrantPlugins module Puppet module Config - class Puppet < Vagrant.plugin("2", :config) + class Puppet < Vagrant.plugin("2", :config) + + # The path to Puppet's bin/ directory. + # @return [String] + attr_accessor :binary_path + attr_accessor :facter attr_accessor :hiera_config_path attr_accessor :manifest_file @@ -17,6 +22,7 @@ module VagrantPlugins def initialize super + @binary_path = UNSET_VALUE @hiera_config_path = UNSET_VALUE @manifest_file = UNSET_VALUE @manifests_path = UNSET_VALUE @@ -88,6 +94,7 @@ module VagrantPlugins @synced_folder_type = nil if @synced_folder_type == UNSET_VALUE @temp_dir = "/tmp/vagrant-puppet" if @temp_dir == UNSET_VALUE @working_directory = nil if @working_directory == UNSET_VALUE + @binary_path = nil if @binary_path == UNSET_VALUE end # Returns the module paths as an array of paths expanded relative to the diff --git a/plugins/provisioners/puppet/provisioner/puppet.rb b/plugins/provisioners/puppet/provisioner/puppet.rb index 66461af5e..0cd5e8033 100644 --- a/plugins/provisioners/puppet/provisioner/puppet.rb +++ b/plugins/provisioners/puppet/provisioner/puppet.rb @@ -103,7 +103,7 @@ module VagrantPlugins verify_shared_folders(check) # Verify Puppet is installed and run it - verify_binary("puppet") + verify_binary(puppet_binary_path("puppet")) # Upload Hiera configuration if we have it @hiera_config_path = nil @@ -138,12 +138,23 @@ module VagrantPlugins end end + # Returns the path to the Puppet binary, taking into account the + # `binary_path` configuration option. + def puppet_binary_path(binary) + return binary if !@config.binary_path + return File.join(@config.binary_path, binary) + end + def verify_binary(binary) - @machine.communicate.sudo( - "which #{binary}", - error_class: PuppetError, - error_key: :not_detected, - binary: binary) + puts "verify_binary: #{binary}" + if !machine.communicate.test("sh -c 'command -v #{binary}'") + @config.binary_path = "/opt/puppetlabs/bin" + @machine.communicate.sudo( + "test -x /opt/puppetlabs/bin/#{binary}", + error_class: PuppetError, + error_key: :not_detected, + binary: binary) + end end def run_puppet_apply @@ -200,7 +211,7 @@ module VagrantPlugins facter = "#{facts.join(" ")} " end - command = "#{facter}puppet apply #{options}" + command = "#{facter} #{config.binary_path}/puppet apply #{options}" if config.working_directory if windows? command = "cd #{config.working_directory}; if (`$?) \{ #{command} \}"