Vagrant

Debugging

For debugging purposes it can be very(!) helpfull to actually see what's going on on the system.

Either of this commands should work:

VAGRANT_LOG=debug vagrant up <machine>

# or

vagrant up --debug <machine>

Error

An error occurred during installation of VirtualBox Guest Additions 4.3.20. Some functionality may not work as intended.

Very annoying error which is discussed in details here.

Custom box(Virtualbox)

  • Install OS in VirtualBox.

Configure the box like this:

  • Create vagrant user
useradd -m -G wheel vagrant
passwd vagrant
  • Configure sudo
$ visudo
- # %wheel ....
+ %wheel
chown 0400 /home/vagrant/.ssh/authorized_keys
chown 0700 /home/vagrant/.ssh
  • Disable DNS resolving for SSH
# /etc/ssh/sshd_conf
...
- #UseDNS yes
UseDNS no
  • Install VirtualBox-guest-additions
yum install dkms kernel-header kernel-devel make gcc bzip2 perl
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
/mnt/cdrom/VBoxLinuxAdditions.run
  • Create Vagrant folder
mkdir /vagrant
chown vagrant: /vagrant
  • Shutdown and package the box:
vagrant package --base <machine-name> --output <outputfile.box>

sudo

  • Error:

Source

...
==> rhel55: Configuring and enabling network interfaces...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

cat /etc/redhat-release

Stdout from the command:

Stderr from the command:

sudo: sorry, you must have a tty to run sudo
  • Solution:

Put this line in your Vagrant file:

config.ssh.pty = true

NB: This can prevent provisioning scripts from terminating! See next error for details.

Sending SSH keep-alive

Source

Error:

When provisioning a host via Vagrant the provisioning script does not seem to terminate and the commands stays in den terminal indefinitly. This affects multiple hosts with different scripts and cannot be pinpointed to a part or command within the provisining script.

Adding more debug output shows the last, repeating command is

DEBUG ssh: Sending SSH keep-alive
DEBUG ssh: Sending SSH keep-alive
DEBUG ssh: Sending SSH keep-alive
...

Solution:

This might be related to the SSH pty that cannot be aquired during the process. Set the pty for the machine to false and try again.

config.ssh.pty = false