diff --git a/CHANGELOG.md b/CHANGELOG.md index d35ff0f2e..54b3910df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ IMPROVEMENTS: - provisioners/ansible: allow files for extra vars [GH-2366] - provisioners/puppet: client cert and private key can now be specified for the puppet server provisioner. [GH-902] + - provisioners/puppet: the manifests path can be in the VM. [GH-1805] - provisioners/shell: Added `keep_color` option to not automatically color output based on stdout/stderr. [GH-2505] - provisioners/shell: Arguments can now be an array of args. [GH-1949] diff --git a/plugins/provisioners/puppet/config/puppet.rb b/plugins/provisioners/puppet/config/puppet.rb index 46b3c9f0f..084254bd3 100644 --- a/plugins/provisioners/puppet/config/puppet.rb +++ b/plugins/provisioners/puppet/config/puppet.rb @@ -29,21 +29,24 @@ module VagrantPlugins def finalize! super + if @manifests_path == UNSET_VALUE + @manifests_path = [:host, "manifests"] + end + + if @manifests_path && !@manifests_path.is_a?(Array) + @manifests_path = [:host, @manifests_path] + end + + @manifests_path[0] = @manifests_path[0].to_sym + @hiera_config_path = nil if @hiera_config_path == UNSET_VALUE @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 @nfs = false if @nfs == UNSET_VALUE end - # Returns the manifests path expanded relative to the root path of the - # environment. - def expanded_manifests_path(root_path) - Pathname.new(manifests_path).expand_path(root_path) - end - # Returns the module paths as an array of paths expanded relative to the # root path. def expanded_module_paths(root_path) @@ -62,18 +65,20 @@ module VagrantPlugins errors = _detected_errors # Calculate the manifests and module paths based on env - this_expanded_manifests_path = expanded_manifests_path(machine.env.root_path) this_expanded_module_paths = expanded_module_paths(machine.env.root_path) # Manifests path/file validation - if !this_expanded_manifests_path.directory? - errors << I18n.t("vagrant.provisioners.puppet.manifests_path_missing", - :path => this_expanded_manifests_path) - else - expanded_manifest_file = this_expanded_manifests_path.join(manifest_file) - if !expanded_manifest_file.file? - errors << I18n.t("vagrant.provisioners.puppet.manifest_missing", - :manifest => expanded_manifest_file.to_s) + if manifests_path[0].to_sym == :host + expanded_path = File.expand_path(manifests_path[1], machine.env.root_path) + if expanded_path.directory? + errors << I18n.t("vagrant.provisioners.puppet.manifests_path_missing", + :path => this_expanded_manifests_path) + else + expanded_manifest_file = expanded_path.join(manifest_file) + if !expanded_manifest_file.file? + errors << I18n.t("vagrant.provisioners.puppet.manifest_missing", + :manifest => expanded_manifest_file.to_s) + end end end diff --git a/plugins/provisioners/puppet/provisioner/puppet.rb b/plugins/provisioners/puppet/provisioner/puppet.rb index b43a3d65b..86247e4e1 100644 --- a/plugins/provisioners/puppet/provisioner/puppet.rb +++ b/plugins/provisioners/puppet/provisioner/puppet.rb @@ -17,7 +17,6 @@ module VagrantPlugins def configure(root_config) # Calculate the paths we're going to use based on the environment 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 = File.join(manifests_guest_path, @config.manifest_file) @@ -32,8 +31,11 @@ module VagrantPlugins folder_opts[:owner] = "root" if !folder_opts[:nfs] # Share the manifests directory with the guest - root_config.vm.synced_folder( - @expanded_manifests_path, manifests_guest_path, folder_opts) + if @config.manifests_path[0].to_sym == :host + root_config.vm.synced_folder( + File.expand_path(@config.manifests_path[1], root_path), + manifests_guest_path, folder_opts) + end # Share the module paths @module_paths.each do |from, to| @@ -62,7 +64,8 @@ module VagrantPlugins # Upload Hiera configuration if we have it @hiera_config_path = nil if config.hiera_config_path - local_hiera_path = File.expand_path(config.hiera_config_path, @machine.env.root_path) + local_hiera_path = File.expand_path(config.hiera_config_path, + @machine.env.root_path) @hiera_config_path = File.join(config.temp_dir, "hiera.yaml") @machine.communicate.upload(local_hiera_path, @hiera_config_path) end @@ -71,7 +74,13 @@ module VagrantPlugins end def manifests_guest_path - File.join(config.temp_dir, "manifests") + if config.manifests_path[0] == :host + # The path is on the host, so point to where it is shared + File.join(config.temp_dir, "manifests") + else + # The path is on the VM, so just point directly to it + config.manifests_path[1] + end end def verify_binary(binary) diff --git a/website/docs/source/v2/provisioning/puppet_apply.html.md b/website/docs/source/v2/provisioning/puppet_apply.html.md index 61b0df844..57f74f4ce 100644 --- a/website/docs/source/v2/provisioning/puppet_apply.html.md +++ b/website/docs/source/v2/provisioning/puppet_apply.html.md @@ -64,6 +64,23 @@ end The path can be relative or absolute. If it is relative, it is relative to the project root. +You can also specify a manifests path that is on the remote machine +already, perhaps put in place by a shell provisioner. In this case, Vagrant +won't attempt to upload the manifests directory. To specify a remote +manifests path, use the following syntax: + +```ruby +Vagrant.configure("2") do |config| + config.vm.provision "puppet" do |puppet| + puppet.manifests_path = ["vm", "/path/to/manifests"] + puppet.manifest_file = "default.pp" + end +end +``` + +It is a somewhat odd syntax, but the tuple (two-element array) says +that the path is located in the "vm" at "/path/to/manifests". + ## Modules Vagrant also supports provisioning with [Puppet modules](http://docs.puppetlabs.com/guides/modules.html).