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
062b2270
Commit
062b2270
authored
Jun 29, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2306 from wtschreiter/knife_config_by_template
Add knife config by template
parents
1b9d0dcd
18438cf2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
10 deletions
+51
-10
provisioner/chef-client/provisioner.go
provisioner/chef-client/provisioner.go
+51
-10
No files found.
provisioner/chef-client/provisioner.go
View file @
062b2270
...
@@ -187,14 +187,20 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
...
@@ -187,14 +187,20 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
}
}
err
=
p
.
executeChef
(
ui
,
comm
,
configPath
,
jsonPath
)
err
=
p
.
executeChef
(
ui
,
comm
,
configPath
,
jsonPath
)
knifeConfigPath
,
err2
:=
p
.
createKnifeConfig
(
ui
,
comm
,
nodeName
,
serverUrl
,
p
.
config
.
ClientKey
,
p
.
config
.
SslVerifyMode
)
if
err2
!=
nil
{
return
fmt
.
Errorf
(
"Error creating knife config on node: %s"
,
err2
)
}
if
!
p
.
config
.
SkipCleanNode
{
if
!
p
.
config
.
SkipCleanNode
{
if
err2
:=
p
.
cleanNode
(
ui
,
comm
,
nodeName
);
err2
!=
nil
{
if
err2
:=
p
.
cleanNode
(
ui
,
comm
,
nodeName
,
knifeConfigPath
);
err2
!=
nil
{
return
fmt
.
Errorf
(
"Error cleaning up chef node: %s"
,
err2
)
return
fmt
.
Errorf
(
"Error cleaning up chef node: %s"
,
err2
)
}
}
}
}
if
!
p
.
config
.
SkipCleanClient
{
if
!
p
.
config
.
SkipCleanClient
{
if
err2
:=
p
.
cleanClient
(
ui
,
comm
,
nodeName
);
err2
!=
nil
{
if
err2
:=
p
.
cleanClient
(
ui
,
comm
,
nodeName
,
knifeConfigPath
);
err2
!=
nil
{
return
fmt
.
Errorf
(
"Error cleaning up chef client: %s"
,
err2
)
return
fmt
.
Errorf
(
"Error cleaning up chef client: %s"
,
err2
)
}
}
}
}
...
@@ -273,6 +279,32 @@ func (p *Provisioner) createConfig(ui packer.Ui, comm packer.Communicator, nodeN
...
@@ -273,6 +279,32 @@ func (p *Provisioner) createConfig(ui packer.Ui, comm packer.Communicator, nodeN
return
remotePath
,
nil
return
remotePath
,
nil
}
}
func
(
p
*
Provisioner
)
createKnifeConfig
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
nodeName
string
,
serverUrl
string
,
clientKey
string
,
sslVerifyMode
string
)
(
string
,
error
)
{
ui
.
Message
(
"Creating configuration file 'knife.rb'"
)
// Read the template
tpl
:=
DefaultKnifeTemplate
ctx
:=
p
.
config
.
ctx
ctx
.
Data
=
&
ConfigTemplate
{
NodeName
:
nodeName
,
ServerUrl
:
serverUrl
,
ClientKey
:
clientKey
,
SslVerifyMode
:
sslVerifyMode
,
}
configString
,
err
:=
interpolate
.
Render
(
tpl
,
&
ctx
)
if
err
!=
nil
{
return
""
,
err
}
remotePath
:=
filepath
.
ToSlash
(
filepath
.
Join
(
p
.
config
.
StagingDir
,
"knife.rb"
))
if
err
:=
comm
.
Upload
(
remotePath
,
bytes
.
NewReader
([]
byte
(
configString
)),
nil
);
err
!=
nil
{
return
""
,
err
}
return
remotePath
,
nil
}
func
(
p
*
Provisioner
)
createJson
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
)
(
string
,
error
)
{
func
(
p
*
Provisioner
)
createJson
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
)
(
string
,
error
)
{
ui
.
Message
(
"Creating JSON attribute file"
)
ui
.
Message
(
"Creating JSON attribute file"
)
...
@@ -334,32 +366,30 @@ func (p *Provisioner) createDir(ui packer.Ui, comm packer.Communicator, dir stri
...
@@ -334,32 +366,30 @@ func (p *Provisioner) createDir(ui packer.Ui, comm packer.Communicator, dir stri
return
nil
return
nil
}
}
func
(
p
*
Provisioner
)
cleanNode
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
node
string
)
error
{
func
(
p
*
Provisioner
)
cleanNode
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
node
string
,
knifeConfigPath
string
)
error
{
ui
.
Say
(
"Cleaning up chef node..."
)
ui
.
Say
(
"Cleaning up chef node..."
)
args
:=
[]
string
{
"node"
,
"delete"
,
node
}
args
:=
[]
string
{
"node"
,
"delete"
,
node
}
if
err
:=
p
.
knifeExec
(
ui
,
comm
,
node
,
args
);
err
!=
nil
{
if
err
:=
p
.
knifeExec
(
ui
,
comm
,
node
,
knifeConfigPath
,
args
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to cleanup node: %s"
,
err
)
return
fmt
.
Errorf
(
"Failed to cleanup node: %s"
,
err
)
}
}
return
nil
return
nil
}
}
func
(
p
*
Provisioner
)
cleanClient
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
node
string
)
error
{
func
(
p
*
Provisioner
)
cleanClient
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
node
string
,
knifeConfigPath
string
)
error
{
ui
.
Say
(
"Cleaning up chef client..."
)
ui
.
Say
(
"Cleaning up chef client..."
)
args
:=
[]
string
{
"client"
,
"delete"
,
node
}
args
:=
[]
string
{
"client"
,
"delete"
,
node
}
if
err
:=
p
.
knifeExec
(
ui
,
comm
,
node
,
args
);
err
!=
nil
{
if
err
:=
p
.
knifeExec
(
ui
,
comm
,
node
,
knifeConfigPath
,
args
);
err
!=
nil
{
return
fmt
.
Errorf
(
"Failed to cleanup client: %s"
,
err
)
return
fmt
.
Errorf
(
"Failed to cleanup client: %s"
,
err
)
}
}
return
nil
return
nil
}
}
func
(
p
*
Provisioner
)
knifeExec
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
node
string
,
args
[]
string
)
error
{
func
(
p
*
Provisioner
)
knifeExec
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
node
string
,
knifeConfigPath
string
,
args
[]
string
)
error
{
flags
:=
[]
string
{
flags
:=
[]
string
{
"-y"
,
"-y"
,
"-s"
,
fmt
.
Sprintf
(
"'%s'"
,
p
.
config
.
ServerUrl
),
"-c"
,
knifeConfigPath
,
"-k"
,
fmt
.
Sprintf
(
"'%s'"
,
p
.
config
.
ClientKey
),
"-u"
,
fmt
.
Sprintf
(
"'%s'"
,
node
),
}
}
cmdText
:=
fmt
.
Sprintf
(
cmdText
:=
fmt
.
Sprintf
(
...
@@ -573,3 +603,14 @@ environment "{{.ChefEnvironment}}"
...
@@ -573,3 +603,14 @@ environment "{{.ChefEnvironment}}"
ssl_verify_mode :{{.SslVerifyMode}}
ssl_verify_mode :{{.SslVerifyMode}}
{{end}}
{{end}}
`
`
var
DefaultKnifeTemplate
=
`
log_level :info
log_location STDOUT
chef_server_url "{{.ServerUrl}}"
client_key "{{.ClientKey}}"
node_name "{{.NodeName}}"
{{if ne .SslVerifyMode ""}}
ssl_verify_mode :{{.SslVerifyMode}}
{{end}}
`
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