From 518ad704b7f161535f0a621ffff1229f2acf1152 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Thu, 16 Jul 2015 18:18:59 -0700 Subject: [PATCH 1/3] Added notes to warn against manifest_dir and note that manifest_file can be overloaded with a directory --- .../provisioners/puppet-masterless.html.markdown | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/website/source/docs/provisioners/puppet-masterless.html.markdown b/website/source/docs/provisioners/puppet-masterless.html.markdown index 6ba570add..4e7b5d1bc 100644 --- a/website/source/docs/provisioners/puppet-masterless.html.markdown +++ b/website/source/docs/provisioners/puppet-masterless.html.markdown @@ -40,9 +40,10 @@ The reference of available configuration options is listed below. Required parameters: -* `manifest_file` (string) - The manifest file for Puppet to use in order - to compile and run a catalog. This file must exist on your local system - and will be uploaded to the remote machine. +* `manifest_file` (string) - This is either a path to a puppet manifest (`.pp` + file) _or_ a directory containing multiple manifests that puppet will apply. + These file(s) must exist on your local system and will be uploaded to the + remote machine. Optional parameters: @@ -64,6 +65,11 @@ Optional parameters: the `manifest_file`. It is a separate directory that will be set as the "manifestdir" setting on Puppet. + ~> `manifest_dir` is passed to `puppet apply` as the `--manifestdir` option. + This option was deprecated in puppet 3.6, and is slated to be removed in + puppet 4.0. If you have multiple manifests you should simply use + `manifest_file` instead. + * `module_paths` (array of strings) - This is an array of paths to module directories on your local filesystem. These will be uploaded to the remote machine. By default, this is empty. From 56745e14f585904c340707c8a75657833d178266 Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Thu, 16 Jul 2015 19:15:16 -0700 Subject: [PATCH 2/3] manifest_file can now be a folder or file.pp and we will upload it correctly in either case --- provisioner/puppet-masterless/provisioner.go | 49 +++++++++++++------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/provisioner/puppet-masterless/provisioner.go b/provisioner/puppet-masterless/provisioner.go index 177cae23c..546224a54 100644 --- a/provisioner/puppet-masterless/provisioner.go +++ b/provisioner/puppet-masterless/provisioner.go @@ -270,28 +270,43 @@ func (p *Provisioner) uploadManifests(ui packer.Ui, comm packer.Communicator) (s return "", fmt.Errorf("Error creating manifests directory: %s", err) } - // Upload the main manifest - f, err := os.Open(p.config.ManifestFile) + // NOTE! manifest_file may either be a directory or a file, as puppet apply + // now accepts either one. + + fi, err := os.Stat(p.config.ManifestFile) if err != nil { - return "", err - } - defer f.Close() - - manifestFilename := p.config.ManifestFile - if fi, err := os.Stat(p.config.ManifestFile); err != nil { return "", fmt.Errorf("Error inspecting manifest file: %s", err) - } else if !fi.IsDir() { - manifestFilename = filepath.Base(manifestFilename) + } + + if fi.IsDir() { + // If manifest_file is a directory we'll upload the whole thing + ui.Message(fmt.Sprintf( + "Uploading manifest directory from: %s", p.config.ManifestFile)) + + remoteManifestDir := fmt.Sprintf("%s/manifests", p.config.StagingDir) + err := p.uploadDirectory(ui, comm, remoteManifestDir, p.config.ManifestFile) + if err != nil { + return "", fmt.Errorf("Error uploading manifest dir: %s", err) + } + return remoteManifestDir, nil } else { - ui.Say("WARNING: manifest_file should be a file. Use manifest_dir for directories") - } + // Otherwise manifest_file is a file and we'll upload it + ui.Message(fmt.Sprintf( + "Uploading manifest file from: %s", p.config.ManifestFile)) - remoteManifestFile := fmt.Sprintf("%s/%s", remoteManifestsPath, manifestFilename) - if err := comm.Upload(remoteManifestFile, f, nil); err != nil { - return "", err - } + f, err := os.Open(p.config.ManifestFile) + if err != nil { + return "", err + } + defer f.Close() - return remoteManifestFile, nil + manifestFilename := filepath.Base(p.config.ManifestFile) + remoteManifestFile := fmt.Sprintf("%s/%s", remoteManifestsPath, manifestFilename) + if err := comm.Upload(remoteManifestFile, f, nil); err != nil { + return "", err + } + return remoteManifestFile, nil + } } func (p *Provisioner) createDir(ui packer.Ui, comm packer.Communicator, dir string) error { From 37c20e2bf056fb221d0a0bee3093bb0990ed79fc Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Fri, 17 Jul 2015 12:06:20 -0700 Subject: [PATCH 3/3] Added links to puppet docs to clarify behavior of manifest with multiple files --- .../provisioners/puppet-masterless.html.markdown | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/website/source/docs/provisioners/puppet-masterless.html.markdown b/website/source/docs/provisioners/puppet-masterless.html.markdown index 4e7b5d1bc..8fd05e4f2 100644 --- a/website/source/docs/provisioners/puppet-masterless.html.markdown +++ b/website/source/docs/provisioners/puppet-masterless.html.markdown @@ -41,9 +41,11 @@ The reference of available configuration options is listed below. Required parameters: * `manifest_file` (string) - This is either a path to a puppet manifest (`.pp` - file) _or_ a directory containing multiple manifests that puppet will apply. - These file(s) must exist on your local system and will be uploaded to the - remote machine. + file) _or_ a directory containing multiple manifests that puppet will apply + (the ["main manifest"][1]). These file(s) must exist on your local system and + will be uploaded to the remote machine. + + [1]: https://docs.puppetlabs.com/puppet/latest/reference/dirs_manifest.html Optional parameters: @@ -66,9 +68,8 @@ Optional parameters: the "manifestdir" setting on Puppet. ~> `manifest_dir` is passed to `puppet apply` as the `--manifestdir` option. - This option was deprecated in puppet 3.6, and is slated to be removed in - puppet 4.0. If you have multiple manifests you should simply use - `manifest_file` instead. + This option was deprecated in puppet 3.6, and removed in puppet 4.0. If you + have multiple manifests you should use `manifest_file` instead. * `module_paths` (array of strings) - This is an array of paths to module directories on your local filesystem. These will be uploaded to the remote