Vagrant: setting hostname fails for Ubuntu 15.10 VM

Created on 30 Nov 2015  路  13Comments  路  Source: hashicorp/vagrant

Failure occurred when the line: config.vm.hostname = 'onevm' was added to the Vagrantfile.
Prior to adding this setting the VM would start up correctly. (VM does have the correct new hostname if halted and restarted)

Problem seems to be that on 15.10 the hostname start/restart command e.g.: service hostname restart or the systemd version: systemctl restart hostname fail with error:

Failed to start hostname.service: Unit hostname.service is masked.

The command: sudo hostname onevm seemed to work correctly, although I think the correct command fo systemd-type systems should be:

sudo hostnamectl --static set-hostname onevm

Here is the snippet debugging output for the setting of the hostname:

==> onevm: Setting hostname...
DEBUG ssh: Checking whether SSH is ready...
DEBUG ssh: Re-using SSH connection.
 INFO ssh: SSH is ready!
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute:  (sudo=false)
DEBUG ssh: Exit status: 0
DEBUG guest: Searching for cap: change_host_name
DEBUG guest: Checking in: ubuntu
DEBUG guest: Found cap: change_host_name in ubuntu
 INFO guest: Execute capability: change_host_name [#<Vagrant::Machine: onevm (VagrantPlugins::ProviderVirtualBox::Provider)>, "onevm"] (ubuntu)
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: hostname -f (sudo=true)
DEBUG ssh: stderr: mesg: ttyname failed: Inappropriate ioctl for device

DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: echo; printf $SSH_AUTH_SOCK (sudo=false)
DEBUG ssh: stdout: 
/tmp/ssh-DDFbm1qv12/agent.729
DEBUG ssh: Exit status: 0
 INFO ssh: Setting SSH_AUTH_SOCK remotely: /tmp/ssh-DDFbm1qv12/agent.729
DEBUG ssh: stdout: vagrant.vm

DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: [ `lsb_release -c -s` = vivid ] (sudo=false)
DEBUG ssh: Exit status: 1
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: echo 'onevm' > /etc/hostname (sudo=true)
DEBUG ssh: stderr: mesg: ttyname failed: Inappropriate ioctl for device

DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: echo; printf $SSH_AUTH_SOCK (sudo=false)
DEBUG ssh: stdout: 
/tmp/ssh-DDFbm1qv12/agent.729
DEBUG ssh: Exit status: 0
 INFO ssh: Setting SSH_AUTH_SOCK remotely: /tmp/ssh-DDFbm1qv12/agent.729
DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: grep 'vagrant.vm' /etc/hosts (sudo=false)
DEBUG ssh: stdout: 127.0.1.1    vagrant.vm  vagrant

DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: sed -ri 's@^(([0-9]{1,3}\.){3}[0-9]{1,3})\s+vagrant\.vm(\s.*)?$@\1 onevm onevm@g' /etc/hosts (sudo=true)
DEBUG ssh: stderr: mesg: ttyname failed: Inappropriate ioctl for device

DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: echo; printf $SSH_AUTH_SOCK (sudo=false)
DEBUG ssh: stdout: 
/tmp/ssh-DDFbm1qv12/agent.729
DEBUG ssh: Exit status: 0
 INFO ssh: Setting SSH_AUTH_SOCK remotely: /tmp/ssh-DDFbm1qv12/agent.729
DEBUG ssh: Exit status: 0
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: [ `lsb_release -c -s` = hardy ] (sudo=false)
DEBUG ssh: Exit status: 1
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: [ `lsb_release -c -s` = vivid ] (sudo=false)
DEBUG ssh: Exit status: 1
DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: service hostname start (sudo=true)
DEBUG ssh: stderr: sudo: unable to resolve host vagrant

DEBUG ssh: stderr: mesg: ttyname failed: Inappropriate ioctl for device

DEBUG ssh: Re-using SSH connection.
 INFO ssh: Execute: echo; printf $SSH_AUTH_SOCK (sudo=false)
DEBUG ssh: stdout: 

DEBUG ssh: stdout: /tmp/ssh-DDFbm1qv12/agent.729
DEBUG ssh: Exit status: 0
 INFO ssh: Setting SSH_AUTH_SOCK remotely: /tmp/ssh-DDFbm1qv12/agent.729
DEBUG ssh: stderr: Failed to start hostname.service: Unit hostname.service is masked.

DEBUG ssh: Exit status: 1
ERROR warden: Error occurred: The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

service hostname start

Stdout from the command:

Stderr from the command:

sudo: unable to resolve host vagrant
mesg: ttyname failed: Inappropriate ioctl for device
Failed to start hostname.service: Unit hostname.service is masked.

Most helpful comment

Same problem with ubuntu/wily64 :-1:

All 13 comments

Running: Vagrant 1.7.4 on PC-BSD 10.2

Dupe of https://github.com/mitchellh/vagrant/issues/6577 - will be fixed in Vagrant 1.8. Thanks!

Hi there, my issue is related to this:

==> Robbie: mesg: 
==> Robbie: ttyname failed
==> Robbie: : 
==> Robbie: Inappropriate ioctl for device
==> Robbie: Provisioning virtual machine...
==> Robbie: Please, wait...
==> Robbie: Installing few things for the server:...
...
$ vagrant -v
Vagrant 1.8.1

Same problem with ubuntu/wily64 :-1:

Same problem with 1.8.1 booting 16.04 on the vmware fusion provider.

same here
on wily64::

$ grep ubun Vagrantfile
config.vm.box = "ubuntu/wily64"
vagrant.vm.hostname = "ubuntu"

vagrant up:

==> vagrant: Setting hostname...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

service hostname start

Stdout from the command:

Stderr from the command:

mesg: ttyname failed: Inappropriate ioctl for device
Failed to start hostname.service: Unit hostname.service is masked.

Same on Debian Stretch with 1.8.1:

==> default: Checking if box 'fujimakishouten/debian-stretch64' is up to date...

==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
GuestAdditions 5.0.16 running --- OK.
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

/sbin/ifdown eth1 2> /dev/null

Stdout from the command:



Stderr from the command:

mesg: ttyname failed: Inappropriate ioctl for device

vagrant 1.8.1 ubuntu/xenial64 fails too

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/xenial64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/xenial64' is up to date...
==> default: Setting the name of the VM: ubuntu-xenial-16.04-cloudimg
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostly
    default: Adapter 3: bridged
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customisations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: ubuntu
    default: SSH auth method: password
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: Warning: Authentication failure. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    default: 
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

/sbin/ifdown eth1 2> /dev/null

Stdout from the command:



Stderr from the command:

sudo: unable to resolve host ubuntu-denial
mesg: ttyname failed: Inappropriate ioctl for device

ruby-2.3.1 ~/sandbox-vagrant $ vagrant -v
Vagrant 1.8.1

although, when I try to ssh into vagrant machine, it does work

ruby-2.3.1 ~/sandbox-vagrant $ vagrant ssh
Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.4.0-22-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.


_____________________________________________________________________
WARNING! Your environment specifies an invalid locale.
 The unknown environment variables are:
   LC_CTYPE=UTF-8 LC_ALL=
 This can affect your user experience significantly, including the
 ability to manage packages. You may install the locales by running:

   sudo apt-get install language-pack-UTF-8
     or
   sudo locale-gen UTF-8

To see all available language packs, run:
   apt-cache search "^language-pack-[a-z][a-z]$"
To disable this message for all users, run:
   sudo touch /var/lib/cloud/instance/locale-check.skip
_____________________________________________________________________

ubuntu@ubuntu-xenial:~$

ping @sethvargo is this a known bug or already fixed, but not released yet? (using Vagrant 1.8.4 and it still exists)

The ubuntu/xenial64 box is built wrong and horribly broken. Please note that "ubuntu" is the name of a user, not a representation of a canonical source for ubuntu images. Please try bento/ubuntu-16.04 instead. Thanks.

thanks a lot @sethvargo, your suggestion seems to work now...

hmm @sethvargo it seems as there's a more general issue, see #7508

No, I replied on there.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hesco picture hesco  路  3Comments

DreadPirateShawn picture DreadPirateShawn  路  3Comments

tomhking picture tomhking  路  3Comments

rrzaripov picture rrzaripov  路  3Comments

cbednarski picture cbednarski  路  3Comments