Add a binary_path option to the puppet provisioner to match the chef provisioner, and support new puppet 4 install location.

This commit is contained in:
Ben Hines 2015-04-11 23:35:25 -07:00
parent cf847e0410
commit 3a2a9a3b94
2 changed files with 26 additions and 8 deletions

View File

@ -2,6 +2,11 @@ module VagrantPlugins
module Puppet module Puppet
module Config 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 :facter
attr_accessor :hiera_config_path attr_accessor :hiera_config_path
attr_accessor :manifest_file attr_accessor :manifest_file
@ -17,6 +22,7 @@ module VagrantPlugins
def initialize def initialize
super super
@binary_path = UNSET_VALUE
@hiera_config_path = UNSET_VALUE @hiera_config_path = UNSET_VALUE
@manifest_file = UNSET_VALUE @manifest_file = UNSET_VALUE
@manifests_path = UNSET_VALUE @manifests_path = UNSET_VALUE
@ -88,6 +94,7 @@ module VagrantPlugins
@synced_folder_type = nil if @synced_folder_type == UNSET_VALUE @synced_folder_type = nil if @synced_folder_type == UNSET_VALUE
@temp_dir = "/tmp/vagrant-puppet" if @temp_dir == UNSET_VALUE @temp_dir = "/tmp/vagrant-puppet" if @temp_dir == UNSET_VALUE
@working_directory = nil if @working_directory == UNSET_VALUE @working_directory = nil if @working_directory == UNSET_VALUE
@binary_path = nil if @binary_path == UNSET_VALUE
end end
# Returns the module paths as an array of paths expanded relative to the # Returns the module paths as an array of paths expanded relative to the

View File

@ -103,7 +103,7 @@ module VagrantPlugins
verify_shared_folders(check) verify_shared_folders(check)
# Verify Puppet is installed and run it # Verify Puppet is installed and run it
verify_binary("puppet") verify_binary(puppet_binary_path("puppet"))
# Upload Hiera configuration if we have it # Upload Hiera configuration if we have it
@hiera_config_path = nil @hiera_config_path = nil
@ -138,13 +138,24 @@ module VagrantPlugins
end end
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) def verify_binary(binary)
puts "verify_binary: #{binary}"
if !machine.communicate.test("sh -c 'command -v #{binary}'")
@config.binary_path = "/opt/puppetlabs/bin"
@machine.communicate.sudo( @machine.communicate.sudo(
"which #{binary}", "test -x /opt/puppetlabs/bin/#{binary}",
error_class: PuppetError, error_class: PuppetError,
error_key: :not_detected, error_key: :not_detected,
binary: binary) binary: binary)
end end
end
def run_puppet_apply def run_puppet_apply
default_module_path = "/etc/puppet/modules" default_module_path = "/etc/puppet/modules"
@ -200,7 +211,7 @@ module VagrantPlugins
facter = "#{facts.join(" ")} " facter = "#{facts.join(" ")} "
end end
command = "#{facter}puppet apply #{options}" command = "#{facter} #{config.binary_path}/puppet apply #{options}"
if config.working_directory if config.working_directory
if windows? if windows?
command = "cd #{config.working_directory}; if (`$?) \{ #{command} \}" command = "cd #{config.working_directory}; if (`$?) \{ #{command} \}"