service[datastax-agent] cannot be found in the resource collection.
eyalzek opened this issue · comments
I'm overwriting the file datastax-agent-env.sh
to fit my needs and I'm using a template
resource to do so since there is no way to do it using attributes and this cookbook (at least not one that I could find).
Here is a snippet of my recipe:
include_recipe 'cassandra-dse::opscenter_agent_datastax'
template '/etc/datastax-agent/datastax-agent-env.sh' do
source 'datastax-agent-env.sh.erb'
owner 'root'
group 'root'
mode '0644'
variables(
:agent_config => node[cookbook_name]['datastax-agent']['env']
)
notifies :restart, 'service[datastax-agent]', :delayed
end
This is not the entire recipe, but it shows what's relevant. The problem is that when trying to converge this I'm getting:
ERROR: resource template[/etc/datastax-agent/datastax-agent-env.sh] is configured to notify resource service[datastax-agent] with action restart, but service[datastax-agent] cannot be found in the resource collection.
I figured the service resource should be available to notify? As can be seen here:
https://github.com/michaelklishin/cassandra-chef-cookbook/blob/master/recipes/opscenter_agent_datastax.rb#L59
Your template
resource successfully notifies the service.
I'm sorry but this is a generic Chef question. I don't have the time to answer those, please take it to Stack Overflow.
I still don't understand why I need to define the service once again in my own recipe when it's obviously declared in the included recipe. This works without an issue for service[cassandra]
for example. But let it be
@michaelklishin this was caused by the following line:
https://github.com/michaelklishin/cassandra-chef-cookbook/blob/master/recipes/opscenter_agent_datastax.rb#L33
Would you consider adding some logging there so a user would be able to know why the included recipe is being skipped altogether? It took me long to figure this out.