Skip to content

Instantly share code, notes, and snippets.

@aalmenar
Forked from scalp42/check_resource.rb
Created February 19, 2024 08:44
Show Gist options
  • Save aalmenar/9a15a997bce4fd9c1506c4f3074cf951 to your computer and use it in GitHub Desktop.
Save aalmenar/9a15a997bce4fd9c1506c4f3074cf951 to your computer and use it in GitHub Desktop.
Figure if a resource exists or not in Chef before notifying it
resource_not_found = {}
begin
resources('ruby_block[my-resource-supposed-to-exist]')
rescue Chef::Exceptions::ResourceNotFound
resource_not_found['ruby_block[my-resource-supposed-to-exist]'] = true
end
template '/etc/my/template.conf' do
source 'template.conf.erb'
mode '640'
notifies :run, 'ruby_block[my-resource-supposed-to-exist]' unless resource_not_found['ruby_block[my-resource-supposed-to-exist]']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment