# Renaming a node

**URL:** <https://discourse.chef.io/t/renaming-a-node/1402>\
**Category:** Chef Infra (archive)\
**Created:** [April 2, 2010, 5:16pm UTC](https://discourse.chef.io/t/renaming-a-node/1402 "2010-04-02T17:16:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Merrells](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/john_merrells/32/825_2.png) [@John\_Merrells](https://discourse.chef.io/u/John_Merrells)\
**Post date:** [April 2, 2010, 5:16pm UTC](https://discourse.chef.io/t/renaming-a-node/1402/1 "2010-04-02T17:16:59Z")

</div>

How would I go about renaming a node?

Before you reply that I should just give the node the right name in the first place… The scenario is that I’m bootstrapping brand new machines via a hosting provider api, and when the machine first starts the only name it has is its ip address. Via that I get the RDNS provided by the hosting provider, and use that as the initial node name. Then chef runs and registers the client/node. Then the appropriate roles are applied to the node and the machine is configured and starts doing its designated job. But… the node now has a silly machine generated name… it’d be nice if I could easily rename them easily.

Thanks for any advice.

John

–  
John Merrells  
[http://johnmerrells.com](http://johnmerrells.com)  
+1.415.244.5808

---

<div class="post-metadata">

**Author:** ![Michael\_Hale](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/michael_hale/32/834_2.png) [@Michael\_Hale](https://discourse.chef.io/u/Michael_Hale)\
**Post date:** [April 2, 2010, 5:27pm UTC](https://discourse.chef.io/t/renaming-a-node/1402/2 "2010-04-02T17:27:07Z")

</div>

It sounds like you are talking about changing the hostname on the  
nodes? Here is how I do that:

> <https://github.com/mikehale/cookbooks/blob/master/hostname/recipes/default.rb>

On Fri, Apr 2, 2010 at 1:16 PM, John Merrells [john@merrells.com](mailto:john@merrells.com) wrote:

> How would I go about renaming a node?
> 
> Before you reply that I should just give the node the right name in the first place... The scenario is that I'm bootstrapping brand new machines via a hosting provider api, and when the machine first starts the only name it has is its ip address. Via that I get the RDNS provided by the hosting provider, and use that as the initial node name. Then chef runs and registers the client/node. Then the appropriate roles are applied to the node and the machine is configured and starts doing its designated job. But... the node now has a silly machine generated name.... it'd be nice if I could easily rename them easily.
> 
> Thanks for any advice.
> 
> John
> 
> --  
> John Merrells  
> [http://johnmerrells.com](http://johnmerrells.com)  
> +1.415.244.5808

---

<div class="post-metadata">

**Author:** ![John\_Merrells](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/john_merrells/32/825_2.png) [@John\_Merrells](https://discourse.chef.io/u/John_Merrells)\
**Post date:** [April 2, 2010, 5:42pm UTC](https://discourse.chef.io/t/renaming-a-node/1402/3 "2010-04-02T17:42:17Z")

</div>

On Apr 2, 2010, at 10:27 AM, Michael Hale wrote:

> It sounds like you are talking about changing the hostname on the  
> nodes? Here is how I do that:  
> [cookbooks/hostname/recipes/default.rb at master · mikehale/cookbooks · GitHub](http://github.com/mikehale/cookbooks/blob/master/hostname/recipes/default.rb)

Thanks - that's partly it.

But is there a way to rename the node object that lives within the chef sever?

I was expecting to find this....

knife node rename node\_before node\_after

But it seems that I'd have to get, create, delete to simulate a rename, having  
copied the run\_list over.

The other thing I don't grok yet is the relationship between the client name,  
the node name, and the hostname. When chef client registers itself it creates  
a client and a node with the hostname for their name and creates a certificate  
for the client.... but.... if i change the hostname of the machine is it going to  
break the authentication of the client using the client certificate? Hmm...  
thinking out load really.

John

--  
John Merrells

> **[John Merrells](https://johnmerrells.com/)**
>
> Startup Advisor | Founder Coach | Fractional CTO | Technical Due Diligence

+1.415.244.5808

---

<div class="post-metadata">

**Author:** ![Joshua\_Timberman](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/joshua_timberman/32/424_2.png) [@Joshua\_Timberman](https://discourse.chef.io/u/Joshua_Timberman)\
**Post date:** [April 2, 2010, 5:46pm UTC](https://discourse.chef.io/t/renaming-a-node/1402/4 "2010-04-02T17:46:34Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Hello!

On Apr 2, 2010, at 11:42 AM, John Merrells wrote:

> The other thing I don't grok yet is the relationship between the  
> client name,  
> the node name, and the hostname. When chef client registers itself  
> it creates  
> a client and a node with the hostname for their name and creates a  
> certificate  
> for the client.... but.... if i change the hostname of the machine  
> is it going to  
> break the authentication of the client using the client certificate?  
> Hmm...  
> thinking out load really.

Chef uses the "node\_name" value for the "client\_name" when it  
registers the new client with the API.

By default, the "node\_name" comes from the FQDN as detected by ohai  
(via hostname -f). You can override this setting in the client.rb by  
setting node\_name explicitly:

% grep node\_name /etc/chef/client.rb  
node\_name "[web1prod.example.com](http://web1prod.example.com)"

This isn't easily managable or scalable but for a one-off system it's  
okay.

* * *

Opscode, Inc  
Joshua Timberman, Senior Solutions Engineer  
C: 720.334.RUBY E: [joshua@opscode.com](mailto:joshua@opscode.com)

-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.10 (Darwin)

iEYEARECAAYFAku2LXoACgkQO97WSdVpzT0uEgCggCPKY+3J5KBR7qrL8wfJsg9n  
H2wAn117YMUvf91HcMIY1LH5Ky6BQfWs  
=KJbK  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![John\_Merrells](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/john_merrells/32/825_2.png) [@John\_Merrells](https://discourse.chef.io/u/John_Merrells)\
**Post date:** [April 2, 2010, 5:54pm UTC](https://discourse.chef.io/t/renaming-a-node/1402/5 "2010-04-02T17:54:11Z")

</div>

On Apr 2, 2010, at 10:46 AM, Joshua Timberman wrote:

> On Apr 2, 2010, at 11:42 AM, John Merrells wrote:
> 
> > The other thing I don't grok yet is the relationship between the client name,  
> > the node name, and the hostname. When chef client registers itself it creates  
> > a client and a node with the hostname for their name and creates a certificate  
> > for the client.... but.... if i change the hostname of the machine is it going to  
> > break the authentication of the client using the client certificate? Hmm...  
> > thinking out load really.
> 
> Chef uses the "node\_name" value for the "client\_name" when it registers the new client with the API.
> 
> By default, the "node\_name" comes from the FQDN as detected by ohai (via hostname -f). You can override this setting in the client.rb by setting node\_name explicitly:
> 
> % grep node\_name /etc/chef/client.rb  
> node\_name "[web1prod.example.com](http://web1prod.example.com)"
> 
> This isn't easily managable or scalable but for a one-off system it's okay.

Thanks.

I think that only helps me if I know what the hostname is going to be before chef-client runs for the first time. Currently, as a quirk of the hosting provider API the machine doesn't know that. I should probably push on that.

btw - does chef require that the hostname be resolvable? Or does it just have to look like a fqdn?

John

--  
John Merrells

> **[John Merrells](https://johnmerrells.com/)**
>
> Startup Advisor | Founder Coach | Fractional CTO | Technical Due Diligence

+1.415.244.5808

---

<div class="post-metadata">

**Author:** ![kallistec](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallistec/32/23_2.png) [@kallistec](https://discourse.chef.io/u/kallistec)\
**Post date:** [April 2, 2010, 6:01pm UTC](https://discourse.chef.io/t/renaming-a-node/1402/6 "2010-04-02T18:01:33Z")

</div>

Ohai!

Your FQDN doesn't need to resolve via DNS. Even just 'localdomain'  
will get the job done.

Dan DeLeo

On Fri, Apr 2, 2010 at 10:54 AM, John Merrells [john@merrells.com](mailto:john@merrells.com) wrote:

> On Apr 2, 2010, at 10:46 AM, Joshua Timberman wrote:
> 
> On Apr 2, 2010, at 11:42 AM, John Merrells wrote:
> 
> The other thing I don't grok yet is the relationship between the client  
> name,
> 
> the node name, and the hostname. When chef client registers itself it  
> creates
> 
> a client and a node with the hostname for their name and creates a  
> certificate
> 
> for the client.... but.... if i change the hostname of the machine is it  
> going to
> 
> break the authentication of the client using the client certificate? Hmm...
> 
> thinking out load really.
> 
> Chef uses the "node\_name" value for the "client\_name" when it registers the  
> new client with the API.
> 
> By default, the "node\_name" comes from the FQDN as detected by ohai (via  
> hostname -f). You can override this setting in the client.rb by setting  
> node\_name explicitly:
> 
> % grep node\_name /etc/chef/client.rb  
> node\_name "[web1prod.example.com](http://web1prod.example.com)"
> 
> This isn't easily managable or scalable but for a one-off system it's okay.
> 
> ## Thanks. I think that only helps me if I know what the hostname is going to be before chef-client runs for the first time. Currently, as a quirk of the hosting provider API the machine doesn't know that. I should probably push on that. btw - does chef require that the hostname be resolvable? Or does it just have to look like a fqdn? John
> 
> John Merrells  
> [http://johnmerrells.com](http://johnmerrells.com)  
> +1.415.244.5808

---

<div class="post-metadata">

**Author:** ![John\_Merrells](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/john_merrells/32/825_2.png) [@John\_Merrells](https://discourse.chef.io/u/John_Merrells)\
**Post date:** [April 2, 2010, 6:06pm UTC](https://discourse.chef.io/t/renaming-a-node/1402/7 "2010-04-02T18:06:45Z")

</div>

On Apr 2, 2010, at 11:01 AM, Daniel DeLeo wrote:

> Ohai!

Ohai! indeed. What a friendly community this is 🙂

> Your FQDN doesn't need to resolve via DNS. Even just 'localdomain'  
> will get the job done.

Ah - that's good news.

John

--  
John Merrells

> **[John Merrells](https://johnmerrells.com/)**
>
> Startup Advisor | Founder Coach | Fractional CTO | Technical Due Diligence

+1.415.244.5808

---

<div class="post-metadata">

**Author:** ![John\_Merrells](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/john_merrells/32/825_2.png) [@John\_Merrells](https://discourse.chef.io/u/John_Merrells)\
**Post date:** [April 2, 2010, 7:17pm UTC](https://discourse.chef.io/t/renaming-a-node/1402/8 "2010-04-02T19:17:32Z")

</div>

On Apr 2, 2010, at 10:46 AM, Joshua Timberman wrote:

> On Apr 2, 2010, at 11:42 AM, John Merrells wrote:
> 
> > The other thing I don't grok yet is the relationship between the client name,  
> > the node name, and the hostname. When chef client registers itself it creates  
> > a client and a node with the hostname for their name and creates a certificate  
> > for the client.... but.... if i change the hostname of the machine is it going to  
> > break the authentication of the client using the client certificate? Hmm...  
> > thinking out load really.
> 
> Chef uses the "node\_name" value for the "client\_name" when it registers the new client with the API.
> 
> By default, the "node\_name" comes from the FQDN as detected by ohai (via hostname -f). You can override this setting in the client.rb by setting node\_name explicitly:
> 
> % grep node\_name /etc/chef/client.rb  
> node\_name "[web1prod.example.com](http://web1prod.example.com)"
> 
> This isn't easily managable or scalable but for a one-off system it's okay.

I'm still stuck with this.

If the machine starts with fqdn A and the chef client registers a new node on the chef server with name A, then the client starts fine. If I then create a chef server node named B, with the webui, and then change the hostname of the machine from A to B, in /etc/hosts and /etc/hostnames and reboot, then the client silently fails to connect to the server. If I then go into client.rb and set node\_name=A then all is happy again. If I go `ohai | grep fqdn` then I do get back B.....

The only thing I can think of is that the silence is a feature of the security system.... so the client cert is now busted in some way... so the client cert must be connected to the hostname somehow?

John

--  
John Merrells

> **[John Merrells](https://johnmerrells.com/)**
>
> Startup Advisor | Founder Coach | Fractional CTO | Technical Due Diligence

+1.415.244.5808

---

<div class="post-metadata">

**Author:** ![John\_Merrells](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/john_merrells/32/825_2.png) [@John\_Merrells](https://discourse.chef.io/u/John_Merrells)\
**Post date:** [April 2, 2010, 7:39pm UTC](https://discourse.chef.io/t/renaming-a-node/1402/9 "2010-04-02T19:39:54Z")

</div>

On Apr 2, 2010, at 12:17 PM, John Merrells wrote:

> If the machine starts with fqdn A and the chef client registers a new node on the chef server with name A, then the client starts fine. If I then create a chef server node named B, with the webui, and then change the hostname of the machine from A to B, in /etc/hosts and /etc/hostnames and reboot, then the client silently fails to connect to the server. If I then go into client.rb and set node\_name=A then all is happy again. If I go `ohai | grep fqdn` then I do get back B.....
> 
> The only thing I can think of is that the silence is a feature of the security system.... so the client cert is now busted in some way... so the client cert must be connected to the hostname somehow?

Worked it out. So, yes, the client key includes the node\_name, so I had to delete /etc/chef/client.pem, making sure that the validation.pem was there, and then I restarted the chef client, which caused it to create a new client key for the new node name.

This means that the cookbook that Michael Hale pointed out...

> <https://github.com/mikehale/cookbooks/blob/master/hostname/recipes/default.rb>

...probably only works if the client.rb already contains the node\_name declaration.

John

--  
John Merrells

> **[John Merrells](https://johnmerrells.com/)**
>
> Startup Advisor | Founder Coach | Fractional CTO | Technical Due Diligence

+1.415.244.5808
