Check for attribute in Chef recipe: Not an easy task
The doc says n.attributes?(“hostname”), but that failed me and took some time to understand. I had to check for nilness, too:
if ! (n.attributes?(“hostname”) and n[‘hostname’] != nil)
Chef::Log.info(“Not adding node: #{n} – no hostname. Not bootstrapped correctly?”)
next
else
Chef::Log.info(“Found hostname attr for #{n}”)
end
Leave a Comment