Created
November 22, 2013 21:04
-
-
Save scalp42/7606857 to your computer and use it in GitHub Desktop.
Figure if a resource exists or not in Chef before notifying it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Inspired by your code, I wrote the following:
I suspect that approaches like these aren't the most Chef ways to code this, but I'm not sure what would be a better solution. A
library
sounded like a good option, but then code is run in a different lexical scope, and that brought about more complexity, so I just used local variables.