boxes = {
  "freebsd-10" => {
    :box => "bento/freebsd-10.4",
    :ip  => '192.70.21.2',
    :cpu => "100",
    :ram => "512",
    :sync_type => "rsync",
    :shell_provision => "pkg install -qy lang/python",
    :host_vars => {
      "ansible_python_interpreter" => "/usr/local/bin/python",
    },
  },
  "debian-9" => {
    :box => "bento/debian-9.3",
    :ip  => '192.70.21.3',
    :cpu => "100",
    :ram => "512",
  },
  "windows-2012" => {
    :box => "elastic/windows-2012_r2-x86_64",
    :ip  => '192.70.21.4',
    :cpu => "100",
    :ram => "1024",
    :host_vars => {
      "ansible_winrm_scheme" => "http",
    },
  },
  "windows-2016" => {
    :box => "elastic/windows-2016-x86_64",
    :ip  => '192.70.21.5',
    :cpu => "100",
    :ram => "1024",
    :host_vars => {
      "ansible_winrm_scheme" => "http",
    },
  },
}

groups = {
  "windows" => ["windows-2012", "windows-2016"],
  "unix"  =>   ["freebsd-10", "debian-9"],
}

Vagrant.configure("2") do |config|
  host_vars = Hash.new
  boxes.each do |box_name, box|
    host_vars[box_name] = box[:host_vars]
  end

  boxes.each do |box_name, box|
    config.vm.define box_name do |machine|
      machine.vm.box = box[:box]
      machine.vm.hostname = "%s" % box_name

      machine.vm.provider "virtualbox" do |v|
        v.customize ["modifyvm", :id, "--cpuexecutioncap", box[:cpu]]
        v.customize ["modifyvm", :id, "--memory",          box[:ram]]
      end

      machine.vm.network :private_network, ip: box[:ip]

      host_dir = "../"
      mount_point = "/home/vagrant/go/src/github.com/elastic/go-sysinfo"
      if box_name =~ /^windows/
        host_dir = ".gopath_mount/"
        mount_point = "c:\\Users\\vagrant\\go"
      end
      machine.vm.synced_folder host_dir, mount_point,
        type: box[:sync_type], owner: "vagrant", group: "vagrant", create: true,
        rsync__exclude: ["testing", ".git"]

      if box.has_key?(:shell_provision)
        machine.vm.provision "shell",
          inline: box[:shell_provision]
      end

      machine.vm.provision :ansible do |ansible|
        ansible.playbook_command = "ve/bin/ansible-playbook"
        ansible.playbook = "ansible/main.yml"
        ansible.verbose = ENV['ANSIBLE_VERBOSE'] ||= "v"
        ansible.tags = ENV['ANSIBLE_TAGS'] ||= "setup"
        ansible.host_vars = host_vars
        ansible.groups = groups
      end
    end
  end
end
