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

Unable to set hostname on Ubuntu 16.04 box #7288

Closed
josebolos opened this Issue May 4, 2016 · 14 comments

Comments

Projects
None yet
9 participants
@josebolos

josebolos commented May 4, 2016

I am using the ubuntu/xenial64 box from here: https://atlas.hashicorp.com/ubuntu/boxes/xenial64

In my vagrantfile, I have:

config.vm.hostname = "xenial1234"

After booting up, setting the hostname fails:

The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

hostname -f

Stdout from the command:



Stderr from the command:

sudo: unable to resolve host ubuntu-xenial: Connection timed out
mesg: ttyname failed: Inappropriate ioctl for device
hostname: Temporary failure in name resolution

Changing to trusty64 fixes the problem.

Vagrant version

Vagrant 1.8.1

Host operating system

OS X 10.11.4

Guest operating system

Ubuntu 16.04 Xenial Xerus

Virtualisation software

VirtualBox 5.0.20

Vagrantfile

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/xenial64"
  config.vm.hostname = "xenial1234"
end

Debug

https://gist.github.com/joseluisbolos/889e7925a23d7fa0f19b4ae920b081e9

References

This seems to be similar (but not necessarily the same) to: #4784 #5947 #6577 #6616

@macnibblet

This comment has been minimized.

Show comment
Hide comment
@macnibblet

macnibblet May 4, 2016

I have the same issue, pretty much blocking my development 👎

macnibblet commented May 4, 2016

I have the same issue, pretty much blocking my development 👎

@krzysbaranski

This comment has been minimized.

Show comment
Hide comment
@krzysbaranski

krzysbaranski May 4, 2016

it's likely that this is box issue not vagrant bug.
temporary fix:

  # fix hosts ubuntu/xenial
  echo 127.0.0.1 `hostname` |sudo tee -a /etc/hosts

Another thing in xenial #7241 is that vagrant expects eth1 & eth2 interfaces in box, to fix that run

  # fix network ubuntu/xenial
  # disable Predictable Network Interface Names
  ip a show dev eth1 > /dev/null
  if (($? > 0)); then
    echo "#### eth1 not exists (eth1 and eth2 is expected by vagrant)"
    echo "#### turning off Predictable Network Interface Names"
    grep -q "net.ifnames=0" /etc/default/grub
    if (($? > 0)); then
      echo "GRUB_CMDLINE_LINUX=\"net.ifnames=0"\" | sudo tee -a /etc/default/grub
      sudo update-grub
      echo "#### restart box to disable Predictable Network Interface Names"
    fi
  fi

krzysbaranski commented May 4, 2016

it's likely that this is box issue not vagrant bug.
temporary fix:

  # fix hosts ubuntu/xenial
  echo 127.0.0.1 `hostname` |sudo tee -a /etc/hosts

Another thing in xenial #7241 is that vagrant expects eth1 & eth2 interfaces in box, to fix that run

  # fix network ubuntu/xenial
  # disable Predictable Network Interface Names
  ip a show dev eth1 > /dev/null
  if (($? > 0)); then
    echo "#### eth1 not exists (eth1 and eth2 is expected by vagrant)"
    echo "#### turning off Predictable Network Interface Names"
    grep -q "net.ifnames=0" /etc/default/grub
    if (($? > 0)); then
      echo "GRUB_CMDLINE_LINUX=\"net.ifnames=0"\" | sudo tee -a /etc/default/grub
      sudo update-grub
      echo "#### restart box to disable Predictable Network Interface Names"
    fi
  fi
@josebolos

This comment has been minimized.

Show comment
Hide comment
@josebolos

josebolos May 5, 2016

Hi @krzysbaranski, I'm not sure if it's an issue with the box or with Vagrant. Thanks to your comment I've realised there are even more issues that this one is related to. For future reference: #7155 #7241

Thanks for the workaround, btw!

josebolos commented May 5, 2016

Hi @krzysbaranski, I'm not sure if it's an issue with the box or with Vagrant. Thanks to your comment I've realised there are even more issues that this one is related to. For future reference: #7155 #7241

Thanks for the workaround, btw!

@jaraco

This comment has been minimized.

Show comment
Hide comment
@jaraco

jaraco May 5, 2016

temporary fix:

How does one implement this temporary fix? I tried adding the code to the provisioning script, but vagrant up still fails with the reported error. Does the workaround need to be applied to the box first?

jaraco commented May 5, 2016

temporary fix:

How does one implement this temporary fix? I tried adding the code to the provisioning script, but vagrant up still fails with the reported error. Does the workaround need to be applied to the box first?

@krzysbaranski

This comment has been minimized.

Show comment
Hide comment
@krzysbaranski

krzysbaranski May 5, 2016

@jaraco you have to run this manually (vagrant ssh) after failed provision and reload box with provisioning

krzysbaranski commented May 5, 2016

@jaraco you have to run this manually (vagrant ssh) after failed provision and reload box with provisioning

@macnibblet

This comment has been minimized.

Show comment
Hide comment
@macnibblet

macnibblet May 6, 2016

I'm not having any success with the workaround. Anyone have any ideas on the main issue ?

macnibblet commented May 6, 2016

I'm not having any success with the workaround. Anyone have any ideas on the main issue ?

@nhojpatrick

This comment has been minimized.

Show comment
Hide comment
@nhojpatrick

nhojpatrick commented May 19, 2016

I'm seeing the same issue from the box provided by ubuntu.

https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-vagrant.box

@landam

This comment has been minimized.

Show comment
Hide comment
@landam

landam May 28, 2016

I have also the same issue with the latest box provided by ubuntu...

landam commented May 28, 2016

I have also the same issue with the latest box provided by ubuntu...

@krzysbaranski

This comment has been minimized.

Show comment
Hide comment
@krzysbaranski

krzysbaranski May 28, 2016

You can try this proposed fix #7318

krzysbaranski commented May 28, 2016

You can try this proposed fix #7318

@nhojpatrick

This comment has been minimized.

Show comment
Hide comment
@nhojpatrick

nhojpatrick May 29, 2016

That patch is for Debian not Ubuntu.

nhojpatrick commented May 29, 2016

That patch is for Debian not Ubuntu.

@nhojpatrick

This comment has been minimized.

Show comment
Hide comment
@nhojpatrick

nhojpatrick May 29, 2016

Looking at the ubuntu files I think the fixes for Vivid also need to be done for Wily and Xenial. Will look into do a patch.

nhojpatrick commented May 29, 2016

Looking at the ubuntu files I think the fixes for Vivid also need to be done for Wily and Xenial. Will look into do a patch.

@nhojpatrick

This comment has been minimized.

Show comment
Hide comment
@nhojpatrick

nhojpatrick May 31, 2016

The file (plugins/guests/ubuntu/cap/change_host_name.rb) already in master fixes host name change for ubuntu vivid, wily and also xenial as it now uses systemd. I also believe it needs the #7318 patch applied as well.

nhojpatrick commented May 31, 2016

The file (plugins/guests/ubuntu/cap/change_host_name.rb) already in master fixes host name change for ubuntu vivid, wily and also xenial as it now uses systemd. I also believe it needs the #7318 patch applied as well.

@sethvargo sethvargo added this to the 1.8.2 milestone May 31, 2016

@spotlightishere

This comment has been minimized.

Show comment
Hide comment
@spotlightishere

spotlightishere Jun 2, 2016

There's a patch (#7253) that fixed this for me. It takes a little bit more to start up boxes on the first time you start up a box (further vagrant up'd boxes won't have this problem).

spotlightishere commented Jun 2, 2016

There's a patch (#7253) that fixed this for me. It takes a little bit more to start up boxes on the first time you start up a box (further vagrant up'd boxes won't have this problem).

@mowings

This comment has been minimized.

Show comment
Hide comment
@mowings

mowings Nov 3, 2016

I realize it's a bit late for this, but if you are having issues with setting hostname on xenial, you can install libnss-myhostname in the container. This may prove useful if you don't want to upgrade vagrant to a later version.

You may also want to unlink /lib/systemd/system/hostname.service (in the container) -- this will re-enable the hostname service so that you older versions of vagrant can properly set the hostname on xenial.

mowings commented Nov 3, 2016

I realize it's a bit late for this, but if you are having issues with setting hostname on xenial, you can install libnss-myhostname in the container. This may prove useful if you don't want to upgrade vagrant to a later version.

You may also want to unlink /lib/systemd/system/hostname.service (in the container) -- this will re-enable the hostname service so that you older versions of vagrant can properly set the hostname on xenial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment