github.com/crowdsecurity/crowdsec@v1.6.1/test/ansible/vagrant/wizard/common (about)

     1  # vim: set ft=ruby:
     2  # frozen_string_literal: true
     3  
     4  def find_ansible_cfg
     5    path = Pathname.new(Dir.pwd)
     6    until path.root?
     7      ansible_cfg = path + 'ansible.cfg'
     8      return path if ansible_cfg.exist?
     9      path = path.parent
    10    end
    11    nil # return nil if not found
    12  end
    13  
    14  Vagrant.configure('2') do |config|
    15    config.vm.define 'wizard'
    16  
    17    if ARGV.any? { |arg| arg == 'up' || arg == 'provision' }
    18      unless ENV['DB_BACKEND']
    19        $stderr.puts "\e[31mThe DB_BACKEND environment variable is not defined. Please set up the environment and try again.\e[0m"
    20        exit 1
    21      end
    22    end
    23  
    24    config.vm.provision 'shell', path: 'bootstrap' if File.exist?('bootstrap')
    25    config.vm.synced_folder '.', '/vagrant', disabled: true
    26  
    27    config.vm.provider :libvirt do |libvirt|
    28      libvirt.cpus = 4
    29      libvirt.memory = 4096
    30    end
    31  
    32    path = find_ansible_cfg
    33    if !path
    34      puts "ansible.cfg not found"
    35    end
    36  
    37    config.vm.provision 'ansible' do |ansible|
    38      ansible.config_file = (path + 'ansible.cfg').to_s
    39      ansible.playbook = (path + 'provision_dependencies.yml').to_s
    40      ansible.compatibility_mode = "2.0"
    41    end
    42  
    43    config.vm.provision 'ansible' do |ansible|
    44      ansible.config_file = (path + 'ansible.cfg').to_s
    45      ansible.playbook = (path + 'provision_test_suite.yml').to_s
    46      ansible.compatibility_mode = "2.0"
    47    end
    48  
    49    config.vm.provision 'ansible' do |ansible|
    50      ansible.config_file = (path + 'ansible.cfg').to_s
    51      ansible.playbook = (path + 'prepare_tests.yml').to_s
    52      ansible.compatibility_mode = "2.0"
    53    end
    54  
    55    config.vm.provision 'ansible' do |ansible|
    56      ansible.config_file = (path + 'ansible.cfg').to_s
    57      ansible.playbook = (path + 'debug_tools.yml').to_s
    58      ansible.compatibility_mode = "2.0"
    59    end
    60  
    61    config.vm.provision 'ansible' do |ansible|
    62      ansible.config_file = (path + 'ansible.cfg').to_s
    63      ansible.playbook = (path + 'run_wizard_tests.yml').to_s
    64      ansible.compatibility_mode = "2.0"
    65    end
    66  
    67  end