Vagrant.require_version ">= 2.0.0"
# Require JSON module
require 'json'
# Read JSON file with config details
f = JSON.parse(File.read(File.join(File.dirname(__FILE__), 'config.json')))
# Local PATH_SRC for mounting
$PathSrc = ENV['PATH_SRC'] || "."
Vagrant.configure(2) do |config|
config.vagrant.plugins = ["vagrant-hostmanager", "vagrant-vbguest"]
# check for updates of the base image
config.vm.box_check_update = true
# wait a while longer
config.vm.boot_timeout = 1200
# disable update guest additions
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = false
end
# enable ssh agent forwarding
config.ssh.forward_agent = true
# use the standard vagrant ssh key
config.ssh.insert_key = false
# manage /etc/hosts
config.hostmanager.enabled = true
config.hostmanager.include_offline = true
config.hostmanager.manage_guest = true
config.hostmanager.manage_host = true
# Iterate through entries in JSON file
f.each do |g|
  config.vm.define g['name'] do |s|
    s.vm.box = g['box']
    s.vm.hostname = g['name']
    s.vm.network 'private_network', ip: g['ip_addr']
    s.vm.network :forwarded_port,
      host: g['forwarded_port'],
      guest: g['app_port']
    # set no_share to false to enable file sharing
    s.vm.synced_folder ".", "/vagrant", disabled: g['no_share']
    s.vm.provider :virtualbox do |virtualbox|
      virtualbox.customize ["modifyvm", :id,
        "--audio", "none",
        "--cpus", g['cpus'],
        "--memory", g['memory'],
        "--graphicscontroller", "VMSVGA",
        "--vram", "64"
      ]
      virtualbox.gui = g['gui']
      virtualbox.name = g['name']
    end
  end
end
 config.vm.provision "ansible_local" do |ansible|
  ansible.compatibility_mode = "2.0"
  ansible.galaxy_role_file = "roles/requirements.yml"
  ansible.galaxy_roles_path = "roles"
  ansible.playbook = "playbook.yml"
  ansible.verbose = "vv"
  end
end
