# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  config.vm.define "winbuilder", primary: true do |winbuilder|
    winbuilder.vm.box = "jborean93/WindowsServer2019"
    winbuilder.vm.provider :libvirt do |libvirt|
      libvirt.memory = 8192  # installation of VS fails with too little memory
    end
    winbuilder.vm.guest = :windows
    winbuilder.vm.communicator = "winrm"
    winbuilder.vm.boot_timeout = 600
    winbuilder.vm.graceful_halt_timeout = 600
    winbuilder.winrm.transport = :ssl
    winbuilder.winrm.basic_auth_only = true
    winbuilder.winrm.ssl_peer_verification = false
  end

  config.vm.define "samba", autostart: false do |samba|
    samba.vm.box = "centos/stream8"
  end

  # WARNING: if following line is removed, Vagrant seems to act like it would
  # be Linux with following error:
  # At line:1 char:33
  # + ip=$(which ip); ${ip:-/sbin/ip} addr show | grep -i 'inet ' | grep -v ...
  # +                                 ~~~~
  # Unexpected token 'addr' in expression or statement.
  #    + CategoryInfo          : ParserError: (:) [Invoke-Expression], ParseException
  #    + FullyQualifiedErrorId : UnexpectedToken,Microsoft.PowerShell.Commands.InvokeExpressionCommand
  config.vm.synced_folder ".", "/vagrant", disabled: true

  # the following parameters can be adapted, the certificate validation must
  # be ignored because the box is setup with a self-signed certificate.
  config.vm.provision "ansible" do |ansible|
    ansible.verbose = "v"
    ansible.groups = {
      "windows_builders" => ["winbuilder"],
      "windows_hosts:children" => ["windows_builders"],
      "windows_hosts:vars" => {
        "ansible_winrm_server_cert_validation" => "ignore"
      },
      "samba_servers" => ["samba"],
      "linux_hosts:children" => ["samba_servers"],
    }
    ansible.galaxy_role_file = "roles/requirements.yml"
    ansible.galaxy_roles_path = "roles"
    ansible.playbook = "playbook-provision.yml"
    ansible.compatibility_mode = "2.0"
  end
end
