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

require 'securerandom'

BRANCH_OR_TAG_NAME = ENV['CI_COMMIT_REF_SLUG'] || 'local-tests'
DOMAIN_PREFIX = "vagrant-" + BRANCH_OR_TAG_NAME + "-#{SecureRandom.hex(3)}-"

Vagrant.configure("2") do |config|
  ### Global settings for all VMS
  config.vagrant.sensitive = [ ENV['PSONO_CI_API_KEY_ID'], ENV['PSONO_CI_API_SECRET_KEY_HEX'] ]

  # disable synced folders
  config.vm.synced_folder ".", "/vagrant", disabled: true

  # The maximum amount of time to wait for a response
  config.winrm.timeout = 600
  
  # use same private key on all machines
  config.ssh.insert_key = false

  config.vm.provider "libvirt" do |vm|
    vm.default_prefix = DOMAIN_PREFIX
  end

  # common Ansible provisionner for all hosts
  # filtering is done using 'hosts' directive in site.yml
  config.vm.provision "ansible", type: 'ansible' do |ansible|
    ansible.playbook = "site.yml"
    ansible.config_file = "ansible.cfg"
    ansible.inventory_path = "inventory"
    ansible.galaxy_role_file = "requirements.yml"
    # only for debug
    ansible.verbose = ENV['VAGRANT_ANSIBLE_VERBOSE'] || false
  end
end


# include PacketFence(s) from PacketFence Vagrantfile
pfservers_vagrantfile = File.expand_path('pfservers/Vagrantfile')
load pfservers_vagrantfile if File.exists?(pfservers_vagrantfile)

# include ad(s) from Winservers Vagrantfile
winservers_vagrantfile = File.expand_path('winservers/Vagrantfile')
load winservers_vagrantfile if File.exists?(winservers_vagrantfile)

# include switch(s) and supplicant(s) from Cumulus Vagrantfile
cumulus_vagrantfile = File.expand_path('cumulus/Vagrantfile')
load cumulus_vagrantfile if File.exists?(cumulus_vagrantfile)

# include switch(s) and supplicant(s) from Wireless Vagrantfile
wireless_vagrantfile = File.expand_path('wireless/Vagrantfile')
load wireless_vagrantfile if File.exists?(wireless_vagrantfile)

# include linux servers from linux_servers Vagrantfile
linux_servers_vagrantfile = File.expand_path('linux_servers/Vagrantfile')
load linux_servers_vagrantfile if File.exists?(linux_servers_vagrantfile)
