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
14787fd4
Commit
14787fd4
authored
Jun 15, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provisioner/chef-client: run cleanup on node [GH-1295]
parent
86539398
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
15 deletions
+27
-15
provisioner/chef-client/provisioner.go
provisioner/chef-client/provisioner.go
+27
-15
No files found.
provisioner/chef-client/provisioner.go
View file @
14787fd4
...
...
@@ -9,7 +9,6 @@ import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
...
...
@@ -336,15 +335,9 @@ func (p *Provisioner) createDir(ui packer.Ui, comm packer.Communicator, dir stri
func
(
p
*
Provisioner
)
cleanNode
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
node
string
)
error
{
ui
.
Say
(
"Cleaning up chef node..."
)
app
:=
fmt
.
Sprintf
(
"knife node delete %s -y"
,
node
)
cmd
:=
exec
.
Command
(
"sh"
,
"-c"
,
app
)
out
,
err
:=
cmd
.
Output
()
ui
.
Message
(
fmt
.
Sprintf
(
"%s"
,
out
))
if
err
!=
nil
{
return
err
args
:=
[]
string
{
"node"
,
"delete"
,
node
}
if
err
:=
p
.
knifeExec
(
ui
,
comm
,
node
,
args
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to cleanup node: %s"
,
err
)
}
return
nil
...
...
@@ -352,16 +345,35 @@ func (p *Provisioner) cleanNode(ui packer.Ui, comm packer.Communicator, node str
func
(
p
*
Provisioner
)
cleanClient
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
node
string
)
error
{
ui
.
Say
(
"Cleaning up chef client..."
)
app
:=
fmt
.
Sprintf
(
"knife client delete %s -y"
,
node
)
args
:=
[]
string
{
"client"
,
"delete"
,
node
}
if
err
:=
p
.
knifeExec
(
ui
,
comm
,
node
,
args
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to cleanup client: %s"
,
err
)
}
cmd
:=
exec
.
Command
(
"sh"
,
"-c"
,
app
)
out
,
err
:=
cmd
.
Output
()
return
nil
}
ui
.
Message
(
fmt
.
Sprintf
(
"%s"
,
out
))
func
(
p
*
Provisioner
)
knifeExec
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
node
string
,
args
[]
string
)
error
{
flags
:=
[]
string
{
"-y"
,
"-s"
,
fmt
.
Sprintf
(
"'%s'"
,
p
.
config
.
ServerUrl
),
"-k"
,
fmt
.
Sprintf
(
"'%s'"
,
p
.
config
.
ClientKey
),
"-u"
,
fmt
.
Sprintf
(
"'%s'"
,
node
),
}
if
err
!=
nil
{
cmdText
:=
fmt
.
Sprintf
(
"knife %s %s"
,
strings
.
Join
(
args
,
" "
),
strings
.
Join
(
flags
,
" "
))
if
!
p
.
config
.
PreventSudo
{
cmdText
=
"sudo "
+
cmdText
}
cmd
:=
&
packer
.
RemoteCmd
{
Command
:
cmdText
}
if
err
:=
cmd
.
StartWithUi
(
comm
,
ui
);
err
!=
nil
{
return
err
}
if
cmd
.
ExitStatus
!=
0
{
return
fmt
.
Errorf
(
"Non-zero exit status. See output above for more info."
)
}
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