Merge pull request #10943 from hashicorp/extract-puppet

Extract Puppet plugins
This commit is contained in:
Megan Marsh 2021-04-20 13:44:20 -07:00 committed by GitHub
commit dc63b9a7a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 395 additions and 1171 deletions

View File

@ -54,8 +54,6 @@ import (
fileprovisioner "github.com/hashicorp/packer/provisioner/file"
inspecprovisioner "github.com/hashicorp/packer/provisioner/inspec"
powershellprovisioner "github.com/hashicorp/packer/provisioner/powershell"
puppetmasterlessprovisioner "github.com/hashicorp/packer/provisioner/puppet-masterless"
puppetserverprovisioner "github.com/hashicorp/packer/provisioner/puppet-server"
saltmasterlessprovisioner "github.com/hashicorp/packer/provisioner/salt-masterless"
shellprovisioner "github.com/hashicorp/packer/provisioner/shell"
shelllocalprovisioner "github.com/hashicorp/packer/provisioner/shell-local"
@ -102,8 +100,6 @@ var Provisioners = map[string]packersdk.Provisioner{
"file": new(fileprovisioner.Provisioner),
"inspec": new(inspecprovisioner.Provisioner),
"powershell": new(powershellprovisioner.Provisioner),
"puppet-masterless": new(puppetmasterlessprovisioner.Provisioner),
"puppet-server": new(puppetserverprovisioner.Provisioner),
"salt-masterless": new(saltmasterlessprovisioner.Provisioner),
"shell": new(shellprovisioner.Provisioner),
"shell-local": new(shelllocalprovisioner.Provisioner),

View File

@ -39,6 +39,8 @@ import (
parallelspvmbuilder "github.com/hashicorp/packer-plugin-parallels/builder/parallels/pvm"
proxmoxclone "github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/clone"
proxmoxiso "github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/iso"
puppetmasterlessprovisioner "github.com/hashicorp/packer-plugin-puppet/provisioner/puppet-masterless"
puppetserverprovisioner "github.com/hashicorp/packer-plugin-puppet/provisioner/puppet-server"
qemubuilder "github.com/hashicorp/packer-plugin-qemu/builder/qemu"
scalewaybuilder "github.com/hashicorp/packer-plugin-scaleway/builder/scaleway"
virtualboxisobuilder "github.com/hashicorp/packer-plugin-virtualbox/builder/virtualbox/iso"
@ -95,10 +97,12 @@ var VendoredBuilders = map[string]packersdk.Builder{
// VendoredProvisioners are provisioner components that were once bundled with the
// Packer core, but are now being imported from their counterpart plugin repos
var VendoredProvisioners = map[string]packersdk.Provisioner{
"ansible": new(ansibleprovisioner.Provisioner),
"ansible-local": new(ansiblelocalprovisioner.Provisioner),
"chef-client": new(chefclientprovisioner.Provisioner),
"chef-solo": new(chefsoloprovisioner.Provisioner),
"ansible": new(ansibleprovisioner.Provisioner),
"ansible-local": new(ansiblelocalprovisioner.Provisioner),
"chef-client": new(chefclientprovisioner.Provisioner),
"chef-solo": new(chefsoloprovisioner.Provisioner),
"puppet-masterless": new(puppetmasterlessprovisioner.Provisioner),
"puppet-server": new(puppetserverprovisioner.Provisioner),
}
// VendoredPostProcessors are post-processor components that were once bundled with the

1
go.mod
View File

@ -48,6 +48,7 @@ require (
github.com/hashicorp/packer-plugin-outscale v0.0.1
github.com/hashicorp/packer-plugin-parallels v0.0.1
github.com/hashicorp/packer-plugin-proxmox v0.0.2
github.com/hashicorp/packer-plugin-puppet v0.0.1
github.com/hashicorp/packer-plugin-qemu v0.0.1
github.com/hashicorp/packer-plugin-scaleway v0.0.1
github.com/hashicorp/packer-plugin-sdk v0.2.0

2
go.sum
View File

@ -484,6 +484,8 @@ github.com/hashicorp/packer-plugin-parallels v0.0.1 h1:fcaaiGWdU1+X4IGadXdUhJ2si
github.com/hashicorp/packer-plugin-parallels v0.0.1/go.mod h1:FGNtZ7XFBr3IYuj7uvJtSaNnyhAwe457zP464m06+20=
github.com/hashicorp/packer-plugin-proxmox v0.0.2 h1:x6QW7PeKh+IJymPEt3QdpBhSRi5vqXb8qTWv7rMLuns=
github.com/hashicorp/packer-plugin-proxmox v0.0.2/go.mod h1:3URutEWX1yy10qcHNJncS4OMpZknA1FyvlrfL+5usYk=
github.com/hashicorp/packer-plugin-puppet v0.0.1 h1:avOlJB2suArgqo3gn/JipLtHY0TVuTcweYA3GxVceyY=
github.com/hashicorp/packer-plugin-puppet v0.0.1/go.mod h1:HgRpw6hXYykjyceBRbrRvBT7vSU7Ofo5HIfFRMCehQc=
github.com/hashicorp/packer-plugin-qemu v0.0.1 h1:yGnmWf4Z+ZmOJXJF6w23V2KChtTCiPHsFnfg7+LRu74=
github.com/hashicorp/packer-plugin-qemu v0.0.1/go.mod h1:8Q/LCjO7oplLcLe1KLdEt7rq94h42Di6Lab2DTLNwVg=
github.com/hashicorp/packer-plugin-scaleway v0.0.1 h1:FSq76WuMJNKwCvF77v06EpuLe/AJP3sG5/YrfL41kcw=

View File

@ -1,528 +0,0 @@
package puppetmasterless
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"testing"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
"github.com/hashicorp/packer/packer"
"github.com/stretchr/testify/assert"
)
func testConfig() (config map[string]interface{}, tf *os.File) {
tf, err := ioutil.TempFile("", "packer")
if err != nil {
panic(err)
}
config = map[string]interface{}{
"manifest_file": tf.Name(),
}
return config, tf
}
func TestProvisioner_Impl(t *testing.T) {
var raw interface{}
raw = &Provisioner{}
if _, ok := raw.(packersdk.Provisioner); !ok {
t.Fatalf("must be a Provisioner")
}
}
func TestGuestOSConfig_empty_unix(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Execute Puppet
p.config.ctx.Data = &ExecuteTemplate{
ManifestFile: "/r/m/f",
PuppetBinDir: p.config.PuppetBinDir,
Sudo: !p.config.PreventSudo,
WorkingDir: p.config.WorkingDir,
}
log.Println(p.config.ExecuteCommand)
command, err := interpolate.Render(p.config.ExecuteCommand, &p.config.ctx)
if err != nil {
t.Fatalf("err: %s", err)
}
expected := "cd /tmp/packer-puppet-masterless && " +
"sudo -E puppet apply --detailed-exitcodes /r/m/f"
assert.Equal(t, expected, command)
}
func TestGuestOSConfig_full_unix(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
facterVars := []string{
fmt.Sprintf(p.guestOSTypeConfig.facterVarsFmt, "lhs", "rhs"),
fmt.Sprintf(p.guestOSTypeConfig.facterVarsFmt, "foo", "bar"),
}
modulePaths := []string{"/m/p", "/a/b"}
// Execute Puppet
p.config.ctx.Data = &ExecuteTemplate{
FacterVars: strings.Join(facterVars, p.guestOSTypeConfig.facterVarsJoiner),
HieraConfigPath: "/h/c/p",
ManifestDir: "/r/m/d",
ManifestFile: "/r/m/f",
ModulePath: strings.Join(modulePaths, p.guestOSTypeConfig.modulePathJoiner),
PuppetBinDir: p.config.PuppetBinDir,
Sudo: !p.config.PreventSudo,
WorkingDir: p.config.WorkingDir,
ExtraArguments: strings.Join(p.config.ExtraArguments, " "),
}
command, err := interpolate.Render(p.config.ExecuteCommand, &p.config.ctx)
if err != nil {
t.Fatalf("err: %s", err)
}
expected := "cd /tmp/packer-puppet-masterless && FACTER_lhs='rhs' FACTER_foo='bar' " +
"sudo -E puppet apply " +
"--detailed-exitcodes --modulepath='/m/p:/a/b' --hiera_config='/h/c/p' " +
"--manifestdir='/r/m/d' /r/m/f"
assert.Equal(t, expected, command)
}
func TestGuestOSConfig_empty_windows(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
config["guest_os_type"] = "windows"
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Execute Puppet
p.config.ctx.Data = &ExecuteTemplate{
ManifestFile: "/r/m/f",
PuppetBinDir: p.config.PuppetBinDir,
Sudo: !p.config.PreventSudo,
WorkingDir: p.config.WorkingDir,
}
log.Println(p.config.ExecuteCommand)
command, err := interpolate.Render(p.config.ExecuteCommand, &p.config.ctx)
if err != nil {
t.Fatalf("err: %s", err)
}
expected := "cd " + filepath.ToSlash(os.Getenv("SYSTEMROOT")) + "/Temp/packer-puppet-masterless && puppet apply --detailed-exitcodes /r/m/f"
assert.Equal(t, expected, command)
}
func TestGuestOSConfig_full_windows(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
config["guest_os_type"] = "windows"
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
facterVars := []string{
fmt.Sprintf(p.guestOSTypeConfig.facterVarsFmt, "lhs", "rhs"),
fmt.Sprintf(p.guestOSTypeConfig.facterVarsFmt, "foo", "bar"),
}
modulePaths := []string{"/m/p", "/a/b"}
// Execute Puppet
p.config.ctx.Data = &ExecuteTemplate{
FacterVars: strings.Join(facterVars, p.guestOSTypeConfig.facterVarsJoiner),
HieraConfigPath: "/h/c/p",
ManifestDir: "/r/m/d",
ManifestFile: "/r/m/f",
ModulePath: strings.Join(modulePaths, p.guestOSTypeConfig.modulePathJoiner),
PuppetBinDir: p.config.PuppetBinDir,
Sudo: !p.config.PreventSudo,
WorkingDir: p.config.WorkingDir,
ExtraArguments: strings.Join(p.config.ExtraArguments, " "),
}
command, err := interpolate.Render(p.config.ExecuteCommand, &p.config.ctx)
if err != nil {
t.Fatalf("err: %s", err)
}
expected := "cd " + filepath.ToSlash(os.Getenv("SYSTEMROOT")) + "/Temp/packer-puppet-masterless && " +
"SET \"FACTER_lhs=rhs\" & SET \"FACTER_foo=bar\" && " +
"puppet apply --detailed-exitcodes --modulepath='/m/p;/a/b' --hiera_config='/h/c/p' " +
"--manifestdir='/r/m/d' /r/m/f"
assert.Equal(t, expected, command)
}
func TestProvisionerPrepare_puppetBinDir(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
delete(config, "puppet_bin_dir")
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Test with a good one
tf, err := ioutil.TempFile("", "packer")
if err != nil {
t.Fatalf("error tempfile: %s", err)
}
defer os.Remove(tf.Name())
config["puppet_bin_dir"] = tf.Name()
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
}
func TestProvisionerPrepare_hieraConfigPath(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
delete(config, "hiera_config_path")
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Test with a good one
tf, err := ioutil.TempFile("", "packer")
if err != nil {
t.Fatalf("error tempfile: %s", err)
}
defer os.Remove(tf.Name())
config["hiera_config_path"] = tf.Name()
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
}
func TestProvisionerPrepare_manifestFile(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
delete(config, "manifest_file")
p := new(Provisioner)
err := p.Prepare(config)
if err == nil {
t.Fatal("should be an error")
}
// Test with a good one
tf, err := ioutil.TempFile("", "packer")
if err != nil {
t.Fatalf("error tempfile: %s", err)
}
defer os.Remove(tf.Name())
config["manifest_file"] = tf.Name()
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
}
func TestProvisionerPrepare_manifestDir(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
delete(config, "manifestdir")
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Test with a good one
td, err := ioutil.TempDir("", "packer")
if err != nil {
t.Fatalf("error: %s", err)
}
defer os.RemoveAll(td)
config["manifest_dir"] = td
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
}
func TestProvisionerPrepare_modulePaths(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
delete(config, "module_paths")
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Test with bad paths
config["module_paths"] = []string{"i-should-not-exist"}
p = new(Provisioner)
err = p.Prepare(config)
if err == nil {
t.Fatal("should be an error")
}
// Test with a good one
td, err := ioutil.TempDir("", "packer")
if err != nil {
t.Fatalf("error: %s", err)
}
defer os.RemoveAll(td)
config["module_paths"] = []string{td}
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
}
func TestProvisionerPrepare_facterFacts(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
delete(config, "facter")
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Test with malformed fact
config["facter"] = "fact=stringified"
p = new(Provisioner)
err = p.Prepare(config)
if err == nil {
t.Fatal("should be an error")
}
// Test with a good one
td, err := ioutil.TempDir("", "packer")
if err != nil {
t.Fatalf("error: %s", err)
}
defer os.RemoveAll(td)
facts := make(map[string]string)
facts["fact_name"] = "fact_value"
config["facter"] = facts
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Make sure the default facts are present
delete(config, "facter")
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
if p.config.Facter == nil {
t.Fatalf("err: Default facts are not set in the Puppet provisioner!")
}
if _, ok := p.config.Facter["packer_build_name"]; !ok {
t.Fatalf("err: packer_build_name fact not set in the Puppet provisioner!")
}
if _, ok := p.config.Facter["packer_builder_type"]; !ok {
t.Fatalf("err: packer_builder_type fact not set in the Puppet provisioner!")
}
}
func TestProvisionerPrepare_extraArguments(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
// Test with missing parameter
delete(config, "extra_arguments")
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Test with malformed value
config["extra_arguments"] = "{{}}"
p = new(Provisioner)
err = p.Prepare(config)
if err == nil {
t.Fatal("should be an error")
}
// Test with valid values
config["extra_arguments"] = []string{
"arg",
}
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
}
func TestProvisionerPrepare_stagingDir(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
delete(config, "staging_directory")
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Make sure the default staging directory is correct
if p.config.StagingDir != "/tmp/packer-puppet-masterless" {
t.Fatalf("err: Default staging_directory is not set in the Puppet provisioner!")
}
// Make sure default staging directory can be overridden
config["staging_directory"] = "/tmp/override"
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
if p.config.StagingDir != "/tmp/override" {
t.Fatalf("err: Overridden staging_directory is not set correctly in the Puppet provisioner!")
}
}
func TestProvisionerPrepare_workingDir(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
delete(config, "working_directory")
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Make sure default working dir and staging dir are the same
if p.config.WorkingDir != p.config.StagingDir {
t.Fatalf("err: Default working_directory is not set to the same value as default staging_directory in the Puppet provisioner!")
}
// Make sure the default working directory is correct
if p.config.WorkingDir != "/tmp/packer-puppet-masterless" {
t.Fatalf("err: Default working_directory is not set in the Puppet provisioner!")
}
// Make sure default working directory can be overridden
config["working_directory"] = "/tmp/override"
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
if p.config.WorkingDir != "/tmp/override" {
t.Fatalf("err: Overridden working_directory is not set correctly in the Puppet provisioner!")
}
}
func TestProvisionerProvision_extraArguments(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
ui := &packer.MachineReadableUi{
Writer: ioutil.Discard,
}
comm := new(packersdk.MockCommunicator)
extraArguments := []string{
"--some-arg=yup",
"--some-other-arg",
}
config["extra_arguments"] = extraArguments
// Test with valid values
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
if err != nil {
t.Fatalf("err: %s", err)
}
expectedArgs := strings.Join(extraArguments, " ")
if !strings.Contains(comm.StartCmd.Command, expectedArgs) {
t.Fatalf("Command %q doesn't contain the expected arguments %q", comm.StartCmd.Command, expectedArgs)
}
// Test with missing parameter
delete(config, "extra_arguments")
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
err = p.Provision(context.Background(), ui, comm, make(map[string]interface{}))
if err != nil {
t.Fatalf("err: %s", err)
}
// Check the expected `extra_arguments` position for an empty value
splitCommand := strings.Split(comm.StartCmd.Command, " ")
if "" == splitCommand[len(splitCommand)-2] {
t.Fatalf("Command %q contains an extra-space which may cause arg parsing issues", comm.StartCmd.Command)
}
}

View File

@ -1,13 +0,0 @@
package version
import (
"github.com/hashicorp/packer-plugin-sdk/version"
packerVersion "github.com/hashicorp/packer/version"
)
var PuppetMasterlessPluginVersion *version.PluginVersion
func init() {
PuppetMasterlessPluginVersion = version.InitializePluginVersion(
packerVersion.Version, packerVersion.VersionPrerelease)
}

View File

@ -1,227 +0,0 @@
package puppetserver
import (
"io/ioutil"
"os"
"testing"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
)
func testConfig() (config map[string]interface{}, tf *os.File) {
tf, err := ioutil.TempFile("", "packer")
if err != nil {
panic(err)
}
config = map[string]interface{}{
"puppet_server": tf.Name(),
}
return config, tf
}
func TestProvisioner_Impl(t *testing.T) {
var raw interface{}
raw = &Provisioner{}
if _, ok := raw.(packersdk.Provisioner); !ok {
t.Fatalf("must be a Provisioner")
}
}
func TestProvisionerPrepare_puppetBinDir(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
delete(config, "puppet_bin_dir")
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Test with a good one
tf, err := ioutil.TempFile("", "packer")
if err != nil {
t.Fatalf("error tempfile: %s", err)
}
defer os.Remove(tf.Name())
config["puppet_bin_dir"] = tf.Name()
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
}
func TestProvisionerPrepare_clientPrivateKeyPath(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
delete(config, "client_private_key_path")
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Test with bad paths
config["client_private_key_path"] = "i-should-not-exist"
p = new(Provisioner)
err = p.Prepare(config)
if err == nil {
t.Fatal("should be an error")
}
// Test with a good one
td, err := ioutil.TempDir("", "packer")
if err != nil {
t.Fatalf("error: %s", err)
}
defer os.RemoveAll(td)
config["client_private_key_path"] = td
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
}
func TestProvisionerPrepare_clientCertPath(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
delete(config, "client_cert_path")
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Test with bad paths
config["client_cert_path"] = "i-should-not-exist"
p = new(Provisioner)
err = p.Prepare(config)
if err == nil {
t.Fatal("should be an error")
}
// Test with a good one
td, err := ioutil.TempDir("", "packer")
if err != nil {
t.Fatalf("error: %s", err)
}
defer os.RemoveAll(td)
config["client_cert_path"] = td
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
}
func TestProvisionerPrepare_executeCommand(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
delete(config, "execute_command")
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
}
func TestProvisionerPrepare_facterFacts(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
delete(config, "facter")
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Test with malformed fact
config["facter"] = "fact=stringified"
p = new(Provisioner)
err = p.Prepare(config)
if err == nil {
t.Fatal("should be an error")
}
// Test with a good one
td, err := ioutil.TempDir("", "packer")
if err != nil {
t.Fatalf("error: %s", err)
}
defer os.RemoveAll(td)
facts := make(map[string]string)
facts["fact_name"] = "fact_value"
config["facter"] = facts
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Make sure the default facts are present
delete(config, "facter")
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
if p.config.Facter == nil {
t.Fatalf("err: Default facts are not set in the Puppet provisioner!")
}
if _, ok := p.config.Facter["packer_build_name"]; !ok {
t.Fatalf("err: packer_build_name fact not set in the Puppet provisioner!")
}
if _, ok := p.config.Facter["packer_builder_type"]; !ok {
t.Fatalf("err: packer_builder_type fact not set in the Puppet provisioner!")
}
}
func TestProvisionerPrepare_stagingDir(t *testing.T) {
config, tempfile := testConfig()
defer os.Remove(tempfile.Name())
defer tempfile.Close()
delete(config, "staging_dir")
p := new(Provisioner)
err := p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
// Make sure the default staging directory is correct
if p.config.StagingDir != "/tmp/packer-puppet-server" {
t.Fatalf("err: Default staging_dir is not set in the Puppet provisioner!")
}
// Make sure default staging directory can be overridden
config["staging_dir"] = "/tmp/override"
p = new(Provisioner)
err = p.Prepare(config)
if err != nil {
t.Fatalf("err: %s", err)
}
if p.config.StagingDir != "/tmp/override" {
t.Fatalf("err: Overridden staging_dir is not set correctly in the Puppet provisioner!")
}
}

View File

@ -1,13 +0,0 @@
package version
import (
"github.com/hashicorp/packer-plugin-sdk/version"
packerVersion "github.com/hashicorp/packer/version"
)
var PuppetServerPluginVersion *version.PluginVersion
func init() {
PuppetServerPluginVersion = version.InitializePluginVersion(
packerVersion.Version, packerVersion.VersionPrerelease)
}

View File

@ -0,0 +1,373 @@
Mozilla Public License Version 2.0
==================================
1. Definitions
--------------
1.1. "Contributor"
means each individual or legal entity that creates, contributes to
the creation of, or owns Covered Software.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used
by a Contributor and that particular Contributor's Contribution.
1.3. "Contribution"
means Covered Software of a particular Contributor.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached
the notice in Exhibit A, the Executable Form of such Source Code
Form, and Modifications of such Source Code Form, in each case
including portions thereof.
1.5. "Incompatible With Secondary Licenses"
means
(a) that the initial Contributor has attached the notice described
in Exhibit B to the Covered Software; or
(b) that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the
terms of a Secondary License.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in
a separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible,
whether at the time of the initial grant or subsequently, any and
all of the rights conveyed by this License.
1.10. "Modifications"
means any of the following:
(a) any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered
Software; or
(b) any new file in Source Code Form that contains any Covered
Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the
License, by the making, using, selling, offering for sale, having
made, import, or transfer of either its Contributions or its
Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU
Lesser General Public License, Version 2.1, the GNU Affero General
Public License, Version 3.0, or any later versions of those
licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that
controls, is controlled by, or is under common control with You. For
purposes of this definition, "control" means (a) the power, direct
or indirect, to cause the direction or management of such entity,
whether by contract or otherwise, or (b) ownership of more than
fifty percent (50%) of the outstanding shares or beneficial
ownership of such entity.
2. License Grants and Conditions
--------------------------------
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
(a) under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
(b) under Patent Claims of such Contributor to make, use, sell, offer
for sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
(a) for any code that a Contributor has removed from Covered Software;
or
(b) for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
(c) under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights
to grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
in Section 2.1.
3. Responsibilities
-------------------
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
(a) such Covered Software must also be made available in Source Code
Form, as described in Section 3.1, and You must inform recipients of
the Executable Form how they can obtain a copy of such Source Code
Form by reasonable means in a timely manner, at a charge no more
than the cost of distribution to the recipient; and
(b) You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter
the recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty,
or limitations of liability) contained within the Source Code Form of
the Covered Software, except that You may alter any license notices to
the extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
---------------------------------------------------
If it is impossible for You to comply with any of the terms of this
License with respect to some or all of the Covered Software due to
statute, judicial order, or regulation then You must: (a) comply with
the terms of this License to the maximum extent possible; and (b)
describe the limitations and the code they affect. Such description must
be placed in a text file included with all distributions of the Covered
Software under this License. Except to the extent prohibited by statute
or regulation, such description must be sufficiently detailed for a
recipient of ordinary skill to be able to understand it.
5. Termination
--------------
5.1. The rights granted under this License will terminate automatically
if You fail to comply with any of its terms. However, if You become
compliant, then the rights granted under this License from a particular
Contributor are reinstated (a) provisionally, unless and until such
Contributor explicitly and finally terminates Your grants, and (b) on an
ongoing basis, if such Contributor fails to notify You of the
non-compliance by some reasonable means prior to 60 days after You have
come back into compliance. Moreover, Your grants from a particular
Contributor are reinstated on an ongoing basis if such Contributor
notifies You of the non-compliance by some reasonable means, this is the
first time You have received notice of non-compliance with this License
from such Contributor, and You become compliant prior to 30 days after
Your receipt of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
end user license agreements (excluding distributors and resellers) which
have been validly granted by You or Your distributors under this License
prior to termination shall survive termination.
************************************************************************
* *
* 6. Disclaimer of Warranty *
* ------------------------- *
* *
* Covered Software is provided under this License on an "as is" *
* basis, without warranty of any kind, either expressed, implied, or *
* statutory, including, without limitation, warranties that the *
* Covered Software is free of defects, merchantable, fit for a *
* particular purpose or non-infringing. The entire risk as to the *
* quality and performance of the Covered Software is with You. *
* Should any Covered Software prove defective in any respect, You *
* (not any Contributor) assume the cost of any necessary servicing, *
* repair, or correction. This disclaimer of warranty constitutes an *
* essential part of this License. No use of any Covered Software is *
* authorized under this License except under this disclaimer. *
* *
************************************************************************
************************************************************************
* *
* 7. Limitation of Liability *
* -------------------------- *
* *
* Under no circumstances and under no legal theory, whether tort *
* (including negligence), contract, or otherwise, shall any *
* Contributor, or anyone who distributes Covered Software as *
* permitted above, be liable to You for any direct, indirect, *
* special, incidental, or consequential damages of any character *
* including, without limitation, damages for lost profits, loss of *
* goodwill, work stoppage, computer failure or malfunction, or any *
* and all other commercial damages or losses, even if such party *
* shall have been informed of the possibility of such damages. This *
* limitation of liability shall not apply to liability for death or *
* personal injury resulting from such party's negligence to the *
* extent applicable law prohibits such limitation. Some *
* jurisdictions do not allow the exclusion or limitation of *
* incidental or consequential damages, so this exclusion and *
* limitation may not apply to You. *
* *
************************************************************************
8. Litigation
-------------
Any litigation relating to this License may be brought only in the
courts of a jurisdiction where the defendant maintains its principal
place of business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions.
Nothing in this Section shall prevent a party's ability to bring
cross-claims or counter-claims.
9. Miscellaneous
----------------
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides
that the language of a contract shall be construed against the drafter
shall not be used to construe this License against a Contributor.
10. Versions of the License
---------------------------
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses
If You choose to distribute Source Code Form that is Incompatible With
Secondary Licenses under the terms of this version of the License, the
notice described in Exhibit B of this License must be attached.
Exhibit A - Source Code Form License Notice
-------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular
file, then You may include the notice in a location (such as a LICENSE
file in a relevant directory) where a recipient would be likely to look
for such a notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
---------------------------------------------------------
This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.

4
vendor/modules.txt vendored
View File

@ -548,6 +548,10 @@ github.com/hashicorp/packer-plugin-parallels/builder/parallels/pvm
github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/clone
github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/common
github.com/hashicorp/packer-plugin-proxmox/builder/proxmox/iso
# github.com/hashicorp/packer-plugin-puppet v0.0.1
## explicit
github.com/hashicorp/packer-plugin-puppet/provisioner/puppet-masterless
github.com/hashicorp/packer-plugin-puppet/provisioner/puppet-server
# github.com/hashicorp/packer-plugin-qemu v0.0.1
## explicit
github.com/hashicorp/packer-plugin-qemu/builder/qemu

View File

@ -1,198 +0,0 @@
---
description: >
The masterless Puppet Packer provisioner configures Puppet to run on the
machines by Packer from local modules and manifest files. Modules and
manifests
can be uploaded from your local machine to the remote machine or can simply
use
remote paths. Puppet is run in masterless mode, meaning it never communicates
to a Puppet master.
page_title: Puppet Masterless - Provisioners
---
# Puppet (Masterless) Provisioner
@include 'provisioners/unmaintained-plugin.mdx'
Type: `puppet-masterless`
The masterless Puppet Packer provisioner configures Puppet to run on the
machines by Packer from local modules and manifest files. Modules and manifests
can be uploaded from your local machine to the remote machine or can simply use
remote paths (perhaps obtained using something like the shell provisioner).
Puppet is run in masterless mode, meaning it never communicates to a Puppet
master.
-> **Note:** Puppet will _not_ be installed automatically by this
provisioner. This provisioner expects that Puppet is already installed on the
machine. It is common practice to use the [shell
provisioner](/docs/provisioners/shell) before the Puppet provisioner to do
this.
## Basic Example
The example below is fully functional and expects the configured manifest file
to exist relative to your working directory.
```json
{
"type": "puppet-masterless",
"manifest_file": "site.pp"
}
```
## Configuration Reference
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 (the ["main
manifest"](https://docs.puppetlabs.com/puppet/latest/reference/dirs_manifest)).
These file(s) must exist on your local system and will be uploaded to the
remote machine.
Optional parameters:
- `execute_command` (string) - The command-line to execute Puppet. This is a
[template engine](/docs/templates/legacy_json_templates/engine). Therefore, you
may use user variables and template functions in this field. In addition,
you may use the following extra variables:
- FacterVars: Additional facts to set when executing Puppet, joined for
use in a command. This is internal and not settable by the user.
- HieraConfigPath: Path to a hiera configuration file to upload and use;
set in the template option hiera_config_path
- ManifestDir: The directory of the manifest file on the remote machine.
- ManifestFile: The manifest file on the remote machine.
- ModulePath: The module_paths, combined into one path variable.
- ModulePathJoiner: A colon `:` on posix systems and a semicolon `;` on
Windows.
- PuppetBinDir: The directory that the Puppet binary is in.
- Sudo: Returns false when PreventSudo is set, and true when it is not.
- WorkingDir: The value provided in the `working_directory` option.
See below for `execute_command`'s default value.
* `extra_arguments` (array of strings) - Additional options to pass to the
Puppet command. This allows for customization of
`execute_command` without having to completely replace or subsume its
contents, making forward-compatible customizations much easier to maintain.
This string is lazy-evaluated so one can incorporate logic driven by
template variables as well as private elements of ExecuteTemplate (see
source: provisioner/puppet-masterless/provisioner.go).
```text
[
{{if ne "{{user environment}}" ""}}--environment={{user environment}}{{end}},
{{if ne ".ModulePath" ""}}--modulepath="{{.ModulePath}}{{.ModulePathJoiner}}$(puppet config print {{if ne "{{user `environment`}}" ""}}--environment={{user `environment`}}{{end}} modulepath)"{{end}}
]
```
* `facter` (object of key:value strings) - Additional
[facts](https://docs.puppet.com/facter/) to make available to the Puppet
run.
* `guest_os_type` (string) - The remote host's OS type ('windows' or 'unix')
to tailor command-line and path separators. (default: unix).
* `hiera_config_path` (string) - Local path to self-contained Hiera data to
be uploaded. NOTE: If you need data directories they must be previously
transferred with a File provisioner.
* `ignore_exit_codes` (boolean) - If true, Packer will ignore failures.
* `manifest_dir` (string) - Local directory with manifests to be uploaded.
This is useful if your main manifest uses imports, but the directory might
not contain the `manifest_file` itself.
~> `manifest_dir` is passed to Puppet as `--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) - Array of local module directories to be
uploaded.
- `prevent_sudo` (boolean) - On Unix platforms Puppet is typically invoked
with `sudo`. If true, it will be omitted. (default: false)
- `puppet_bin_dir` (string) - Path to the Puppet binary. Ideally the program
should be on the system (unix: `$PATH`, windows: `%PATH%`), but some
builders (eg. Docker) do not run profile-setup scripts and therefore PATH
might be empty or minimal. On Windows, spaces should be `^`-escaped, i.e.
`c:/program^ files/puppet^ labs/puppet/bin`.
- `staging_directory` (string) - Directory to where uploaded files will be
placed (unix: "/tmp/packer-puppet-masterless", windows:
"%SYSTEMROOT%/Temp/packer-puppet-masterless"). It doesn't need to
pre-exist, but the parent must have permissions sufficient for the account
Packer connects as to create directories and write files. Use a Shell
provisioner to prepare the way if needed.
- `working_directory` (string) - Directory from which `execute_command` will
be run. If using Hiera files with relative paths, this option can be
helpful. (default: `staging_directory`)
- `elevated_user` and `elevated_password` (string) - If specified, Puppet
will be run with elevated privileges using the given Windows user. See the
[powershell](/docs/provisioners/powershell) provisioner for the full
details. This is a [template engine](/docs/templates/legacy_json_templates/engine).
Therefore, you may use user variables and template functions in this
field, including `` {{ build `Password`}} `` to use the password being used
by the communicator to connect to your instance.
@include 'provisioners/common-config.mdx'
## Execute Command
By default, Packer uses the following command (broken across multiple lines for
readability) to execute Puppet:
```shell
cd {{.WorkingDir}} &&
{{if ne .FacterVars ""}}{{.FacterVars}} {{end}}
{{if .Sudo}}sudo -E {{end}}
{{if ne .PuppetBinDir ""}}{{.PuppetBinDir}}/{{end}}
puppet apply --detailed-exitcodes
{{if .Debug}}--debug {{end}}
{{if ne .ModulePath ""}}--modulepath='{{.ModulePath}}' {{end}}
{{if ne .HieraConfigPath ""}}--hiera_config='{{.HieraConfigPath}}' {{end}}
{{if ne .ManifestDir ""}}--manifestdir='{{.ManifestDir}}' {{end}}
{{if ne .ExtraArguments ""}}{{.ExtraArguments}} {{end}}
{{.ManifestFile}}
```
The following command is used if guest OS type is windows:
```shell
cd {{.WorkingDir}} &&
{{if ne .FacterVars ""}}{{.FacterVars}} && {{end}}
{{if ne .PuppetBinDir ""}}{{.PuppetBinDir}}/{{end}}
puppet apply --detailed-exitcodes
{{if .Debug}}--debug {{end}}
{{if ne .ModulePath ""}}--modulepath='{{.ModulePath}}' {{end}}
{{if ne .HieraConfigPath ""}}--hiera_config='{{.HieraConfigPath}}' {{end}}
{{if ne .ManifestDir ""}}--manifestdir='{{.ManifestDir}}' {{end}}
{{if ne .ExtraArguments ""}}{{.ExtraArguments}} {{end}}
{{.ManifestFile}}
```
## Default Facts
In addition to being able to specify custom Facter facts using the `facter`
configuration, the provisioner automatically defines certain commonly useful
facts:
- `packer_build_name` is set to the name of the build that Packer is running.
This is most useful when Packer is making multiple builds and you want to
distinguish them in your Hiera hierarchy.
- `packer_builder_type` is the type of the builder that was used to create
the machine that Puppet is running on. This is useful if you want to run
only certain parts of your Puppet code on systems built with certain
builders.

View File

@ -1,176 +0,0 @@
---
description: |
The puppet-server Packer provisioner provisions Packer machines with Puppet by
connecting to a Puppet master.
page_title: Puppet Server - Provisioners
---
# Puppet Server Provisioner
@include 'provisioners/unmaintained-plugin.mdx'
Type: `puppet-server`
The `puppet-server` Packer provisioner provisions Packer machines with Puppet
by connecting to a Puppet master.
-> **Note:** Puppet will _not_ be installed automatically by this
provisioner. This provisioner expects that Puppet is already installed on the
machine. It is common practice to use the [shell
provisioner](/docs/provisioners/shell) before the Puppet provisioner to do
this.
## Basic Example
The example below is fully functional and expects a Puppet server to be
accessible from your network.
```json
{
"type": "puppet-server",
"extra_arguments": "--test --pluginsync",
"facter": {
"server_role": "webserver"
}
}
```
## Configuration Reference
The reference of available configuration options is listed below.
The provisioner takes various options. None are strictly required. They are
listed below:
- `client_cert_path` (string) - Path to the directory on your disk that
contains the client certificate for the node. This defaults to nothing, in
which case a client cert won't be uploaded.
- `client_private_key_path` (string) - Path to the directory on your disk
that contains the client private key for the node. This defaults to
nothing, in which case a client private key won't be uploaded.
- `execute_command` (string) - The command-line to execute Puppet. This is a
[template engine](/docs/templates/legacy_json_templates/engine). Therefore, you
may use user variables and template functions in this field. In addition,
you may use the following extra variables:
- ClientCertPath: The value set in the template option
`client_cert_path`.
- ClientPrivateKeyPath: The value set in the template option
`client_private_key_path`.
- FacterVars: Additional facts to set when executing Puppet, joined for
use in a command. This is internal and not settable by the user.
- PuppetNode: The hostname of the Puppet node, set in `puppet_node`.
- PuppetServer: The hostname of the Puppet server, set in `puppet_server`
- PuppetBinDir: The directory that the Puppet binary is in.
- Sudo: Returns false when PreventSudo is set, and true when it is not.
- WorkingDir: The value provided in the `working_directory` option.
See below for `execute_command`'s default value.
* `extra_arguments` (array of strings) - Additional options to pass to the
Puppet command. This allows for customization of `execute_command` without
having to completely replace or subsume its contents, making
forward-compatible customizations much easier to maintain.
This string is lazy-evaluated so one can incorporate logic driven by
template variables as well as private elements of ExecuteTemplate (see
source: provisioner/puppet-server/provisioner.go).
```text
[
{{if ne "{{user environment}}" ""}}--environment={{user environment}}{{end}}
]
```
* `facter` (object of key/value strings) - Additional
[facts](https://puppet.com/docs/puppet/latest/facter.html) to make available to the Puppet run.
* `guest_os_type` (string) - The remote host's OS type ('windows' or 'unix')
to tailor command-line and path separators. (default: unix).
* `ignore_exit_codes` (boolean) - If true, Packer will ignore failures.
* `prevent_sudo` (boolean) - On Unix platforms Puppet is typically invoked
with `sudo`. If true, it will be omitted. (default: false)
* `puppet_bin_dir` (string) - Path to the Puppet binary. Ideally the program
should be on the system (unix: `$PATH`, windows: `%PATH%`), but some
builders (eg. Docker) do not run profile-setup scripts and therefore PATH
might be empty or minimal. On Windows, spaces should be `^`-escaped, i.e.
`c:/program^ files/puppet^ labs/puppet/bin`.
* `puppet_node` (string) - The name of the node. If this isn't set, the fully
qualified domain name will be used.
* `puppet_server` (string) - Hostname of the Puppet server. By default
"puppet" will be used.
* `staging_dir` (string) - Directory to where uploaded files will be placed
(unix: "/tmp/packer-puppet-masterless", windows:
"%SYSTEMROOT%/Temp/packer-puppet-masterless"). It doesn't need to
pre-exist, but the parent must have permissions sufficient for the account
Packer connects as to create directories and write files. Use a Shell
provisioner to prepare the way if needed.
* `working_directory` (string) - Directory from which `execute_command` will
be run. If using Hiera files with relative paths, this option can be
helpful. (default: `staging_directory`)
* `elevated_user` and `elevated_password` (string) - If specified, Puppet
will be run with elevated privileges using the given Windows user. See the
[powershell](/docs/provisioners/powershell) provisioner for the full
details. This is a [template engine](/docs/templates/legacy_json_templates/engine).
Therefore, you may use user variables and template functions in this
field, including `` {{ build `Password`}} `` to use the password being used
by the communicator to connect to your instance.
@include 'provisioners/common-config.mdx'
## Execute Command
By default, Packer uses the following command (broken across multiple lines for
readability) to execute Puppet:
```shell
cd {{.WorkingDir}} &&
{{if ne .FacterVars ""}}{{.FacterVars}} {{end}}
{{if .Sudo}}sudo -E {{end}}
{{if ne .PuppetBinDir ""}}{{.PuppetBinDir}}/{{end}}
puppet agent --onetime --no-daemonize --detailed-exitcodes
{{if .Debug}}--debug {{end}}
{{if ne .PuppetServer ""}}--server='{{.PuppetServer}}' {{end}}
{{if ne .PuppetNode ""}}--certname='{{.PuppetNode}}' {{end}}
{{if ne .ClientCertPath ""}}--certdir='{{.ClientCertPath}}' {{end}}
{{if ne .ClientPrivateKeyPath ""}}--privatekeydir='{{.ClientPrivateKeyPath}}' {{end}}
{{if ne .ExtraArguments ""}}{{.ExtraArguments}} {{end}}
```
The following command is used if guest OS type is windows:
```shell
cd {{.WorkingDir}} &&
{{if ne .FacterVars ""}}{{.FacterVars}} && {{end}}
{{if ne .PuppetBinDir ""}}{{.PuppetBinDir}}/{{end}}
puppet agent --onetime --no-daemonize --detailed-exitcodes
{{if .Debug}}--debug {{end}}
{{if ne .PuppetServer ""}}--server='{{.PuppetServer}}' {{end}}
{{if ne .PuppetNode ""}}--certname='{{.PuppetNode}}' {{end}}
{{if ne .ClientCertPath ""}}--certdir='{{.ClientCertPath}}' {{end}}
{{if ne .ClientPrivateKeyPath ""}}--privatekeydir='{{.ClientPrivateKeyPath}}' {{end}}
{{if ne .ExtraArguments ""}}{{.ExtraArguments}} {{end}}
```
## Default Facts
In addition to being able to specify custom Facter facts using the `facter`
configuration, the provisioner automatically defines certain commonly useful
facts:
- `packer_build_name` is set to the name of the build that Packer is running.
This is most useful when Packer is making multiple builds and you want to
distinguish them in your Hiera hierarchy.
- `packer_builder_type` is the type of the builder that was used to create
the machine that Puppet is running on. This is useful if you want to run
only certain parts of your Puppet code on systems built with certain
builders.

View File

@ -844,14 +844,6 @@
"title": "PowerShell",
"path": "provisioners/powershell"
},
{
"title": "Puppet Masterless",
"path": "provisioners/puppet-masterless"
},
{
"title": "Puppet Server",
"path": "provisioners/puppet-server"
},
{
"title": "Salt Masterless",
"path": "provisioners/salt-masterless"

View File

@ -71,6 +71,13 @@
"pluginTier": "community",
"version": "latest"
},
{
"title": "Puppet",
"path": "puppet",
"repo": "hashicorp/packer-plugin-puppet",
"version": "latest",
"pluginTier": "community"
},
{
"title": "Scaleway",
"path": "scaleway",