chef: Resource that uses with_run_context does not trigger notifications
Description
If you write a custom resource that uses the accumulator pattern via with_run_context and edit_resource or find_resource the resulting resource does not trigger any notifications for the custom resource.
Chef Version
Chef 12.16 & 13.8
Platform Version
Tested on Ubuntu 14.04 and 16.04 with both of the above chef client versions.
Replication Case
Create an accumulator, we’ll call this one aliases:
property :address, String
property :recipients, Array
action :add do
with_run_context :root do
edit_resource(:template, "/tmp/aliases") do |new_resource|
source 'aliases.erb'
variables[:aliases] ||= {}
variables[:aliases][new_resource.address] ||= []
variables[:aliases][new_resource.address] += new_resource.recipients
action :nothing
delayed_action :create
end
end
end
Then in a recipe, consume the resource and try to attach a service reload signal:
service 'mailserver' do
supports reload: true
action :nothing
end
foo_aliases do
address 'bar'
recipients ['baz', 'quux']
notifies :reload, 'service[mailserver]'
end
After foo_aliases converges at the end of the chef run, the service will not be signaled at all.
Workaround
A workaround does not exist (to my knowledge) as the sub-resources that are created via find/edit resource do not mark the returned resource as updated.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 35 (34 by maintainers)
Commits related to this issue
- Rip out service notification hack This was a workaround to https://github.com/chef/chef/issues/6987 that was proposed by @coderanger a while back. We use a resource action to signal the parent resour... — committed to sous-chefs/postgresql by martinisoft 6 years ago
- Rip out service notification hack This was a workaround to https://github.com/chef/chef/issues/6987 that was proposed by @coderanger a while back. We use a resource action to signal the parent resour... — committed to sous-chefs/postgresql by martinisoft 6 years ago
Indeed, it feels like the resulting behaviour here is definitely surprising, even if it is as coded.
I’m certain you can hack it up with raw ruby to work right now…