Search code examples
rubychef-infracookbookrecipe

Chef - print log at the end of statement if source isn't valid


this is my code:

if node['app']['source']
    src = "#{node['app']['source']}\\#{node['app']['file_name']}"
else 
    src = "second_source"
end

I want to add a log.warn at the end of my statement in case of any source isn't valid, something like:

if node['app']['source']
    src = "#{node['app']['source']}\\#{node['app']['file_name']}"
else 
    src = "second_source"
whatever
    Chef::Log.warn "This path #{src} is not supported, check attributes again"
    return
end

I will glad if somebody has an any idea, Thank you...


Solution

  • That isn't how code works, a condition can either be true or false, and the two branches of if/else cover both cases. You would have to come up with a way to check if a source is valid and use if/elsif/else or similar.