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
288b9a70
Commit
288b9a70
authored
Jun 22, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1657 from njhartwell/master
Adding disable sudo support to salt masterless
parents
c5503ee0
c4cee75b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
3 deletions
+39
-3
provisioner/salt-masterless/provisioner.go
provisioner/salt-masterless/provisioner.go
+14
-3
provisioner/salt-masterless/provisioner_test.go
provisioner/salt-masterless/provisioner_test.go
+25
-0
No files found.
provisioner/salt-masterless/provisioner.go
View file @
288b9a70
...
@@ -23,6 +23,8 @@ type Config struct {
...
@@ -23,6 +23,8 @@ type Config struct {
SkipBootstrap
bool
`mapstructure:"skip_bootstrap"`
SkipBootstrap
bool
`mapstructure:"skip_bootstrap"`
BootstrapArgs
string
`mapstructure:"bootstrap_args"`
BootstrapArgs
string
`mapstructure:"bootstrap_args"`
DisableSudo
bool
`mapstructure:"disable_sudo"`
// Local path to the minion config
// Local path to the minion config
MinionConfig
string
`mapstructure:"minion_config"`
MinionConfig
string
`mapstructure:"minion_config"`
...
@@ -106,7 +108,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
...
@@ -106,7 +108,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
return
fmt
.
Errorf
(
"Unable to download Salt: %s"
,
err
)
return
fmt
.
Errorf
(
"Unable to download Salt: %s"
,
err
)
}
}
cmd
=
&
packer
.
RemoteCmd
{
cmd
=
&
packer
.
RemoteCmd
{
Command
:
fmt
.
Sprintf
(
"
sudo sh /tmp/install_salt.sh %s"
,
p
.
config
.
BootstrapArgs
),
Command
:
fmt
.
Sprintf
(
"
%s /tmp/install_salt.sh %s"
,
p
.
sudo
(
"sh"
)
,
p
.
config
.
BootstrapArgs
),
}
}
ui
.
Message
(
fmt
.
Sprintf
(
"Installing Salt with command %s"
,
cmd
.
Command
))
ui
.
Message
(
fmt
.
Sprintf
(
"Installing Salt with command %s"
,
cmd
.
Command
))
if
err
=
cmd
.
StartWithUi
(
comm
,
ui
);
err
!=
nil
{
if
err
=
cmd
.
StartWithUi
(
comm
,
ui
);
err
!=
nil
{
...
@@ -166,7 +168,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
...
@@ -166,7 +168,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
}
}
ui
.
Message
(
"Running highstate"
)
ui
.
Message
(
"Running highstate"
)
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
"sudo salt-call --local state.highstate -l info --retcode-passthrough"
}
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
p
.
sudo
(
"salt-call --local state.highstate -l info --retcode-passthrough"
)
}
if
err
=
cmd
.
StartWithUi
(
comm
,
ui
);
err
!=
nil
||
cmd
.
ExitStatus
!=
0
{
if
err
=
cmd
.
StartWithUi
(
comm
,
ui
);
err
!=
nil
||
cmd
.
ExitStatus
!=
0
{
if
err
==
nil
{
if
err
==
nil
{
err
=
fmt
.
Errorf
(
"Bad exit status: %d"
,
cmd
.
ExitStatus
)
err
=
fmt
.
Errorf
(
"Bad exit status: %d"
,
cmd
.
ExitStatus
)
...
@@ -184,6 +186,15 @@ func (p *Provisioner) Cancel() {
...
@@ -184,6 +186,15 @@ func (p *Provisioner) Cancel() {
os
.
Exit
(
0
)
os
.
Exit
(
0
)
}
}
// Prepends sudo to supplied command if config says to
func
(
p
*
Provisioner
)
sudo
(
cmd
string
)
string
{
if
p
.
config
.
DisableSudo
{
return
cmd
}
return
"sudo "
+
cmd
}
func
(
p
*
Provisioner
)
uploadFile
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
dst
,
src
string
)
error
{
func
(
p
*
Provisioner
)
uploadFile
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
dst
,
src
string
)
error
{
f
,
err
:=
os
.
Open
(
src
)
f
,
err
:=
os
.
Open
(
src
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -199,7 +210,7 @@ func (p *Provisioner) uploadFile(ui packer.Ui, comm packer.Communicator, dst, sr
...
@@ -199,7 +210,7 @@ func (p *Provisioner) uploadFile(ui packer.Ui, comm packer.Communicator, dst, sr
func
(
p
*
Provisioner
)
moveFile
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
dst
,
src
string
)
error
{
func
(
p
*
Provisioner
)
moveFile
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
dst
,
src
string
)
error
{
ui
.
Message
(
fmt
.
Sprintf
(
"Moving %s to %s"
,
src
,
dst
))
ui
.
Message
(
fmt
.
Sprintf
(
"Moving %s to %s"
,
src
,
dst
))
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
fmt
.
Sprintf
(
"sudo mv %s %s"
,
src
,
dst
)}
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
fmt
.
Sprintf
(
p
.
sudo
(
"mv %s %s"
)
,
src
,
dst
)}
if
err
:=
cmd
.
StartWithUi
(
comm
,
ui
);
err
!=
nil
||
cmd
.
ExitStatus
!=
0
{
if
err
:=
cmd
.
StartWithUi
(
comm
,
ui
);
err
!=
nil
||
cmd
.
ExitStatus
!=
0
{
if
err
==
nil
{
if
err
==
nil
{
err
=
fmt
.
Errorf
(
"Bad exit status: %d"
,
cmd
.
ExitStatus
)
err
=
fmt
.
Errorf
(
"Bad exit status: %d"
,
cmd
.
ExitStatus
)
...
...
provisioner/salt-masterless/provisioner_test.go
View file @
288b9a70
...
@@ -103,3 +103,28 @@ func TestProvisionerPrepare_LocalPillarRoots(t *testing.T) {
...
@@ -103,3 +103,28 @@ func TestProvisionerPrepare_LocalPillarRoots(t *testing.T) {
t
.
Fatalf
(
"err: %s"
,
err
)
t
.
Fatalf
(
"err: %s"
,
err
)
}
}
}
}
func
TestProvisionerSudo
(
t
*
testing
.
T
)
{
var
p
Provisioner
config
:=
testConfig
()
err
:=
p
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
withSudo
:=
p
.
sudo
(
"echo hello"
)
if
withSudo
!=
"sudo echo hello"
{
t
.
Fatalf
(
"sudo command not generated correctly"
)
}
config
[
"disable_sudo"
]
=
true
err
=
p
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
withoutSudo
:=
p
.
sudo
(
"echo hello"
)
if
withoutSudo
!=
"echo hello"
{
t
.
Fatalf
(
"sudo-less command not generated correctly"
)
}
}
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