I have a recipe that sets a variable inside a ruby_block and needs to use that variable as an input attribute for a recipe. How can I use the include_recipe after the ruby_block has been executed?
Thanks
ruby_block "evaluate_config" do #~FC014
block do
file = File.read('/opt/config/baselogging.json')
data = JSON.parse(file)
node.default['kibana']['apache']['basic_auth_username'] = data['KibanaUser']
node.default['kibana']['apache']['basic_auth_password'] = data['KibanaPassword']
include_recipe 'kibana'
end
end
To include a recipe from a ruby_block, you must call it using run_context.
For example:
ruby_block "evaluate_config" do #~FC014
block do
...
#include_recipe 'kibana'
run_context.include_recipe "cookbook::recipe"
end
end
You can read and set attributes from ruby block, and than after it you can include recipe like:
ruby_block "evaluate_config" do #~FC014
block do
file = File.read('/opt/config/baselogging.json')
data = JSON.parse(file)
node.set['kibana']['apache']['basic_auth_username'] = data['KibanaUser']
node.set['kibana']['apache']['basic_auth_password'] = data['KibanaPassword']
end
end
include_recipe 'kibana'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With