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

require 'securerandom'

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

Vagrant.configure("2") do |config|
  ### Global settings for all VMS
  # disable synced folders
  config.vm.synced_folder ".", "/vagrant", disabled: true

  # use same private key on all machines
  config.ssh.insert_key = false

  # Number of seconds to wait for establishing an SSH connection to the guest
  config.ssh.connect_timeout = 90

  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 "site_ansible", type: 'ansible' do |ansible|
    ansible.playbook = "site.yml"
    ansible.config_file = "ansible.cfg"
    ansible.inventory_path = "inventory"
    # 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.exist?(pfservers_vagrantfile)

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

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

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