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
361d7fbf
Commit
361d7fbf
authored
Jul 21, 2013
by
Rafael Garcia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provisioner/salt: install salt
parent
05ef4568
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
159 additions
and
1 deletion
+159
-1
config.go
config.go
+2
-1
plugin/provisioner-salt/main.go
plugin/provisioner-salt/main.go
+10
-0
provisioner/salt/provisioner.go
provisioner/salt/provisioner.go
+147
-0
No files found.
config.go
View file @
361d7fbf
...
...
@@ -38,7 +38,8 @@ const defaultConfig = `
"provisioners": {
"file": "packer-provisioner-file",
"shell": "packer-provisioner-shell"
"shell": "packer-provisioner-shell",
"salt": "packer-provisioner-salt"
}
}
`
...
...
plugin/provisioner-salt/main.go
0 → 100644
View file @
361d7fbf
package
main
import
(
"github.com/mitchellh/packer/packer/plugin"
"github.com/mitchellh/packer/provisioner/salt"
)
func
main
()
{
plugin
.
ServeProvisioner
(
new
(
salt
.
Provisioner
))
}
provisioner/salt/provisioner.go
0 → 100644
View file @
361d7fbf
// This package implements a provisioner for Packer that executes a
// saltstack highstate within the remote machine
package
salt
import
(
"fmt"
"github.com/mitchellh/iochan"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/packer"
"io"
"log"
"sort"
"strings"
)
var
Ui
packer
.
Ui
type
config
struct
{
// If true, skips installing Salt. Defaults to false.
SkipInstall
bool
`mapstructure:"skip_install"`
}
type
Provisioner
struct
{
config
config
}
func
(
p
*
Provisioner
)
Prepare
(
raws
...
interface
{})
error
{
var
md
mapstructure
.
Metadata
decoderConfig
:=
&
mapstructure
.
DecoderConfig
{
Metadata
:
&
md
,
Result
:
&
p
.
config
,
}
decoder
,
err
:=
mapstructure
.
NewDecoder
(
decoderConfig
)
if
err
!=
nil
{
return
err
}
for
_
,
raw
:=
range
raws
{
err
:=
decoder
.
Decode
(
raw
)
if
err
!=
nil
{
return
err
}
}
// Accumulate any errors
errs
:=
make
([]
error
,
0
)
// Unused keys are errors
if
len
(
md
.
Unused
)
>
0
{
sort
.
Strings
(
md
.
Unused
)
for
_
,
unused
:=
range
md
.
Unused
{
if
unused
!=
"type"
&&
!
strings
.
HasPrefix
(
unused
,
"packer_"
)
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Unknown configuration key: %s"
,
unused
))
}
}
}
if
len
(
errs
)
>
0
{
return
&
packer
.
MultiError
{
errs
}
}
return
nil
}
func
InstallSalt
(
comm
packer
.
Communicator
)
(
err
error
)
{
Ui
.
Say
(
"Installing Salt"
)
cmd
:=
"wget -O - http://bootstrap.saltstack.org | sudo sh"
if
err
=
executeCommand
(
cmd
,
comm
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Unable to install Salt: %d"
,
err
)
}
return
nil
}
func
(
p
*
Provisioner
)
Provision
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
)
error
{
var
err
error
Ui
=
ui
if
!
p
.
config
.
SkipInstall
{
if
err
=
InstallSalt
(
comm
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Error installing Salt: %s"
,
err
)
}
}
return
nil
}
func
executeCommand
(
command
string
,
comm
packer
.
Communicator
)
(
err
error
)
{
// Setup the remote command
stdout_r
,
stdout_w
:=
io
.
Pipe
()
stderr_r
,
stderr_w
:=
io
.
Pipe
()
var
cmd
packer
.
RemoteCmd
cmd
.
Command
=
command
cmd
.
Stdout
=
stdout_w
cmd
.
Stderr
=
stderr_w
log
.
Printf
(
"Executing command: %s"
,
cmd
.
Command
)
err
=
comm
.
Start
(
&
cmd
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed executing command: %s"
,
err
)
}
exitChan
:=
make
(
chan
int
,
1
)
stdoutChan
:=
iochan
.
DelimReader
(
stdout_r
,
'\n'
)
stderrChan
:=
iochan
.
DelimReader
(
stderr_r
,
'\n'
)
go
func
()
{
defer
stdout_w
.
Close
()
defer
stderr_w
.
Close
()
cmd
.
Wait
()
exitChan
<-
cmd
.
ExitStatus
}()
OutputLoop
:
for
{
select
{
case
output
:=
<-
stderrChan
:
Ui
.
Message
(
strings
.
TrimSpace
(
output
))
case
output
:=
<-
stdoutChan
:
Ui
.
Message
(
strings
.
TrimSpace
(
output
))
case
exitStatus
:=
<-
exitChan
:
log
.
Printf
(
"Chef Solo provisioner exited with status %d"
,
exitStatus
)
if
exitStatus
!=
0
{
return
fmt
.
Errorf
(
"Command exited with non-zero exit status: %d"
,
exitStatus
)
}
break
OutputLoop
}
}
// Make sure we finish off stdout/stderr because we may have gotten
// a message from the exit channel first.
for
output
:=
range
stdoutChan
{
Ui
.
Message
(
output
)
}
for
output
:=
range
stderrChan
{
Ui
.
Message
(
output
)
}
return
nil
}
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