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
539e3b48
Commit
539e3b48
authored
Sep 05, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'cfortier2-add-chef-environment'
parents
c9cc82d8
802168f4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
2 deletions
+28
-2
provisioner/chef-client/provisioner.go
provisioner/chef-client/provisioner.go
+9
-2
provisioner/chef-client/provisioner_test.go
provisioner/chef-client/provisioner_test.go
+16
-0
website/source/docs/provisioners/chef-client.html.markdown
website/source/docs/provisioners/chef-client.html.markdown
+3
-0
No files found.
provisioner/chef-client/provisioner.go
View file @
539e3b48
...
...
@@ -20,6 +20,7 @@ import (
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
ChefEnvironment
string
`mapstructure:"chef_environment"`
ConfigTemplate
string
`mapstructure:"config_template"`
ExecuteCommand
string
`mapstructure:"execute_command"`
InstallCommand
string
`mapstructure:"install_command"`
...
...
@@ -47,6 +48,7 @@ type ConfigTemplate struct {
ServerUrl
string
ValidationKeyPath
string
ValidationClientName
string
ChefEnvironment
string
}
type
ExecuteTemplate
struct
{
...
...
@@ -75,6 +77,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
errs
:=
common
.
CheckUnusedConfig
(
md
)
templates
:=
map
[
string
]
*
string
{
"chef_environment"
:
&
p
.
config
.
ChefEnvironment
,
"config_template"
:
&
p
.
config
.
ConfigTemplate
,
"node_name"
:
&
p
.
config
.
NodeName
,
"staging_dir"
:
&
p
.
config
.
StagingDir
,
...
...
@@ -206,7 +209,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
}
configPath
,
err
:=
p
.
createConfig
(
ui
,
comm
,
nodeName
,
serverUrl
,
remoteValidationKeyPath
,
p
.
config
.
ValidationClientName
)
ui
,
comm
,
nodeName
,
serverUrl
,
remoteValidationKeyPath
,
p
.
config
.
ValidationClientName
,
p
.
config
.
ChefEnvironment
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Error creating Chef config file: %s"
,
err
)
}
...
...
@@ -260,7 +263,7 @@ func (p *Provisioner) uploadDirectory(ui packer.Ui, comm packer.Communicator, ds
return
comm
.
UploadDir
(
dst
,
src
,
nil
)
}
func
(
p
*
Provisioner
)
createConfig
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
nodeName
string
,
serverUrl
string
,
remoteKeyPath
string
,
validationClientName
string
)
(
string
,
error
)
{
func
(
p
*
Provisioner
)
createConfig
(
ui
packer
.
Ui
,
comm
packer
.
Communicator
,
nodeName
string
,
serverUrl
string
,
remoteKeyPath
string
,
validationClientName
string
,
chefEnvironment
string
)
(
string
,
error
)
{
ui
.
Message
(
"Creating configuration file 'client.rb'"
)
// Read the template
...
...
@@ -285,6 +288,7 @@ func (p *Provisioner) createConfig(ui packer.Ui, comm packer.Communicator, nodeN
ServerUrl
:
serverUrl
,
ValidationKeyPath
:
remoteKeyPath
,
ValidationClientName
:
validationClientName
,
ChefEnvironment
:
chefEnvironment
,
})
if
err
!=
nil
{
return
""
,
err
...
...
@@ -552,4 +556,7 @@ validation_key "{{.ValidationKeyPath}}"
{{if ne .NodeName ""}}
node_name "{{.NodeName}}"
{{end}}
{{if ne .ChefEnvironment ""}}
environment "{{.ChefEnvironment}}"
{{end}}
`
provisioner/chef-client/provisioner_test.go
View file @
539e3b48
...
...
@@ -22,6 +22,22 @@ func TestProvisioner_Impl(t *testing.T) {
}
}
func
TestProvisionerPrepare_chefEnvironment
(
t
*
testing
.
T
)
{
var
p
Provisioner
config
:=
testConfig
()
config
[
"chef_environment"
]
=
"some-env"
err
:=
p
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
p
.
config
.
ChefEnvironment
!=
"some-env"
{
t
.
Fatalf
(
"unexpected: %#v"
,
p
.
config
.
ChefEnvironment
)
}
}
func
TestProvisionerPrepare_configTemplate
(
t
*
testing
.
T
)
{
var
err
error
var
p
Provisioner
...
...
website/source/docs/provisioners/chef-client.html.markdown
View file @
539e3b48
...
...
@@ -36,6 +36,9 @@ The reference of available configuration options is listed below. No
configuration is actually required, but
`node_name`
is recommended
since it will allow the provisioner to clean up the node/client.
*
`chef_environment`
(string) - The name of the chef_environment sent to the
Chef server. By default this is empty and will not use an environment.
*
`config_template`
(string) - Path to a template that will be used for
the Chef configuration file. By default Packer only sets configuration
it needs to match the settings set in the provisioner configuration. If
...
...
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