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

servers=[
  { :hostname => "d-stretch-64-@@hostname@@", :box => "bento/debian-9" },
  { :hostname => "d-buster-64-@@hostname@@", :box => "bento/debian-10" },
  { :hostname => "d-bullseye-64-@@hostname@@", :box => "bento/debian-11" },
  { :hostname => "centos-6-64-@@hostname@@", :box => "bento/centos-6" },
  { :hostname => "centos-7-64-@@hostname@@", :box => "bento/centos-7" },
  { :hostname => "centos-8-64-@@hostname@@", :box => "bento/centos-8" },
  { :hostname => "u-xenial-64-@@hostname@@", :box => "bento/ubuntu-16.04" },
  { :hostname => "u-bionic-64-@@hostname@@", :box => "bento/ubuntu-18.04" },
  { :hostname => "u-focal-64-@@hostname@@", :box => "bento/ubuntu-20.04" },
  { :hostname => "sles-12-64-@@hostname@@", :box => "wvera/sles12sp2" }
]

Vagrant.configure("2") do |config|
  # All Vagrant configuration is done here. The most pxb configuration
  # options are documented and commented below. For a complete reference,
  # please see the online documentation at vagrantup.com.

  servers.each do |machine|
    config.vm.define "pxc1-#{machine[:hostname]}" do |node1|
      node1.vm.box = machine[:box]
      node1.vm.hostname = machine[:hostname]
      node1.vm.provider "virtualbox" do |vb|
          vb.customize ["modifyvm", :id, "--cpus", 2]
          vb.customize ["modifyvm", :id, "--memory", "2048", "--ioapic", "on"]
#         vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
#         vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
#         vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
      end
      config.vm.provision "shell", inline: <<-SHELL
        if [ -z "$PERCONA_TELEMETRY_URL" ] || [ "$PERCONA_TELEMETRY_URL" != "https://check-dev.percona.com/v1/telemetry/GenericReport" ]; then
          echo 'export PERCONA_TELEMETRY_URL=https://check-dev.percona.com/v1/telemetry/GenericReport' >> /etc/environment || :
        fi
      SHELL
      node1.vm.provision "ansible" do |ansible|
        ansible.playbook = "@@pxc1-playbook_full@@"
        ansible.become = "true"
        # ansible.verbose = "vvvv"
        ansible.host_key_checking = "false"
      end
      node1.vm.synced_folder '.', '/vagrant', :disabled => true
      node1.vm.synced_folder '.', '/home/vagrant/sync', :disabled => true
      node1.vm.network :private_network, ip: "192.168.70.61"
    end

    config.vm.define "pxc2-#{machine[:hostname]}" do |node2|
      node2.vm.box = machine[:box]
      node2.vm.hostname = machine[:hostname]
      node2.vm.provider "virtualbox" do |vb|
          vb.customize ["modifyvm", :id, "--cpus", 2]
          vb.customize ["modifyvm", :id, "--memory", "2048", "--ioapic", "on"]
#         vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
#         vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
#         vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
      end
      config.vm.provision "shell", inline: <<-SHELL
        if [ -z "$PERCONA_TELEMETRY_URL" ] || [ "$PERCONA_TELEMETRY_URL" != "https://check-dev.percona.com/v1/telemetry/GenericReport" ]; then
          echo 'export PERCONA_TELEMETRY_URL=https://check-dev.percona.com/v1/telemetry/GenericReport' >> /etc/environment || :
        fi
      SHELL
      node2.vm.provision "ansible" do |ansible|
        ansible.playbook = "@@pxc2-playbook_full@@"
        ansible.become = "true"
        # ansible.verbose = "vvvv"
        ansible.host_key_checking = "false"
      end
      node2.vm.synced_folder '.', '/vagrant', :disabled => true
      node2.vm.synced_folder '.', '/home/vagrant/sync', :disabled => true
      node2.vm.network :private_network, ip: "192.168.70.62"
    end

    config.vm.define "pxc3-#{machine[:hostname]}" do |node3|
      node3.vm.box = machine[:box]
      node3.vm.hostname = machine[:hostname]
      config.vm.provision "shell", inline: <<-SHELL
        if [ -z "$PERCONA_TELEMETRY_URL" ] || [ "$PERCONA_TELEMETRY_URL" != "https://check-dev.percona.com/v1/telemetry/GenericReport" ]; then
          echo 'export PERCONA_TELEMETRY_URL=https://check-dev.percona.com/v1/telemetry/GenericReport' >> /etc/environment || :
        fi
      SHELL
      node3.vm.provider "virtualbox" do |vb|
          vb.customize ["modifyvm", :id, "--cpus", 2]
          vb.customize ["modifyvm", :id, "--memory", "2048", "--ioapic", "on"]
#         vb.customize ["modifyvm", :id, "--nictype1", "virtio"]
#         vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
#         vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
      end
      node3.vm.provision "ansible" do |ansible|
        ansible.playbook = "@@pxc3-playbook_full@@"
        ansible.become = "true"
        # ansible.verbose = "vvvv"
        ansible.host_key_checking = "false"
      end
      node3.vm.synced_folder '.', '/vagrant', :disabled => true
      node3.vm.synced_folder '.', '/home/vagrant/sync', :disabled => true
      node3.vm.network :private_network, ip: "192.168.70.63"
    end

  end

end