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
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
return "", fmt.Errorf("Error inspecting manifest file: %s", 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 {
......
......@@ -40,9 +40,12 @@ 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
(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:
......@@ -64,6 +67,10 @@ 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 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
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