How to spin up an Oracle DG environment with 1 primary and 2 standbys using Vagrant

I know is not the most optimized Vagrantfile written out there but, I’m going to post only the Vagrantfile for the moment and soon I will upload also the files used to create the databases and broker config:

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

# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.

var_BOX_IMAGE = "oraclebase/oracle-8"
var_mem_size = 4096
var_cpus = 2
var_non_rotational = 'on'
var_u01_disk_node1 = "ol8_19_dg1_u01.vdi"
var_u01_disk_node2 = "ol8_19_dg2_u01.vdi"
var_u01_disk_node3 = "ol8_19_dg3_u01.vdi"


# Try to make it work on both Windows and Linux
if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
  vboxmanage_path = "C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe"
else
  vboxmanage_path = "VBoxManage" # Assume it's in the path on Linux
end

Vagrant.configure("2") do |config|
  config.vm.define "node1" do |subconfig|
    subconfig.vm.box = var_BOX_IMAGE
    subconfig.vm.network "forwarded_port", guest: 1521, host: 1521
    subconfig.vm.network "forwarded_port", guest: 5500, host: 5500
    subconfig.vm.network "private_network", ip: "192.168.56.101"
    subconfig.vm.synced_folder "config", "/vagrant_config"
    subconfig.vm.synced_folder "shared_scripts", "/vagrant_scripts"
    subconfig.vm.synced_folder "software", "/vagrant_software"

    if Vagrant.has_plugin?("vagrant-vbguest") then
      subconfig.vbguest.auto_update = false
    end

    subconfig.vm.provider "virtualbox" do |vb|
      vb.memory = var_mem_size
      vb.cpus   = var_cpus
      vb.name   = "ol8_19_dg1"

      # Get disk path
      line = `"#{vboxmanage_path}" list systemproperties`.split(/\n/).grep(/Default machine folder/).first
      vb_machine_folder = line.split(':', 2)[1].strip()
      second_disk = File.join(vb_machine_folder, vb.name, var_u01_disk_node1)
  
      vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', '0', '--nonrotational', var_non_rotational]
      vb.customize ["storagectl", :id,"--name", "SATA Controller","--hostiocache", "on"]
      
      unless File.exist?(var_u01_disk_node1)
        vb.customize ['createhd', '--filename', second_disk, '--size', 100 * 1024]
      end
      vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', second_disk, '--nonrotational', var_non_rotational]
    end

    subconfig.vm.provision "shell", inline: <<-SHELL
    sh /vagrant/node1/setup.sh
    SHELL
  end

  config.vm.define "node2" do |subconfig|
    subconfig.vm.box = var_BOX_IMAGE
    subconfig.vm.network "forwarded_port", guest: 1521, host: 1522
    subconfig.vm.network "forwarded_port", guest: 5500, host: 5502
    subconfig.vm.network "private_network", ip: "192.168.56.102"
    subconfig.vm.synced_folder "config", "/vagrant_config"
    subconfig.vm.synced_folder "shared_scripts", "/vagrant_scripts"
    subconfig.vm.synced_folder "software", "/vagrant_software"

    if Vagrant.has_plugin?("vagrant-vbguest") then
      subconfig.vbguest.auto_update = false
    end

    subconfig.vm.provider "virtualbox" do |vb|
      vb.memory = var_mem_size
      vb.cpus   = var_cpus
      vb.name   = "ol8_19_dg2"

      # Get disk path
      line = `"#{vboxmanage_path}" list systemproperties`.split(/\n/).grep(/Default machine folder/).first
      vb_machine_folder = line.split(':', 2)[1].strip()
      second_disk = File.join(vb_machine_folder, vb.name, var_u01_disk_node2)
  
      vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', '0', '--nonrotational', var_non_rotational]
      vb.customize ["storagectl", :id,"--name", "SATA Controller","--hostiocache", "on"]
      
      unless File.exist?(var_u01_disk_node2)
        vb.customize ['createhd', '--filename', second_disk, '--size', 100 * 1024]
      end
      vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', second_disk, '--nonrotational', var_non_rotational]
    end
    subconfig.vm.provision "shell", inline: <<-SHELL
    sh /vagrant/node2/setup.sh
    SHELL
  end

  config.vm.define "node3" do |subconfig|
    subconfig.vm.box = var_BOX_IMAGE
    subconfig.vm.network "forwarded_port", guest: 1521, host: 1523
    subconfig.vm.network "forwarded_port", guest: 5500, host: 5503
    subconfig.vm.network "private_network", ip: "192.168.56.103"
    subconfig.vm.synced_folder "config", "/vagrant_config"
    subconfig.vm.synced_folder "shared_scripts", "/vagrant_scripts"
    subconfig.vm.synced_folder "software", "/vagrant_software"

    if Vagrant.has_plugin?("vagrant-vbguest") then
      subconfig.vbguest.auto_update = false
    end

    subconfig.vm.provider "virtualbox" do |vb|
      vb.memory = var_mem_size
      vb.cpus   = var_cpus
      vb.name   = "ol8_19_dg3"

      # Get disk path
      line = `"#{vboxmanage_path}" list systemproperties`.split(/\n/).grep(/Default machine folder/).first
      vb_machine_folder = line.split(':', 2)[1].strip()
      second_disk = File.join(vb_machine_folder, vb.name, var_u01_disk_node3)
  
      vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', '0', '--nonrotational', var_non_rotational]
      vb.customize ["storagectl", :id,"--name", "SATA Controller","--hostiocache", "on"]
      
      unless File.exist?(var_u01_disk_node3)
        vb.customize ['createhd', '--filename', second_disk, '--size', 100 * 1024]
      end
      vb.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', second_disk, '--nonrotational', var_non_rotational]
    end
    subconfig.vm.provision "shell", inline: <<-SHELL
    sh /vagrant/node3/setup.sh
    SHELL
  end
end

And the result would be something like this:

PS D:\vagrant\oracle_dg> vagrant global-status
id       name   provider   state   directory
-----------------------------------------------------------------------
16870cd  node1  virtualbox running D:/vagrant/oracle_dg
897179b  node2  virtualbox running D:/vagrant/oracle_dg
79eeb5c  node3  virtualbox running D:/vagrant/oracle_dg

One comment

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.