Vagrant.require_version ">= 1.8.0"

linux_boxes = {
  "ubuntu-focal" => {:box => "ubuntu/focal64"},
  "ubuntu-bionic" => {:box => "ubuntu/bionic64"},
  "ubuntu-xenial" => {:box => "ubuntu/xenial64"},
  "debian-buster" => {:box => "debian/buster64"},
  "debian-stretch" => {:box => "debian/stretch64"},
  "fedora-32" => {:box => "fedora/32-cloud-base"},
  "centos-8" => {:box => "centos/8"},
  "centos-7" => {:box => "centos/7"},
  "arch-current" => {:box => "archlinux/archlinux"},
  "leap-15-2" => {:box => "opensuse/Leap-15.2.x86_64"}
}
freebsd_boxes = {
    "freebsd-11" => {:box => "freebsd/FreeBSD-11.4-STABLE"},
    "freebsd-12" => {:box => "freebsd/FreeBSD-12.1-STABLE"}
}

Vagrant.configure(2) do |config|
    # Set VM parameters
    config.vm.provider "virtualbox" do |v|
          v.memory = 1024
          v.cpus = 2
          v.customize ["modifyvm", :id, "--ioapic", "on"]
    end

    # Linux boxes
    linux_boxes.each do |hostname, info|
        config.vm.define hostname do |cfg|
            cfg.vm.box = info[:box]
            cfg.vm.hostname = hostname
        end
    end

    # FreeBSD boxes
    freebsd_boxes.each do |hostname, info|
        config.vm.define "freebsd-11" do |cfg|
            cfg.vm.guest = :freebsd
            cfg.vm.box = info[:box]
            cfg.vm.hostname = hostname
            cfg.vm.base_mac = "080027D14C66"
            cfg.ssh.shell = "sh"
            cfg.vm.provider :virtualbox do |vb|
                vb.customize ["modifyvm", :id, "--hwvirtex", "on"]
                vb.customize ["modifyvm", :id, "--audio", "none"]
                vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
                vb.customize ["modifyvm", :id, "--nictype2", "virtio"]
            end
        end
    end

    config.vm.provision :ansible do |ansible|
        ansible.playbook = "test.yml"
        ansible.groups = {
            "centos" => ["centos-7", "centos-8"],
            "debian" => ["debian-buster", "debian-stretch", "ubuntu-focal", "ubuntu-bionic", "ubuntu-xenial"],
            "fedora" => ["fedora-32"],
            "arch" => ["arch-current"],
            "suse" => ["leap-15-2"],
            "freebsd" => ["freebsd-11", "freebsd-12"]
        }
    end
end