Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
41b70aae
Commit
41b70aae
authored
Sep 08, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provisioner/puppet-masterless: support custom facts
parent
a33d4a11
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
2 deletions
+40
-2
provisioner/puppet-masterless/provisioner.go
provisioner/puppet-masterless/provisioner.go
+33
-1
website/source/docs/provisioners/puppet-masterless.html.markdown
.../source/docs/provisioners/puppet-masterless.html.markdown
+7
-1
No files found.
provisioner/puppet-masterless/provisioner.go
View file @
41b70aae
...
...
@@ -19,6 +19,9 @@ type Config struct {
// The command used to execute Puppet.
ExecuteCommand
string
`mapstructure:"execute_command"`
// Additional facts to set when executing Puppet
Facter
map
[
string
]
string
// An array of local paths of modules to upload.
ModulePaths
[]
string
`mapstructure:"module_paths"`
...
...
@@ -38,6 +41,7 @@ type Provisioner struct {
}
type
ExecuteTemplate
struct
{
FacterVars
string
ModulePath
string
ManifestFile
string
Sudo
bool
...
...
@@ -60,7 +64,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
// Set some defaults
if
p
.
config
.
ExecuteCommand
==
""
{
p
.
config
.
ExecuteCommand
=
"{{
if .Sudo}}sudo
{{end}}puppet apply --verbose --modulepath='{{.ModulePath}}' {{.ManifestFile}}"
p
.
config
.
ExecuteCommand
=
"{{
.FacterVars}}{{if .Sudo}} sudo -E
{{end}}puppet apply --verbose --modulepath='{{.ModulePath}}' {{.ManifestFile}}"
}
if
p
.
config
.
StagingDir
==
""
{
...
...
@@ -107,6 +111,27 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
}
}
newFacts
:=
make
(
map
[
string
]
string
)
for
k
,
v
:=
range
p
.
config
.
Facter
{
k
,
err
:=
p
.
config
.
tpl
.
Process
(
k
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing facter key %s: %s"
,
k
,
err
))
continue
}
v
,
err
:=
p
.
config
.
tpl
.
Process
(
v
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing facter value '%s': %s"
,
v
,
err
))
continue
}
newFacts
[
k
]
=
v
}
p
.
config
.
Facter
=
newFacts
// Validation
if
p
.
config
.
ManifestFile
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
...
...
@@ -165,8 +190,15 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
return
fmt
.
Errorf
(
"Error uploading manifests: %s"
,
err
)
}
// Compile the facter variables
facterVars
:=
make
([]
string
,
0
,
len
(
p
.
config
.
Facter
))
for
k
,
v
:=
range
p
.
config
.
Facter
{
facterVars
=
append
(
facterVars
,
fmt
.
Sprintf
(
"FACTER_%s='%s'"
,
k
,
v
))
}
// Execute Puppet
command
,
err
:=
p
.
config
.
tpl
.
Process
(
p
.
config
.
ExecuteCommand
,
&
ExecuteTemplate
{
FacterVars
:
strings
.
Join
(
facterVars
,
" "
),
ManifestFile
:
remoteManifestFile
,
ModulePath
:
strings
.
Join
(
modulePaths
,
":"
),
Sudo
:
!
p
.
config
.
PreventSudo
,
...
...
website/source/docs/provisioners/puppet-masterless.html.markdown
View file @
41b70aae
...
...
@@ -50,6 +50,10 @@ Optional parameters:
various
[
configuration template variables
](
/docs/templates/configuration-templates.html
)
available. See below for more information.
*
`facter`
(object, string keys and values) - Additonal
[
facts
](
http://puppetlabs.com/puppet/related-projects/facter
)
to make
available when Puppet is running.
*
`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.
...
...
@@ -71,7 +75,7 @@ By default, Packer uses the following command (broken across multiple lines
for readability) to execute Puppet:
```
{{
if .Sudo}sudo
{{end}}puppet apply \
{{
.FacterVars}}{{if .Sudo} sudo -E
{{end}}puppet apply \
--verbose \
--modulepath='{{.ModulePath}}' \
{{.ManifestFile}}
...
...
@@ -81,6 +85,8 @@ This command can be customized using the `execute_command` configuration.
As you can see from the default value above, the value of this configuration
can contain various template variables, defined below:
*
`FacterVars`
- Shell-friendly string of environmental variables used
to set custom facts configured for this provisioner.
*
`ManifestFile`
- The path on the remote machine to the manifest file
for Puppet to use.
*
`ModulePath`
- The paths to the module directories.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment