I am trying to write my first chef custom resource. However I am unable to access properties in some other embedded resources.
I have created the following resource
property :template_shortname, String
action :setup do
node.set['apache']['version'] = '2.4'
node.set['apache']['package'] = 'apache2'
include_recipe "apache2::default"
print "the shortname is " + template_shortname
web_app "sample_app" do
server_name "server.com"
server_aliases []
docroot "/www-data"
template "prefix " + template_shortname
end
end
However when executing this I get:
From debug log
The shortname is: server
But the parameter for template_shortname contains an empty array. So it quits with:
TypeError
---------
no implicit conversion of Array into String
Cookbook Trace:
---------------
/tmp/kitchen/cache/cookbooks/phpapp/resources/setup.rb:21:in `+'
/tmp/kitchen/cache/cookbooks/phpapp/resources/setup.rb:21:in `block (2 levels) in class_from_file'
/tmp/kitchen/cache/cookbooks/phpapp/resources/setup.rb:17:in `block in class_from_file'
I am using chef-dk Chef Development Kit Version: 1.1.16 chef-client version: 12.17.44 delivery version: master (83358fb62c0f711c70ad5a81030a6cae4017f103) berks version: 5.2.0 kitchen version: 1.14.2
template "prefix #{template_shortname}"use string interpolation, not addition - Tensibainew_resource.template_shortnamefrom the doc. All in all, setting attributes like that and calling include_recipe withing an action sounds brittle and likely to bite you soon. Thos should be in your phpapp cookbook attributes file and recipe, all in all I don't get what you'r trying to do here. - Tensibaitemplateproperty ofweb_appis an array, so the+operator act as for an array and not for string. Use string interpolation and it should work, I still think attributes andinclude_recipeshould absolutely not be defined in a custom resource (makes no sense to try to install apache twice for two apps). - Tensibai