diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c819c479..a8ac5588e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## 1.2.3 (unreleased) +FEATURES: + + - Added a `working_directory` configuration option to the Puppet apply + provisioner so you can specify the working directory when `puppet` is + called, making it friendly to Hiera data and such. [GH-1670] + IMPROVEMENTS: - Setting hostnames works properly on SmartOS. [GH-1672] diff --git a/plugins/provisioners/puppet/config/puppet.rb b/plugins/provisioners/puppet/config/puppet.rb index 9febf3e0e..9c1a39389 100644 --- a/plugins/provisioners/puppet/config/puppet.rb +++ b/plugins/provisioners/puppet/config/puppet.rb @@ -2,18 +2,35 @@ module VagrantPlugins module Puppet module Config class Puppet < Vagrant.plugin("2", :config) + attr_accessor :facter attr_accessor :manifest_file attr_accessor :manifests_path attr_accessor :module_path - attr_accessor :pp_path attr_accessor :options - attr_accessor :facter + attr_accessor :temp_dir + attr_accessor :working_directory - def manifest_file; @manifest_file || "default.pp"; end - def manifests_path; @manifests_path || "manifests"; end - def pp_path; @pp_path || "/tmp/vagrant-puppet"; end - def options; @options ||= []; end - def facter; @facter ||= {}; end + def initialize + super + + @manifest_file = UNSET_VALUE + @manifests_path = UNSET_VALUE + @module_path = UNSET_VALUE + @options = [] + @facter = {} + @temp_dir = UNSET_VALUE + @working_directory = UNSET_VALUE + end + + def finalize! + super + + @manifest_file = "default.pp" if @manifest_file == UNSET_VALUE + @manifests_path = "manifests" if @manifests_path == UNSET_VALUE + @module_path = nil if @module_path == UNSET_VALUE + @temp_dir = "/tmp/vagrant-puppet" if @temp_dir == UNSET_VALUE + @working_directory = nil if @working_directory == UNSET_VALUE + end # Returns the manifests path expanded relative to the root path of the # environment. diff --git a/plugins/provisioners/puppet/provisioner/puppet.rb b/plugins/provisioners/puppet/provisioner/puppet.rb index 386ee5263..57ea75d88 100644 --- a/plugins/provisioners/puppet/provisioner/puppet.rb +++ b/plugins/provisioners/puppet/provisioner/puppet.rb @@ -19,12 +19,12 @@ module VagrantPlugins root_path = @machine.env.root_path @expanded_manifests_path = @config.expanded_manifests_path(root_path) @expanded_module_paths = @config.expanded_module_paths(root_path) - @manifest_file = @config.manifest_file + @manifest_file = File.join(@expanded_manifests_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.pp_path, "modules-#{i}")] + @module_paths << [path, File.join(config.temp_dir, "modules-#{i}")] end # Share the manifests directory with the guest @@ -56,7 +56,7 @@ module VagrantPlugins end def manifests_guest_path - File.join(config.pp_path, "manifests") + File.join(config.temp_dir, "manifests") end def verify_binary(binary) @@ -92,10 +92,13 @@ module VagrantPlugins facter = "#{facts.join(" ")} " end - command = "cd #{manifests_guest_path} && #{facter}puppet apply #{options} --detailed-exitcodes || [ $? -eq 2 ]" + command = "#{facter}puppet apply #{options} --detailed-exitcodes || [ $? -eq 2 ]" + if config.working_directory + command = "cd #{config.working_directory} && #{command}" + end @machine.env.ui.info I18n.t("vagrant.provisioners.puppet.running_puppet", - :manifest => @manifest_file) + :manifest => config.manifest_file) @machine.communicate.sudo(command) do |type, data| data.chomp!