Vagrant How To

How to cleanup unused vagrant boxes

cleanup vagrant

vagrant global-status --prune
vagrant box prune

How to pass environment variables from host to guest during provisioning

Add , env: {"CX_ZIP_PWD" => ENV['CX_ZIP_PWD']} to the end of the config.vm.provision line

How to configure audio interface

vb.customize ["modifyvm", :id, "--audio", "pulse", "--audiocontroller", "hda", "--audioout", "on", "--audioin", "on"] # YMMV

How to add personal cert to vagrant boxes

if you dont like doing vagrant ssh box, but want to do ssh to the box directly instead
vagrant ssh-config box >> /.ssh/config
or push your key on provisioning

# config.vm.provision "file", source: "~/.ssh/id_rsa.pub", destination: "~/.ssh/me.pub"
#   config.vm.provision "shell" do |s|
#    ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
#    s.inline = <<-SHELL
#      echo #{ssh_pub_key} >> /home/vagrant/.ssh/authorized_keys
#      echo #{ssh_pub_key} >> /root/.ssh/authorized_keys
#    SHELL
#  end

How to enable X11 forwarding on Vagrant and RHEL 7 or CentOS guests

vi Vagrantfile

config.ssh.forward_agent = true
config.ssh.forward_x11 = true

Start the VM, login and run
sudo yum -y -q install xorg-x11-xauth libXmu libXp libXft gtk2 libXtst xorg-x11-fonts-Type1 psmisc
to get all the x fonts and shit.
Logout from the VM and log back in
Give root the X forward when you are a 'vagrant'
sudo xauth add $(xauth list $DISPLAY)
or if you are root already:
xauth add $(su -c "xauth list $DISPLAY" vagrant)
or if you want to give it to another user who does not have sudo:
x=$(xauth list $DISPLAY); sudo su -c "xauth add $x" oracle
ignore the "file does not exist" warning
if you still have issues with the fonts make sure your X host has the same fonts installed