Can you Notify a resource that is not explicitly defined in your cookbook?

For example, I would like to create a number of template files in a loop like this:

templates = [
    "template1",
    "template2",
    "template3"
]

templates.each do |tmp|

    template "/file/path/#{tmp}" do
        source "#{tmp}.erb"
        mode "0644"
        action :create
    end

end

However under some circumstances I would also like to use a notify statement on a particular template, like:

notifies :create, "template[/file/path/template2]", :immediately

Because no template resource for template2 is explicitly defined in the cookbook, is that “notifies” statement going to be functional?? Is there way to write the cookbook so that I can use “notifies” statements like that one while still maintaining the conciseness of building templates in a loop??

Thanks!!!

This should just work. Chef does a pass to resolve all the notifications in between the compile and converge phases, by which time all your template resources will exist.

1 Like

I love chef. Thank you.