Possibilities for node_name in Chef client configuration

The default client.rb setting for node_name is “what Ohai determined to
be the FQDN of the node”

In our environment, this causes a total mess. Due to many factors
outside of our control:

  • node[‘fqdn’] for some nodes is of the form: foo
  • node[‘fqdn’] for some nodes is of the form: foo.DOMAIN
  • node[‘fqdn’] for some nodes is of the form: foo.domain

That’s a real party when using knife, let me tell you.

Because of this, we clearly want to normalize our node object names.

How does one reference the current node object in client.rb so that I
can effectively do something like:

def site_normalize
  # stuff
end

node_name site_normalize(the_node_fqdn)

Set node_name to what you want in /etc/chef/client.rb.

Or, write a library in a cookbook that is something like

module Normalize
  def site_name
    # stuff, where @name is the node name
  end
end

Chef::Node.extend(Normalize)

Then you can call it with:

node.site_name

From anywhere.

Adam

On Mon, Jun 9, 2014 at 7:45 AM, Jeff Blaine jblaine@kickflop.net wrote:

The default client.rb setting for node_name is "what Ohai determined to
be the FQDN of the node"

In our environment, this causes a total mess. Due to many factors
outside of our control:

  • node['fqdn'] for some nodes is of the form: foo
  • node['fqdn'] for some nodes is of the form: foo.DOMAIN
  • node['fqdn'] for some nodes is of the form: foo.domain

That's a real party when using knife, let me tell you.

Because of this, we clearly want to normalize our node object names.

How does one reference the current node object in client.rb so that I
can effectively do something like:

def site_normalize
  # stuff
end

node_name site_normalize(the_node_fqdn)

--
Opscode, Inc.
Adam Jacob, Chief Dev Officer
T: (206) 619-7151 E: adam@opscode.com

At the point the config is loaded, the name has no default value (or rather, the default is nil). It is only later that the default value is inserted if unset in the config (https://github.com/opscode/chef/blob/master/lib/chef/client.rb#L296). If you want to fix this, your base best is just hardwire node_name in the config file at bootstrap time based on some canonical name.

--Noah

On Jun 9, 2014, at 7:45 AM, Jeff Blaine jblaine@kickflop.net wrote:

The default client.rb setting for node_name is "what Ohai determined to
be the FQDN of the node"

In our environment, this causes a total mess. Due to many factors
outside of our control:

  • node['fqdn'] for some nodes is of the form: foo
  • node['fqdn'] for some nodes is of the form: foo.DOMAIN
  • node['fqdn'] for some nodes is of the form: foo.domain

That's a real party when using knife, let me tell you.

Because of this, we clearly want to normalize our node object names.

How does one reference the current node object in client.rb so that I
can effectively do something like:

def site_normalize
# stuff
end

node_name site_normalize(the_node_fqdn)

Thanks Noah and Adam.

Set node_name to what you want in /etc/chef/client.rb.

Well yeah, that's what I'm trying to do :slight_smile:

What I've learned is that chef-client has not gathered ohai
data before it loads this config file, so ohai['fqdn'] is
not available for munging in client.rb as such:

node_name ohai['fqdn'].downcase.gsub('domain.com', '')

Not a big deal there. We already use the chef-client cookbook
and can do the munging there in our wrapper for it.

Is the node name used as any sort of input data for that node's
client key generation?

If so, obviously renaming our node objects is going to require
rekeying everything.

Or, write a library in a cookbook that is something like

module Normalize
  def site_name
    # stuff, where @name is the node name
  end
end

Chef::Node.extend(Normalize)

Then you can call it with:

node.site_name

From anywhere.

... except client.rb.

On Mon, Jun 9, 2014 at 7:45 AM, Jeff Blaine <jblaine@kickflop.net
mailto:jblaine@kickflop.net> wrote:

The default client.rb setting for node_name is "what Ohai determined to
be the FQDN of the node"

In our environment, this causes a total mess. Due to many factors
outside of our control:

* node['fqdn'] for some nodes is of the form: foo
* node['fqdn'] for some nodes is of the form: foo.DOMAIN
* node['fqdn'] for some nodes is of the form: foo.domain

That's a real party when using knife, let me tell you.

Because of this, we clearly want to normalize our node *object* names.

How does one reference the current node object in client.rb so that I
can effectively do something like:

    def site_normalize
      # stuff
    end

    node_name site_normalize(the_node_fqdn)

--
Opscode, Inc.
Adam Jacob, Chief Dev Officer
T: (206) 619-7151 E: adam@opscode.com mailto:adam@opscode.com

On Jun 9, 2014, at 12:26 PM, Jeff Blaine jblaine@kickflop.net wrote:

Thanks Noah and Adam.

Set node_name to what you want in /etc/chef/client.rb.

Well yeah, that's what I'm trying to do :slight_smile:

What I've learned is that chef-client has not gathered ohai
data before it loads this config file, so ohai['fqdn'] is
not available for munging in client.rb as such:

node_name ohai['fqdn'].downcase.gsub('domain.com', '')

Not a big deal there. We already use the chef-client cookbook
and can do the munging there in our wrapper for it.

Is the node name used as any sort of input data for that node's
client key generation?

If so, obviously renaming our node objects is going to require
rekeying everything.

Yes, the node name is used as the API client username as well. Unfortunately fixing this is kind of a pain, but you can make a little script using chef-api or pychef to do the bulk of the copying work.

--Noah