Is there anyway to add ‘include_recipe’ to a library method, then use that method in both the recipe context as well as resource context?
An example of this is below.
class MyApp
Recipe Helpers
module Helper
def license
if node[‘use_vault’]
include_recipe 'chef-vault’
chef_vault_item(node[‘data_bag’], node[‘data_bag_item’])[‘license’]
else
node[‘myapp’][‘license’]
end
end
end
end
Chef::Recipe.send(:include, MyApp::Helper)
Chef::Resource.send(:include, MyApp::Helper)
Works:
my_license = license
template ‘/etc/my.cfg’ do
variables(:license => my_license)
end
Doesn’t work:
template ‘/etc/my.cfg’ do
variables(:license => license)
end
[2014-02-06T15:49:13+00:00] ERROR: undefined method `include_recipe’ for Chef::Resource::Template
Thanks,
Curtis