Thursday, September 22, 2011

Change chef run lists on multiple nodes with knife

Let's assume you're standing up a membase cluster and you want all of your app servers to point to it, instead of a single memcached server that you curse regularly.  Your servers are named "app1, app2, app3... appn..." and their run list is pretty basic.  Here's how to change the run list with a single command:

knife exec -E 'nodes.transform("name:app*.prod.company.com") { |n| n.run_list([ "role[base]", "recipe[membase::moxi]" ]) }'

In this case, I have appended the membase::moxi recipe to the run list, which had previously just included the base role.  Follow this up with:

knife ssh 'name:app*.prod.company.com' '/usr/bin/chef-client' and voila!  You will now run your new run list on all of your app servers.

1 comments: