3

Let me walk you through my steps.

  • I have a node with a base RHEL 5.10 OS; the /etc/hosts file is empty
  • Running the CLI "hostname -f" gives server1-nodex.domain.com, which is correct
  • I bootstrap the node successfully; when I do a "knife node show node_name" I see the correct FQDN, e.g., server1-nodex.domain.com
  • I run a recipe with creates a /etc/hosts file, and puts it in this format; note the alias (nodex) after the IP. I NEED it in this format!

    10.22.10.10 nodex server1-nodex.domain.com

  • Now if I do a knife node show node_name Chef shows the FQDN to be "nodex." Huh???
  • Sure enough running the CLI "hostname -f" also gives "nodex" Huh???
  • Just to test, I stat over, but create the /etc/hosts file in this format; note the alias now appears after the FQDN in the line (I don't need it this way)

    10.22.10.10 server1-nodex.domain.com nodex

  • Now if I do a knife node show node_name, Chef shows the correct FQDN, so does "hostname -f"

Why does Chef do this to my FQDN based on what's in the /etc/hosts file? I have a pre-Chef configuration process (shell scripts) that configures the /etc/hosts file the way I want it, and the FQDN does NOT get affected?

Is this a "bug" or at least an undesirable side effect in Chef?

Chris F
  • 14,337
  • 30
  • 94
  • 192
  • Related to this post? http://serverfault.com/questions/353158/why-does-chef-list-my-node-name-as-localhost – Chris F Aug 22 '14 at 01:22

2 Answers2

1

I am pretty sure this is not Chef's fault, but the init scripts on your Linux box. They read /etc/hosts to determine how to set the hostname.

Look in /etc/sysconfig/network-scripts

You should be able to override this in /etc/sysconfig/network.

sethvargo
  • 26,739
  • 10
  • 86
  • 156
  • Don't those scripts only run when the network is restarted? I don't restart the network during my Chef recipe runs. Yes I believe I will go the /etc/sysconfig/network route – Chris F Aug 22 '14 at 02:06
  • I updated my /etc/sysconfig/network file per http://serverfault.com/questions/353158/why-does-chef-list-my-node-name-as-localhost and it works now. – Chris F Aug 22 '14 at 12:57
1

The hosts file format is:

IP_address canonical_hostname [aliases...]

That is, the first hostname after the IP address is the unique name for this system and anything after that is an alias. You have them reversed in your example.

Typically by default your resolver is configured to look in your hosts file for hostnames first, then use the DNS system (see /etc/resolv.conf and /etc/host.conf). So running 'hostname -f' on your system to get the FQDN is going to be affected by your changes to your /etc/hosts file.

Chef (ohai) uses the resolver to get the fqdn. Since you're changes to /etc/hosts is changing the resolver's answer, it is changing Chef's answer.

btm
  • 11
  • 1