Vagrant - mwicat/personal GitHub Wiki

Install

curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"

Show running machines

vagrant global-status --prune

Turn off machine

vagrant halt ID

Enable ssh from host

vagrant ssh-config >> ~/.ssh/config

Show forwarded ports

vagrant port

Create machine from vagrantfile

vagrant up

Destroy machinef

vagrant destroy

List vms

vagrant box list

Start shell

vagrant ssh

Vagrantfile

vagrant-vbguest is a Vagrant plugin which automatically installs the host's VirtualBox Guest Additions on the guest system.

vagrant plugin install vagrant-vbguest
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.require_version ">= 1.7.0"

Vagrant.configure(2) do |config|

  # Disable the new default behavior introduced in Vagrant 1.7, to
  # ensure that all Vagrant machines will use the same SSH key pair.
  # See https://github.com/hashicorp/vagrant/issues/5005
  config.ssh.insert_key = false

  config.vm.define "www-dev" do |www|
    www.vm.box = "debian/jessie64"
    www.vm.network "forwarded_port", guest: 80, host: 8588, hostip: "127.0.0.1"
    www.vm.network "private_network", ip: "192.168.0.2"
    www.vm.synced_folder "../www/myapp", "/var/www/myapp"
  end

  config.vm.define "db-dev" do |db|
    db.vm.box = "debian/jessie64"
    db.vm.network "forwarded_port", guest: 3306, host: 3307, hostip: "127.0.0.1"
    db.vm.network "private_network", ip: "192.168.0.3"
  end

  config.vm.provision "ansible" do |ansible|
    ansible.become = true
    ansible.verbose = "v"
    ansible.playbook = "site.yml"
    ansible.groups = {
      "www" => ["www-dev"],
      "db" => ["db-dev"],
    }
  end

end