Skip to content
Tags

Check for attribute in Chef recipe: Not an easy task

June 27, 2012

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

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s