Merge pull request #2463 from mitchellh/b-2373

Make manifest_file work as either file.pp or a directory
This commit is contained in:
Chris Bednarski 2015-07-17 12:07:08 -07:00
commit ac75d5329e
2 changed files with 42 additions and 20 deletions

View File

@ -270,29 +270,44 @@ 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
// now accepts either one.
fi, err := os.Stat(p.config.ManifestFile)
if err != nil {
return "", fmt.Errorf("Error inspecting manifest file: %s", err)
}
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 {
// 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) f, err := os.Open(p.config.ManifestFile)
if err != nil { if err != nil {
return "", err return "", err
} }
defer f.Close() defer f.Close()
manifestFilename := p.config.ManifestFile manifestFilename := filepath.Base(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)
} else {
ui.Say("WARNING: manifest_file should be a file. Use manifest_dir for directories")
}
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 {
cmd := &packer.RemoteCmd{ cmd := &packer.RemoteCmd{

View File

@ -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:
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.