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
8beaae0d
Commit
8beaae0d
authored
Nov 25, 2013
by
Jan Brauer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#450 - allow configuration of manifest dir
parent
30ba7307
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
0 deletions
+60
-0
provisioner/puppet-masterless/provisioner.go
provisioner/puppet-masterless/provisioner.go
+35
-0
provisioner/puppet-masterless/provisioner_test.go
provisioner/puppet-masterless/provisioner_test.go
+25
-0
No files found.
provisioner/puppet-masterless/provisioner.go
View file @
8beaae0d
...
...
@@ -31,6 +31,9 @@ type Config struct {
// The main manifest file to apply to kick off the entire thing.
ManifestFile
string
`mapstructure:"manifest_file"`
// The manifest dir, e.g. for includes
ManifestDir
string
`mapstructure:"manifest_dir"`
// If true, `sudo` will NOT be used to execute Puppet.
PreventSudo
bool
`mapstructure:"prevent_sudo"`
...
...
@@ -49,6 +52,8 @@ type ExecuteTemplate struct {
HieraConfigPath
string
ModulePath
string
ManifestFile
string
HasManifestDir
bool
ManifestDir
string
Sudo
bool
}
...
...
@@ -72,6 +77,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
p
.
config
.
ExecuteCommand
=
"{{.FacterVars}} {{if .Sudo}} sudo -E {{end}}"
+
"puppet apply --verbose --modulepath='{{.ModulePath}}' "
+
"{{if .HasHieraConfigPath}}--hiera_config='{{.HieraConfigPath}}' {{end}}"
+
"{{if .HasManifestDir}}--manifestdir='{{.ManifestDir}}' {{end}}"
+
"--detailed-exitcodes "
+
"{{.ManifestFile}}"
}
...
...
@@ -84,6 +90,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
templates
:=
map
[
string
]
*
string
{
"hiera_config_path"
:
&
p
.
config
.
HieraConfigPath
,
"manifest_file"
:
&
p
.
config
.
ManifestFile
,
"manifest_dir"
:
&
p
.
config
.
ManifestDir
,
"staging_dir"
:
&
p
.
config
.
StagingDir
,
}
...
...
@@ -204,6 +211,16 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
}
}
// Upload manifest dir if set
remoteManifestDir
:=
""
if
p
.
config
.
ManifestDir
!=
""
{
var
err
error
remoteManifestDir
,
err
=
p
.
uploadManifestDir
(
ui
,
comm
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Error uploading manifest dir: %s"
,
err
)
}
}
// Upload all modules
modulePaths
:=
make
([]
string
,
0
,
len
(
p
.
config
.
ModulePaths
))
for
i
,
path
:=
range
p
.
config
.
ModulePaths
{
...
...
@@ -233,6 +250,8 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
FacterVars
:
strings
.
Join
(
facterVars
,
" "
),
HasHieraConfigPath
:
remoteHieraConfigPath
!=
""
,
HieraConfigPath
:
remoteHieraConfigPath
,
HasManifestDir
:
remoteManifestDir
!=
""
,
ManifestDir
:
remoteManifestDir
,
ManifestFile
:
remoteManifestFile
,
ModulePath
:
strings
.
Join
(
modulePaths
,
":"
),
Sudo
:
!
p
.
config
.
PreventSudo
,
...
...
@@ -279,6 +298,22 @@ func (p *Provisioner) uploadHieraConfig(ui packer.Ui, comm packer.Communicator)
return
path
,
nil
}
func
(
p
*
Provisioner
)
uploadManifestDir
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
)
(
string
,
error
)
{
ui
.
Message
(
"Uploading manifest dir..."
)
path
,
err
:=
os
.
Open
(
p
.
config
.
ManifestDir
)
if
err
!=
nil
{
return
""
,
err
}
defer
path
.
Close
()
targetPath
:=
fmt
.
Sprintf
(
"%s/manifests"
,
p
.
config
.
StagingDir
)
if
err
:=
p
.
uploadDirectory
(
ui
,
comm
,
targetPath
,
p
.
config
.
ManifestDir
);
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"Error uploading manifest dir: %s"
,
err
)
}
return
p
.
config
.
ManifestDir
,
nil
}
func
(
p
*
Provisioner
)
uploadManifests
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
)
(
string
,
error
)
{
// Create the remote manifests directory...
ui
.
Message
(
"Uploading manifests..."
)
...
...
provisioner/puppet-masterless/provisioner_test.go
View file @
8beaae0d
...
...
@@ -76,6 +76,31 @@ func TestProvisionerPrepare_manifestFile(t *testing.T) {
}
}
func
TestProvisionerPrepare_manifestDir
(
t
*
testing
.
T
)
{
config
:=
testConfig
()
delete
(
config
,
"manifestdir"
)
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
[
"manifest_dir"
]
=
tf
.
Name
()
p
=
new
(
Provisioner
)
err
=
p
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
}
func
TestProvisionerPrepare_modulePaths
(
t
*
testing
.
T
)
{
config
:=
testConfig
()
...
...
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