Commit ac75d532 authored by Chris Bednarski's avatar Chris Bednarski

Merge pull request #2463 from mitchellh/b-2373

Make manifest_file work as either file.pp or a directory
parents dec1b65a 37c20e2b
...@@ -270,28 +270,43 @@ func (p *Provisioner) uploadManifests(ui packer.Ui, comm packer.Communicator) (s ...@@ -270,28 +270,43 @@ func (p *Provisioner) uploadManifests(ui packer.Ui, comm packer.Communicator) (s
return "", fmt.Errorf("Error creating manifests directory: %s", err) return "", fmt.Errorf("Error creating manifests directory: %s", err)
} }
// Upload the main manifest // NOTE! manifest_file may either be a directory or a file, as puppet apply
f, err := os.Open(p.config.ManifestFile) // now accepts either one.
fi, err := os.Stat(p.config.ManifestFile)
if err != nil { if err != nil {
return "", err return "", fmt.Errorf("Error inspecting manifest file: %s", err)
} }
defer f.Close()
manifestFilename := p.config.ManifestFile if fi.IsDir() {
if fi, err := os.Stat(p.config.ManifestFile); err != nil { // If manifest_file is a directory we'll upload the whole thing
return "", fmt.Errorf("Error inspecting manifest file: %s", err) ui.Message(fmt.Sprintf(
} else if !fi.IsDir() { "Uploading manifest directory from: %s", p.config.ManifestFile))
manifestFilename = filepath.Base(manifestFilename)
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 { } 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))
f, err := os.Open(p.config.ManifestFile)
if err != nil {
return "", err
} }
defer f.Close()
manifestFilename := filepath.Base(p.config.ManifestFile)
remoteManifestFile := fmt.Sprintf("%s/%s", remoteManifestsPath, manifestFilename) remoteManifestFile := fmt.Sprintf("%s/%s", remoteManifestsPath, manifestFilename)
if err := comm.Upload(remoteManifestFile, f, nil); err != nil { if err := comm.Upload(remoteManifestFile, f, nil); err != nil {
return "", err return "", err
} }
return remoteManifestFile, nil return remoteManifestFile, nil
}
} }
func (p *Provisioner) createDir(ui packer.Ui, comm packer.Communicator, dir string) error { func (p *Provisioner) createDir(ui packer.Ui, comm packer.Communicator, dir string) error {
......
...@@ -40,9 +40,12 @@ The reference of available configuration options is listed below. ...@@ -40,9 +40,12 @@ The reference of available configuration options is listed below.
Required parameters: Required parameters:
* `manifest_file` (string) - The manifest file for Puppet to use in order * `manifest_file` (string) - This is either a path to a puppet manifest (`.pp`
to compile and run a catalog. This file must exist on your local system file) _or_ a directory containing multiple manifests that puppet will apply
and will be uploaded to the remote machine. (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: Optional parameters:
...@@ -64,6 +67,10 @@ Optional parameters: ...@@ -64,6 +67,10 @@ Optional parameters:
the `manifest_file`. It is a separate directory that will be set as the `manifest_file`. It is a separate directory that will be set as
the "manifestdir" setting on Puppet. 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 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 * `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 directories on your local filesystem. These will be uploaded to the remote
machine. By default, this is empty. machine. By default, this is empty.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment