Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provisioner/chef: Support named run-lists for Policyfiles #11215

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions builtin/provisioners/chef/resource_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type Provisioner struct {
PolicyName string `mapstructure:"policy_name"`
HTTPProxy string `mapstructure:"http_proxy"`
HTTPSProxy string `mapstructure:"https_proxy"`
NamedRunList string `mapstructure:"named_run_list"`
NOProxy []string `mapstructure:"no_proxy"`
NodeName string `mapstructure:"node_name"`
OhaiHints []string `mapstructure:"ohai_hints"`
Expand Down Expand Up @@ -598,9 +599,12 @@ func (p *Provisioner) runChefClientFunc(
var cmd string

// Policyfiles do not support chef environments, so don't pass the `-E` flag.
if p.UsePolicyfile {
switch {
case p.UsePolicyfile && p.NamedRunList == "":
cmd = fmt.Sprintf("%s -j %q", chefCmd, fb)
} else {
case p.UsePolicyfile && p.NamedRunList != "":
cmd = fmt.Sprintf("%s -j %q -n %q", chefCmd, fb, p.NamedRunList)
default:
cmd = fmt.Sprintf("%s -j %q -E %q", chefCmd, fb, p.Environment)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more idiomatic Go (and a little cleaner to read) to write this as follows:

// Policyfiles do not support chef environments, so don't pass the `-E` flag.
switch {
case p.UsePolicyfile && p.NamedRunList == "":
  cmd = fmt.Sprintf("%s -j %q", chefCmd, fb)
case p.UsePolicyfile && p.NamedRunList != "":
  cmd = fmt.Sprintf("%s -j %q -n %q", chefCmd, fb, p.NamedRunList)
default:			}
  cmd = fmt.Sprintf("%s -j %q -E %q", chefCmd, fb, p.Environment)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, that's cleaner. Thanks for the suggestion!


Expand Down
9 changes: 7 additions & 2 deletions website/source/docs/provisioners/chef.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ The following arguments are supported:

* `https_proxy (string)` - (Optional) The proxy server for Chef Client HTTPS connections.

* `named_run_list (string)` - (Optional) The name of an alternate run-list to invoke during the
initial Chef Client run. The run-list must already exist in the Policyfile that defines
`policy_name`. Only applies when `use_policyfile` is `true`.

* `no_proxy (array)` - (Optional) A list of URLs that should bypass the proxy.

* `node_name (string)` - (Required) The name of the node to register with the Chef Server.
Expand All @@ -113,9 +117,10 @@ The following arguments are supported:
* `recreate_client (boolean)` - (Optional) If `true`, first delete any existing Chef Node and
Client before registering the new Chef Client.

* `run_list (array)` - (Required) A list with recipes that will be invoked during the initial
* `run_list (array)` - (Optional) A list with recipes that will be invoked during the initial
Chef Client run. The run-list will also be saved to the Chef Server after a successful
initial run.
initial run. Required if `use_policyfile` is `false`; ignored when `use_policyfile` is `true`
(see `named_run_list` to specify a run-list defined in a Policyfile).

* `secret_key (string)` - (Optional) The contents of the secret key that is used
by the Chef Client to decrypt data bags on the Chef Server. The key will be uploaded to the remote
Expand Down