New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generated /etc/hosts names are backwards #3521

anarcat opened this Issue Oct 12, 2018 · 0 comments


None yet
1 participant

anarcat commented Oct 12, 2018

The /etc/hosts files generated by kubespray are useful, but actually use an incorrect (but common) syntax, for example:

# Ansible inventory hosts BEGIN kubeadmin kube01 kube02
# Ansible inventory hosts END

Notice how the short domain name (e.g. kubeadmin) is before the fully-qualified domain name (FQDN,

This is, arguably, a very minor difference, but it has an impact over unrelated components. For example, hostname -f does not return the right domain name:

$ hostname
$ hostname -f

A properly configured host would return a FQDN for hostname -f, like this:

$ hostname
$ hostname -f

The /etc/hosts manual page is pretty clear on the topic:

For each host a single line should be present with the following information:

IP_address canonical_hostname [aliases...]

[...] Optional aliases provide for name changes, alternate spellings, shorter hostnames, or generic hostnames (for example, localhost).

The EXAMPLES section is similarly unambiguous: the FQDN comes first.

Reversing those domain names in the /etc/hosts file will fix that problem, for which I will submit a PR shortly.


  • Cloud provider or hardware configuration: baremetal
  • OS (printf "$(uname -srm)\n$(cat /etc/os-release)\n"): Linux 4.9.0-7-amd64 x86_64 Debian GNU/Linux 9 (stretch)
  • Version of Ansible (ansible --version): N/A

Kubespray version (commit) (git rev-parse --short HEAD): v2.5.0 (but also applies to later versions)

Network plugin used: calico

Copy of your inventory file:

kubeadmin        ansible_host= ip=
kube01           ansible_host= ip=
kube02           ansible_host= ip=







Command used to invoke ansible:

ansible-playbook -u root -b -i inventory/mykube/hosts.ini cluster.yml

Output of ansible run:


anarcat added a commit to anarcat/kubespray that referenced this issue Oct 12, 2018

show FQDN first in /etc/hosts (closes: kubernetes-incubator#3521)
The hosts(5) manpage clearly states that the first entry is the
"canonical name", or FQDN (Fully-Qualified Domain Name):

    IP_address canonical_hostname [aliases...]

By using the alias as a first entry, `hostname -f` does not return the
correct domain which breaks all sorts of unrelated functionality (it
has impact over email server configuration, for example).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment