I\'m using chef-cookbook-hostname cookbook to setup node\'s hostname. I don\'t want my hostname to be hard coded in the attribute file (default[\'set_fqdn\']).
In
I found this in the Chef docs. I ran into a similar issue. I am going to try the node.run_state
. This information is found at the bottom of this page https://docs.chef.io/recipes.html
Use
node.run_state
to stash transient data during a chef-client run. This data may be passed between resources, and then evaluated during the execution phase.run_state
is an empty Hash that is always discarded at the end of the chef-client run.For example, the following recipe will install the Apache web server, randomly choose PHP or Perl as the scripting language, and then install that scripting language:
package "httpd" do action :install end ruby_block "randomly_choose_language" do block do if Random.rand > 0.5 node.run_state['scripting_language'] = 'php' else node.run_state['scripting_language'] = 'perl' end end end package "scripting_language" do package_name lazy { node.run_state['scripting_language'] } action :install end