Chef Ideas

We believe that the best way to build software is to do it in close collaboration with the people who use it. We invite you to submit your ideas using the form below. Please be sure to include the problem for which you are solving and the benefits of implementing the idea.

We do our best to implement as many Ideas as we can. Our Product team will evaluate all submitted ideas in a timely manner and will disposition each into one of the following categories: will integrate into the product roadmap, further research is needed, unlikely to implement.

Thanks for collaborating with us!

Add Attributes Option for `chef-run`

As a `chef-run` user,

I would like to be able to pass in attributes via the CLI during a `chef-run`,

So that I can parameterize my ad-hoc tasks in a way where I can key off of said attributes, and do action/assignment therein ..

Example use case:

I want to deploy webapp-v1.23 to a target set of nodes using `remote_file` .. This means I would need to update my recipe and execute `chef-run` to make it work as expected .. What I would prefer is to be able to pass in an attribute via the CLI that I can then refer to in my recipe .. For example:

remote_file '/opt/tomcat/webapps/user.war' do
source "http://nexus.example.com/user-#{node['user_webapp_version']}"
owner "tomcat"
group "tomcat"
mode "0755"
action :create
end

And the way I would invoke it would be to do something like this:

chef-run webapp-user[1:10]-dev recipes/deploy.rb --node-attr 'user_webapp_version=1.23'

This will enable me to use `chef-run` as my tool of choice via my automation platform (Jenkins, etc.) to perform ad-hoc tasks against target nodes, where I could create an automation "job", pass it parameters, trigger said job, git clone my automation code, and let `chef-run` :dothething: ..

So a possible rebuttal: "Greg, that info should be in code, not as some parameter that is passed in via the CLI, this is not the Chef way" .. I agree !! But since there is no way to generically assign attributes to targets, there is a way where this same feature could be used to key off of a CLI parameter to refer to code .. Here is an example:

# attributes/default.rb
default['user_webapp_version'] = {
'dev' => 1.23,
'stage' => 1.22,
'prod' => 1.21
}
# recipes/deploy.rb
node_enviro = node['node_enviro']

remote_file '/opt/tomcat/webapps/user.war' do
source "http://nexus.example.com/user-#{node['user_webapp_version'][node_enviro]}"
owner "tomcat"
group "tomcat"
mode "0755"
action :create
end

And the way I would invoke it would be to do something like this:

chef-run webapp-user[1:10]-dev recipes/deploy.rb --node-attr 'node_enviro="dev"'

Addendum: I want to be able to use this `--node-attr` option multiple times via the same execution .. For example:

chef-run webapp-user[1:10]-dev recipes/deploy.rb --node-attr 'user_webapp_version="1.23"' --node-attr 'restart_webapp=false'

  • Gregory Spranger
  • Jul 18 2019
  • Currently Declined
  • Attach files
  • Jessica Yan commented
    11 Sep, 2019 08:39pm

    Reviewed idea w/ Engineering and agreed that the feature is reasonable to add to workstation. Item will be added to backlog for prioritization. TBD on timeline for when this feature will be available.