Renaming a node in chef

Too bad there’s no `knife node rename ‘, eh?

Here’s what you gotta do instead:

knife client delete oldname
knife node delete oldname

On the node itself:

rm /etc/chef/client.pem
sed -i 's/oldname/newname/g' /etc/chef/client.rb
ls /etc/chef/validation.pem # ensure it's there!
chef-client -N newname

This will register the new node name with chef. The runlist will be empty, so you’ll have to rebuild it. Voila!


  • Canonical Chris

    April 26, 2012

    If the client.rb contains no name already (e.g. because it is using the default), as will sometimes happen in EC2 instances, the field to add is


    Furthermore, if you keep using the -N option on the chef-client invocation, you can skip editing the client.rb file.

  • kale

    April 26, 2012

    Thanks for the info — that’s good to know! I include the bit about changing client.rb because I had one instance that wouldn’t properly register a new name despite the -N switch to chef-client; it would only register with my chef server with a new name if I modified client.rb. That case was very likely just a rare weird thing probably unrelated, but as there’s no harm in specifying the new name in cilent.rb, I do it now “just in case”.

  • will

    May 2, 2012

    Sorry to say it but a much better article is at

  • kale

    May 2, 2012

    It’s the same method, just explained differently :)

  • Janne Enberg

    February 18, 2014

    Maybe a combination of “knife node download old-node-name” and “knife node from file nodes/old-node-name.json” would help to preserve the attributes, run lists, etc.

Leave a Reply