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
a100e939
Commit
a100e939
authored
10 years ago
by
Colin Hebert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for custom working directory for puppet
parent
4a0c242c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
1 deletion
+20
-1
provisioner/puppet-masterless/provisioner.go
provisioner/puppet-masterless/provisioner.go
+13
-1
website/source/docs/provisioners/puppet-masterless.html.markdown
.../source/docs/provisioners/puppet-masterless.html.markdown
+7
-0
No files found.
provisioner/puppet-masterless/provisioner.go
View file @
a100e939
...
@@ -41,6 +41,10 @@ type Config struct {
...
@@ -41,6 +41,10 @@ type Config struct {
// The directory where files will be uploaded. Packer requires write
// The directory where files will be uploaded. Packer requires write
// permissions in this directory.
// permissions in this directory.
StagingDir
string
`mapstructure:"staging_directory"`
StagingDir
string
`mapstructure:"staging_directory"`
// The directory from which the command will be executed.
// Packer requires the directory to exist when running puppet.
WorkingDir
string
`mapstructure:"working_directory"`
}
}
type
Provisioner
struct
{
type
Provisioner
struct
{
...
@@ -48,6 +52,7 @@ type Provisioner struct {
...
@@ -48,6 +52,7 @@ type Provisioner struct {
}
}
type
ExecuteTemplate
struct
{
type
ExecuteTemplate
struct
{
WorkingDir
string
FacterVars
string
FacterVars
string
HieraConfigPath
string
HieraConfigPath
string
ModulePath
string
ModulePath
string
...
@@ -73,7 +78,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
...
@@ -73,7 +78,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
// Set some defaults
// Set some defaults
if
p
.
config
.
ExecuteCommand
==
""
{
if
p
.
config
.
ExecuteCommand
==
""
{
p
.
config
.
ExecuteCommand
=
"{{.FacterVars}} {{if .Sudo}} sudo -E {{end}}"
+
p
.
config
.
ExecuteCommand
=
"cd {{.WorkingDir}} && "
+
"{{.FacterVars}} {{if .Sudo}} sudo -E {{end}}"
+
"puppet apply --verbose --modulepath='{{.ModulePath}}' "
+
"puppet apply --verbose --modulepath='{{.ModulePath}}' "
+
"{{if ne .HieraConfigPath
\"\"
}}--hiera_config='{{.HieraConfigPath}}' {{end}}"
+
"{{if ne .HieraConfigPath
\"\"
}}--hiera_config='{{.HieraConfigPath}}' {{end}}"
+
"{{if ne .ManifestDir
\"\"
}}--manifestdir='{{.ManifestDir}}' {{end}}"
+
"{{if ne .ManifestDir
\"\"
}}--manifestdir='{{.ManifestDir}}' {{end}}"
+
...
@@ -85,12 +91,17 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
...
@@ -85,12 +91,17 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
p
.
config
.
StagingDir
=
"/tmp/packer-puppet-masterless"
p
.
config
.
StagingDir
=
"/tmp/packer-puppet-masterless"
}
}
if
p
.
config
.
WorkingDir
==
""
{
p
.
config
.
StagingDir
=
p
.
config
.
StagingDir
}
// Templates
// Templates
templates
:=
map
[
string
]
*
string
{
templates
:=
map
[
string
]
*
string
{
"hiera_config_path"
:
&
p
.
config
.
HieraConfigPath
,
"hiera_config_path"
:
&
p
.
config
.
HieraConfigPath
,
"manifest_file"
:
&
p
.
config
.
ManifestFile
,
"manifest_file"
:
&
p
.
config
.
ManifestFile
,
"manifest_dir"
:
&
p
.
config
.
ManifestDir
,
"manifest_dir"
:
&
p
.
config
.
ManifestDir
,
"staging_dir"
:
&
p
.
config
.
StagingDir
,
"staging_dir"
:
&
p
.
config
.
StagingDir
,
"working_dir"
:
&
p
.
config
.
WorkingDir
,
}
}
for
n
,
ptr
:=
range
templates
{
for
n
,
ptr
:=
range
templates
{
...
@@ -256,6 +267,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
...
@@ -256,6 +267,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
// Execute Puppet
// Execute Puppet
command
,
err
:=
p
.
config
.
tpl
.
Process
(
p
.
config
.
ExecuteCommand
,
&
ExecuteTemplate
{
command
,
err
:=
p
.
config
.
tpl
.
Process
(
p
.
config
.
ExecuteCommand
,
&
ExecuteTemplate
{
WorkingDir
:
p
.
config
.
WorkingDir
,
FacterVars
:
strings
.
Join
(
facterVars
,
" "
),
FacterVars
:
strings
.
Join
(
facterVars
,
" "
),
HieraConfigPath
:
remoteHieraConfigPath
,
HieraConfigPath
:
remoteHieraConfigPath
,
ManifestDir
:
remoteManifestDir
,
ManifestDir
:
remoteManifestDir
,
...
...
This diff is collapsed.
Click to expand it.
website/source/docs/provisioners/puppet-masterless.html.markdown
View file @
a100e939
...
@@ -79,12 +79,18 @@ Optional parameters:
...
@@ -79,12 +79,18 @@ Optional parameters:
this folder. If the permissions are not correct, use a shell provisioner
this folder. If the permissions are not correct, use a shell provisioner
prior to this to configure it properly.
prior to this to configure it properly.
*
`working_directory`
(string) - This is the directory from which the puppet command
will be run. When using hiera with a relative path, this option allows to ensure
that he paths are working properly. If not specified, defaults to the value of
specified
`staging_directory`
(or its default value if not specified either).
## Execute Command
## Execute Command
By default, Packer uses the following command (broken across multiple lines
By default, Packer uses the following command (broken across multiple lines
for readability) to execute Puppet:
for readability) to execute Puppet:
```
liquid
```
liquid
cd
{{.
WorkingDir
}}
&& \
{{.
FacterVars
}}{{
if
.
Sudo
}}
sudo -E
{{
end
}}
puppet apply \
{{.
FacterVars
}}{{
if
.
Sudo
}}
sudo -E
{{
end
}}
puppet apply \
--verbose \
--verbose \
--modulepath='
{{.
ModulePath
}}
' \
--modulepath='
{{.
ModulePath
}}
' \
...
@@ -98,6 +104,7 @@ This command can be customized using the `execute_command` configuration.
...
@@ -98,6 +104,7 @@ This command can be customized using the `execute_command` configuration.
As you can see from the default value above, the value of this configuration
As you can see from the default value above, the value of this configuration
can contain various template variables, defined below:
can contain various template variables, defined below:
*
`WorkingDir`
- The path from which Puppet will be executed.
*
`FacterVars`
- Shell-friendly string of environmental variables used
*
`FacterVars`
- Shell-friendly string of environmental variables used
to set custom facts configured for this provisioner.
to set custom facts configured for this provisioner.
*
`HieraConfigPath`
- The path to a hiera configuration file.
*
`HieraConfigPath`
- The path to a hiera configuration file.
...
...
This diff is collapsed.
Click to expand it.
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