Vagrant + Ansible + Oracle

So, I finally got my act together and created the repositories I’ve been meaning to create for ages, to automatically spin up a VM running Oracle.

They are:

and uses Vagrant to provision the machine, and then Ansible to automatically provision Oracle.

The readme’s for each repository should (hopefully) be enough to get going, but in short these are the steps required:

  • Clone the repositories
  • Download the 12.2 binaries and place them in the <reponame>/swrepo directory
  • vagrant up

This will (by default) give you a VM with:

  • Oracle Linux 7.3
  • Single instance 12.2.0.1 (cdb + 1 pdb)
  • Storage on either FS or ASM

If you want to test a different combination of OS version and Oracle version, just follow the instructions in the readme.

The Vagrant boxes are the same ones I talked about in this post.

If you decide to try this and have problems or just have questions, just ask here or open an issue for the corresponding repository.

Advertisements

23 thoughts on “Vagrant + Ansible + Oracle

  1. Hi Mikael,

    I am trying to start VM for single instance and ASM and it fails at step for ansible:

    => db1-asm: Running provisioner: ansible_local…
    `playbook` does not exist on the guest: /vagrant/ansible-oracle/vbox-si-asm-install.yml

    checking cloned directory from github I do not see any files under ansible-oracle directory
    however in github directory exists but with name “ansible-oracle @ d311447”

    Thanks,
    Andrey

    • Hi,

      Did you do ‘git clone –recursive…’?
      If you don’t the submodule doesn’t get sucked in, and then those files won’t exist.

      regards
      /M

      • Hi Mikael,

        I got a new version of scripts (after the change of hosts.yml format) and am trying to create VMs and provision Oracle but playbook fails at steps of restart dnsmasq

        ==> db-asm-1: Running provisioner: ansible_local…
        db-asm-1: Running ansible-playbook…


        RUNNING HANDLER [init : restart dnsmasq] ***************************************
        changed: [db-asm-1]

        PLAY RECAP *********************************************************************
        db-asm-1 : ok=8 changed=6 unreachable=0 failed=0

        I just finishes w/o errors/failures and not going further. I tried ol73, ol68 with 12.1 and 12.2
        but result the same. I am not sure what might be the issue

        Cheers,
        Andrey

  2. Pingback: Vagrant? Again? …Really? | oravirt

  3. Here is the output:

    [andrey@angor vagrant-vbox-si-asm]$ vagrant up
    Bringing machine ‘db-asm-1’ up with ‘virtualbox’ provider…
    ==> db-asm-1: Importing base box ‘oravirt/ol68’…
    ==> db-asm-1: Matching MAC address for NAT networking…
    ==> db-asm-1: Checking if box ‘oravirt/ol68’ is up to date…
    ==> db-asm-1: Setting the name of the VM: db-asm-1
    ==> db-asm-1: Clearing any previously set network interfaces…
    ==> db-asm-1: Preparing network interfaces based on configuration…
    db-asm-1: Adapter 1: nat
    db-asm-1: Adapter 2: hostonly
    ==> db-asm-1: Forwarding ports…
    db-asm-1: 22 (guest) => 2222 (host) (adapter 1)
    ==> db-asm-1: Running ‘pre-boot’ VM customizations…
    ==> db-asm-1: Booting VM…
    ==> db-asm-1: Waiting for machine to boot. This may take a few minutes…
    db-asm-1: SSH address: 127.0.0.1:2222
    db-asm-1: SSH username: vagrant
    db-asm-1: SSH auth method: private key
    db-asm-1: Warning: Remote connection disconnect. Retrying…
    ==> db-asm-1: Machine booted and ready!
    ==> db-asm-1: Checking for guest additions in VM…
    db-asm-1: The guest additions on this VM do not match the installed version of
    db-asm-1: VirtualBox! In most cases this is fine, but in rare cases it can
    db-asm-1: prevent things such as shared folders from working properly. If you see
    db-asm-1: shared folder errors, please make sure the guest additions within the
    db-asm-1: virtual machine match the version of VirtualBox you have installed on
    db-asm-1: your host and reload your VM.
    db-asm-1:
    db-asm-1: Guest Additions Version: 5.0.20
    db-asm-1: VirtualBox Version: 5.1
    ==> db-asm-1: Setting hostname…
    ==> db-asm-1: Configuring and enabling network interfaces…
    ==> db-asm-1: Mounting shared folders…
    db-asm-1: /vagrant => /home/andrey/vag/vagrant-vbox-si-asm
    db-asm-1: /media/swrepo => /home/andrey/vag/vagrant-vbox-si-asm/swrepo
    ==> db-asm-1: Running provisioner: network (shell)…
    db-asm-1: Running: inline script
    ==> db-asm-1: Shutting down interface eth0:
    ==> db-asm-1: [ OK ]
    ==> db-asm-1: Shutting down interface eth1:
    ==> db-asm-1: [ OK ]
    ==> db-asm-1: Shutting down loopback interface:
    ==> db-asm-1: [ OK ]
    ==> db-asm-1: Bringing up loopback interface:
    ==> db-asm-1: [ OK ]
    ==> db-asm-1: Bringing up interface eth0:
    ==> db-asm-1: Determining IP information for eth0…
    ==> db-asm-1: done.
    ==> db-asm-1: [ OK ]
    ==> db-asm-1: Bringing up interface eth1:
    ==> db-asm-1: Determining if ip address 192.168.9.62 is already in use for device eth1…
    ==> db-asm-1: [ OK ]
    ==> db-asm-1: Running provisioner: ansible_local…
    db-asm-1: Running ansible-playbook…

    PLAY [all] *********************************************************************

    TASK [setup] *******************************************************************
    ok: [db-asm-1]

    TASK [init : Install packages] *************************************************
    ok: [db-asm-1] => (item=[u’ntp’, u’dnsmasq’])

    TASK [init : Make sure ntp is running] *****************************************
    changed: [db-asm-1]

    TASK [init : Generate /etc/hosts] **********************************************
    changed: [db-asm-1]

    TASK [init : Generate /etc/resolv.conf] ****************************************
    changed: [db-asm-1]

    TASK [init : Generate dnsmasq config] ******************************************
    changed: [db-asm-1]

    TASK [init : Start and enable dnsmasq] *****************************************
    changed: [db-asm-1]

    RUNNING HANDLER [init : restart dnsmasq] ***************************************
    changed: [db-asm-1]

    PLAY RECAP *********************************************************************
    db-asm-1 : ok=8 changed=6 unreachable=0 failed=0

    [andrey@angor vagrant-vbox-si-asm]$ vagrant box list
    bento/oracle-6.8 (virtualbox, 2.3.1)
    hashicorp/precise64 (virtualbox, 1.1.0)
    ol73 (virtualbox, 0)
    oravirt/ol68 (virtualbox, 20170418)
    oravirt/ol73 (virtualbox, 20170412)
    oravirt/ol73 (virtualbox, 20170418)

  4. Hi,

    Ok, so that seems to work as expected.

    Now do, ‘setup=true vagrant provision’ (or setup=true vagrant up).
    This changed with the new codebase (The procedure is mentioned in the README, but I’ll also update this blogpost for clarity).

    Let me know if that works for you.

    Also, you can remove the old box-versions (vagrant box remove oravirt/ol73 –box-version 20170412)

    regards
    /Micke

    • Thank you! Now it went through and ansible executed.
      I also noticed that disks being created in directory with vagrant and it filled my home directory
      so I modified the code to create disks under default folder:


      line = `VBoxManage list systemproperties | grep “Default machine folder”`
      vb_machine_folder = line.split(‘:’)[1].strip()

      local_disk_name = File.join(vb_machine_folder, “#{vm[‘hostgroup’]}”, vb.name, “#{vm[‘basename_vm’]}#{v}-#{disk[‘name’]}-#{d}.vdi”)

      Thanks again!

      • Hi again,
        I just added a variable called ‘base_disk_path’ which you could set to your Virtualbox default path and then all disks created by Vagrant end up there instead of the ‘Vagrantfile’ directory.
        So, if your VBOX default is /home/username/VBOX, the disks will end up in /home/username/VBOX/hostgroup/

        regards
        /M

  5. Great!

    No problems, happy to see it being used 😉
    And re the disks: They were also previously created in the ‘vagrant’ directory, that didn’t change with the new config.

    • Hi Mikael,

      I chose 12.1.0.2 GI and RDBMS and also selected in vagrant-vbox-si-asm file second section for non CDB database but it failed (see below). Finally it worked when I put num_pdbs and pdb_prefix

      TASK [oradb-create : Create responsefile for dbca] *****************************
      failed: [db-asm-1] (item=[{u’is_container’: False, u’home’: u’db1′, u’oracle_db_type’: u’SI’, u’oracle_database_type’: u’MULTIPURPOSE’, u’oracle_db_name’: u’orcl’, u’datafile_dest’: u’+DATA’, u’redolog_size_in_mb’: 100, u’state’: u’present’, u’oracle_edition’: u’EE’, u’oracle_db_mem_totalmb’: 1024, u’recoveryfile_dest’: u’+FRA’, u’oracle_db_passwd’: u’Oracle123′, u’oracle_version_db’: u’12.1.0.2′, u’storage_type’: u’ASM’}, {u’_ansible_parsed’: True, u’_ansible_item_result’: True, u’stdout’: u’0′, u’_ansible_no_log’: False, u’warnings’: [], u’changed’: True, u’rc’: 0, u’end’: u’2017-05-01 12:38:21.878805′, u’start’: u’2017-05-01 12:38:21.860863′, u’cmd’: u’grep orcl:/u01/app/oracle/12.1.0.2/db1 /etc/oratab |wc -l’, u’item’: {u’is_container’: False, u’oracle_db_type’: u’SI’, u’oracle_database_type’: u’MULTIPURPOSE’, u’oracle_db_name’: u’orcl’, u’datafile_dest’: u’+DATA’, u’redolog_size_in_mb’: 100, u’state’: u’present’, u’oracle_edition’: u’EE’, u’oracle_db_mem_totalmb’: 1024, u’oracle_version_db’: u’12.1.0.2′, u’recoveryfile_dest’: u’+FRA’, u’oracle_db_passwd’: u’Oracle123′, u’home’: u’db1′, u’storage_type’: u’ASM’}, u’delta’: u’0:00:00.017942′, u’invocation’: {u’module_name’: u’command’, u’module_args’: {u’creates’: None, u’executable’: None, u’_uses_shell’: True, u’_raw_params’: u’grep orcl:/u01/app/oracle/12.1.0.2/db1 /etc/oratab |wc -l’, u’removes’: None, u’warn’: True, u’chdir’: None}}, u’stdout_lines’: [u’0′], u’stderr’: u”}]) => {“failed”: true, “item”: [{“datafile_dest”: “+DATA”, “home”: “db1”, “is_container”: false, “oracle_database_type”: “MULTIPURPOSE”, “oracle_db_mem_totalmb”: 1024, “oracle_db_name”: “orcl”, “oracle_db_passwd”: “Oracle123”, “oracle_db_type”: “SI”, “oracle_edition”: “EE”, “oracle_version_db”: “12.1.0.2”, “recoveryfile_dest”: “+FRA”, “redolog_size_in_mb”: 100, “state”: “present”, “storage_type”: “ASM”}, {“_ansible_item_result”: true, “_ansible_no_log”: false, “_ansible_parsed”: true, “changed”: true, “cmd”: “grep orcl:/u01/app/oracle/12.1.0.2/db1 /etc/oratab |wc -l”, “delta”: “0:00:00.017942”, “end”: “2017-05-01 12:38:21.878805”, “invocation”: {“module_args”: {“_raw_params”: “grep orcl:/u01/app/oracle/12.1.0.2/db1 /etc/oratab |wc -l”, “_uses_shell”: true, “chdir”: null, “creates”: null, “executable”: null, “removes”: null, “warn”: true}, “module_name”: “command”}, “item”: {“datafile_dest”: “+DATA”, “home”: “db1”, “is_container”: false, “oracle_database_type”: “MULTIPURPOSE”, “oracle_db_mem_totalmb”: 1024, “oracle_db_name”: “orcl”, “oracle_db_passwd”: “Oracle123”, “oracle_db_type”: “SI”, “oracle_edition”: “EE”, “oracle_version_db”: “12.1.0.2”, “recoveryfile_dest”: “+FRA”, “redolog_size_in_mb”: 100, “state”: “present”, “storage_type”: “ASM”}, “rc”: 0, “start”: “2017-05-01 12:38:21.860863”, “stderr”: “”, “stdout”: “0”, “stdout_lines”: [“0”], “warnings”: []}], “msg”: “AnsibleUndefinedVariable: ‘dict object’ has no attribute ‘num_pdbs'”}
      failed: [db-asm-2] (item=[{u’is_container’: False, u’home’: u’db1′, u’oracle_db_type’: u’SI’, u’oracle_database_type’: u’MULTIPURPOSE’, u’oracle_db_name’: u’orcl’, u’datafile_dest’: u’+DATA’, u’redolog_size_in_mb’: 100, u’state’: u’present’, u’oracle_edition’: u’EE’, u’oracle_db_mem_totalmb’: 1024, u’recoveryfile_dest’: u’+FRA’, u’oracle_db_passwd’: u’Oracle123′, u’oracle_version_db’: u’12.1.0.2′, u’storage_type’: u’ASM’}, {u’_ansible_parsed’: True, u’_ansible_item_result’: True, u’stdout’: u’0′, u’_ansible_no_log’: False, u’warnings’: [], u’changed’: True, u’rc’: 0, u’end’: u’2017-05-01 12:38:21.802101′, u’start’: u’2017-05-01 12:38:21.769268′, u’cmd’: u’grep orcl:/u01/app/oracle/12.1.0.2/db1 /etc/oratab |wc -l’, u’item’: {u’is_container’: False, u’oracle_db_type’: u’SI’, u’oracle_database_type’: u’MULTIPURPOSE’, u’oracle_db_name’: u’orcl’, u’datafile_dest’: u’+DATA’, u’redolog_size_in_mb’: 100, u’state’: u’present’, u’oracle_edition’: u’EE’, u’oracle_db_mem_totalmb’: 1024, u’oracle_version_db’: u’12.1.0.2′, u’recoveryfile_dest’: u’+FRA’, u’oracle_db_passwd’: u’Oracle123′, u’home’: u’db1′, u’storage_type’: u’ASM’}, u’delta’: u’0:00:00.032833′, u’invocation’: {u’module_name’: u’command’, u’module_args’: {u’creates’: None, u’executable’: None, u’_uses_shell’: True, u’_raw_params’: u’grep orcl:/u01/app/oracle/12.1.0.2/db1 /etc/oratab |wc -l’, u’removes’: None, u’warn’: True, u’chdir’: None}}, u’stdout_lines’: [u’0′], u’stderr’: u”}]) => {“failed”: true, “item”: [{“datafile_dest”: “+DATA”, “home”: “db1”, “is_container”: false, “oracle_database_type”: “MULTIPURPOSE”, “oracle_db_mem_totalmb”: 1024, “oracle_db_name”: “orcl”, “oracle_db_passwd”: “Oracle123”, “oracle_db_type”: “SI”, “oracle_edition”: “EE”, “oracle_version_db”: “12.1.0.2”, “recoveryfile_dest”: “+FRA”, “redolog_size_in_mb”: 100, “state”: “present”, “storage_type”: “ASM”}, {“_ansible_item_result”: true, “_ansible_no_log”: false, “_ansible_parsed”: true, “changed”: true, “cmd”: “grep orcl:/u01/app/oracle/12.1.0.2/db1 /etc/oratab |wc -l”, “delta”: “0:00:00.032833”, “end”: “2017-05-01 12:38:21.802101”, “invocation”: {“module_args”: {“_raw_params”: “grep orcl:/u01/app/oracle/12.1.0.2/db1 /etc/oratab |wc -l”, “_uses_shell”: true, “chdir”: null, “creates”: null, “executable”: null, “removes”: null, “warn”: true}, “module_name”: “command”}, “item”: {“datafile_dest”: “+DATA”, “home”: “db1”, “is_container”: false, “oracle_database_type”: “MULTIPURPOSE”, “oracle_db_mem_totalmb”: 1024, “oracle_db_name”: “orcl”, “oracle_db_passwd”: “Oracle123”, “oracle_db_type”: “SI”, “oracle_edition”: “EE”, “oracle_version_db”: “12.1.0.2”, “recoveryfile_dest”: “+FRA”, “redolog_size_in_mb”: 100, “state”: “present”, “storage_type”: “ASM”}, “rc”: 0, “start”: “2017-05-01 12:38:21.769268”, “stderr”: “”, “stdout”: “0”, “stdout_lines”: [“0”], “warnings”: []}], “msg”: “AnsibleUndefinedVariable: ‘dict object’ has no attribute ‘num_pdbs'”}
      to retry, use: –limit @/vagrant/extra-provision/ansible-oracle/vbox-si-asm-install.retry

      PLAY RECAP *********************************************************************
      db-asm-1 : ok=95 changed=70 unreachable=0 failed=1
      db-asm-2 : ok=95 changed=70 unreachable=0 failed=1

      Ansible failed to complete successfully. Any error output should be
      visible above. Please fix these errors and try again.

      Cheers,
      Andrey

      • changes are in vbox-si-asm:
        (1st section of db1 for 12.2… commented and 2nd uncommented and version is changed
        but it was enough, I had to add pdbs related parameters – pdb_prefix, num_pdbs)
        other than that vagrant command is the same and hosts.yml does not have GI and RDBMS versions


        ################ Grid Infrastructure specifics ################
        configure_cluster: false
        oracle_install_option_gi: HA_CONFIG
        #oracle_install_version_gi: 12.2.0.1
        oracle_install_version_gi: 12.1.0.2

        oracle_password: Oracle123
        oracle_asm_init_dg: crs

        oracle_databases: # Dictionary describing the databases to be installed
        #- home: db1 # ‘Last’ directory in ORACLE_HOME path (e.g /u01/app/oracle/12.1.0.2/racdb)
        # oracle_version_db: 12.2.0.1 # Oracle versiono
        # oracle_edition: EE # The edition of database-server (EE,SE,SEONE)
        # oracle_db_name: orclcdb # Database name
        # oracle_db_passwd: Oracle123 # Passwords (sys/system/dbsnm etc)
        # oracle_db_type: SI # Type of database (RAC,RACONENODE,SI)
        # is_container: True # (true/false) Is the database a container database
        # pdb_prefix: orclpdb
        # num_pdbs: 1
        # storage_type: ASM # Database storage to be used. ASM or FS.
        # oracle_db_mem_totalmb: 1024 # Amount of RAM to be used for SGA
        # oracle_database_type: MULTIPURPOSE # MULTIPURPOSE|DATA_WAREHOUSING|OLTP
        # redolog_size_in_mb: 100
        # datafile_dest: ‘+DATA’
        # recoveryfile_dest: ‘+FRA’
        # state: present
        ## The following will create a new database (non-cdb) running from the same home as above (/u01/app/oracle/12.2.0.1/db1)
        – home: db1 # ‘Last’ directory in ORACLE_HOME path (e.g /u01/app/oracle/12.2.0.1/db1)
        oracle_version_db: 12.1.0.2 # Oracle versiono (12.2.0.1,12.1.0.2,12.1.0.1,11.2.0.4,11.2.0.3)
        oracle_edition: EE # The edition of database-server (EE,SE,SEONE)
        oracle_db_name: orcl # Database name
        oracle_db_passwd: Oracle123 # Passwords (sys/system/dbsnm etc)
        oracle_db_type: SI # Type of database (RAC,RACONENODE,SI)
        is_container: false # (true/false) Is the database a container database
        pdb_prefix: orclpdb
        num_pdbs: 1
        storage_type: ASM # Database storage to be used. ASM or FS.
        oracle_db_mem_totalmb: 1024 # Amount of RAM to be used for SGA
        oracle_database_type: MULTIPURPOSE # MULTIPURPOSE|DATA_WAREHOUSING|OLTP
        redolog_size_in_mb: 100
        datafile_dest: ‘+DATA’
        recoveryfile_dest: ‘+FRA’
        state: present

  6. Ah, ok. That is my bad.
    I’ll update it in the original repo and make sure it’s updated in all others as well.

    Thanks for letting me know!

    regards
    /M

    • Thank you Mikael!

      I just noticed that in 2 created servers eth0 addresses are the same – 10.0.2.15
      and …9.62 and …9.63 are going to eth1
      Should be NAT network address 10… changed as well or it is not taken of during vagrant config?

      • Hi,

        In short, you don’t have to do anything, Vagrant will sort it out for you.

        That’s just the way the nice device numbering works in Virtualbox. The NAT by default always goes to the first NIC (eth0) and then the other networks (whatever they may be) start at eth1/2 etc. If you manually create a VM in VBOX, maybe it is possible to put the NAT network on a different NIC (if you really need to)
        Vagrant will setup port forwarding from the host to the VM if you want to connect directly to the NAT network (which will always be 10.0.2.15). So you’d basically be doing something like ‘ssh localhost -p 2222’ from the host to connect to the NAT network.

        regards
        /Micke

  7. What I meant is that both servers db-asm-1 and -2 have eth0 with IP address 10.0.2.15
    even it is not used anyhow yet but it is still the same across servers

    Thanks,
    Andrey

    • Yes, I know and that is how the NAT thing works in VBOX. You need to portforward from the host to the VM to access that network. And that is why you see this in the vagrant up output:

      db-asm-1: SSH address: 127.0.0.1:2203 <– Or whatever the port may be

      And that is also why the NAT IP on all VM's are the same, as that network is not reachable from 'the outside'

      If you do a vagrant ssh-config you'll see the port that Vagrant used to forward traffic to the NAT network in the VM.

      regards
      /Micke

  8. Hi Micke,

    installing 11.2.0.3 GI and DB it failed due to compatible parameter set to 11.2.0.4
    which is static in vbox-si-asm group vars.

    Also recent change of naming of servers to be created (num_vm, basename_vm) in hosts.yml
    not quite flexible in terms of creating VMs several times. For example if I created vm1, vm2
    first time (setting num_vm: 2, basename_vm: vm), next time it is problematic to create vm3

    Or might be you have some trick how to create it?

    Thanks,
    Andrey

    • Hi,

      Just change the 2 to a 3 in hosts.yml and run vagrant up again and the next host(s) will be created. Works equally well for ‘rac’ nodes with shared storage.

      Re: the compatible issue, that’s just because I never install 11.2.0.3 anymore 😉 I’ll fix it though. Thanks for reporting it!

      /M

      • Thanks, I will try that!
        And I was installing 11.2.0.3 to test upgrade to 12.2, so thought why not to use vagrant + ansible
        scripts you created!
        Thanks again!

  9. Hi Micke,
    while changing names of hosts and group in hosts.yml I noticed that ansible provisioning
    just stops and not going to servers.
    Checking further I see that ansible role only includes hosts which belong to vbox-si-asm
    but when group renamed in hosts.yml role does not run against differently named group.
    cat hosts.yml
    – basename_vm: d-
    num_vm: 1
    hostgroup: grp

    cat inventory
    [grp]
    d-1 ansible_ssh_host=…

    more extra-provision/ansible-oracle/vbox-si-asm-install.yml

    – name: Host configuration
    hosts: vbox-si-asm

    Might be the parameter hostgroup should be removed from hosts.yml (since it should not be
    changed) or might be hosts should be set to all in vbox-si-asm-install.yml

    Thanks,
    Andrey

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s