2015-03-10

Removing Accidental Chef Attributes

If you've accidentally set attributes on a bunch of nodes in a way that breaks your system, you want to delete them. This can happen when you accidentally include a cookbook you didn't mean to and have some attributes set in the attributes/default.rb file.

Here's how to fix it:

for i in $(cat /tmp/hosts); do
  echo -n "$i: "
  knife exec -E "nodes.transform('name:$i') {|n| puts n.hostname ; n.normal_attrs['my_bad_attribute_name'].delete('self')}"
done

Note: replace the nested array format with underscores. In other words node['my']['bad']['attribute']['name'] becomes my_bad_attribute_name

No comments: