# -*- mode: ruby -*-
#
# Title       : vagrantfile
# Description : A vagranfile example with some custom configuration.
# Author      : Manuela Carrasco
# Date        : Jan 21, 2019
# Usage       : vagrant [options] -- command [<args>]
# Help        : vagrant -h
#==============================================================================

# This example has custom options like "machine" but we won't show the code
# where the extra options were added.

Vagrant.configure("2") do |config| # The vagrantfile api version is 2
  # The virtual machine image. For more information
  # https://www.vagrantup.com/docs/vagrant-cloud/
  config.vm.box = "centos/7"
  # Custom configuration for virtualbox machine
  config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id,
                  "--memory", "2048"]
  end
  # Configure ansible in the VM
  config.vm.provision "ansible_local" do |ansible|
    ansible.playbook = "./site.yml"
    # Perform the playbook tasks as another user
    ansible.become = true
    # machine is a custom option for the hostname
    # and it's the playbooks name
    ansible.groups = {
      "#{machine}" => ["default"],
      "all:children" => ["#{machine}"]
    }
    # vault_id is a password file for ansible
    if not vault_id.empty?
      ansible.vault_password_file = "#{vault_id}"
    end
  end
  config.vm.hostname = "my-virtualmachine" # Set VM hostname
