From XennisWiki
Jump to: navigation, search

Vagrant is computer software that creates and configures virtual development environments. It can be seen as a higher-level wrapper around virtualization software such as VirtualBox, VMware, KVM and Linux Containers (LXC), and around configuration management software such as Ansible, Chef, Salt, and Puppet. (Wikipedia)


Install VirtualBox

apt-get install virtualbox virtualbox-dkms

Install Vagrant

apt-get install vagrant

Basic usage

Install a virtual machine with Ubuntu 12.04 (precise) 64-bit

vagrant init hashicorp/precise64
vagrant up

SSH to the virtual machine

vagrant ssh

(1) Reboot the VM, (2) shut it down or (3) destroy it

vagrant reload
vagrant halt
vagrant destroy

Usage with Ansible

Further information: Ansible Provisioner, Using Vagrant and Ansible

Configuration Vagrant

Create a configuration file named Vagrantfile

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| = "ubuntu/xenial64" :private_network, ip: ""

  config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--name", "ExampleApp", "--memory", "1024"]

  # Shared folder from the host machine to the guest machine. Uncomment the line
  # below to enable it.
  #config.vm.synced_folder "../../../example-app", "/webapps/exampleapp/example-app"

  # Ansible provisioner.
  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "vagrant.yml"
    #ansible.host_key_checking = false
    #ansible.verbose = "v"

Configure Ansible

According to the specified ansible.playbook create a playbook vagrant.yml


- name: Create a {{ application_name }} virtual machine via vagrant
  hosts: all
  sudo: yes
  sudo_user: root
  remote_user: vagrant
    - update_apt_cache: yes
    - env_vars/base.yml
    - env_vars/vagrant.yml

    - base
    - web


Run the Vagrant script to setup a VirtualBox and run the Ansible playbook

vagrant up


To re-run the Ansible playbook on the existing VM use: vagrant provision

See also

External links