Install Oracle on CentOS 6.4 With Vagrant and Ansible
This post will cover installing oracle xe on CentOS 6.4 using vagrant and ansible. If you have not already, read the first post on creating a vagrant centos base box
Ansible is an IT orchestration engine/configuration management system, that lets you easily describe how you would like your servers to look and then automate it. It differs from Chef and Puppet, as it requires nothing to be installed on the server, it uses ssh. Tasks are described in yml, which can be written and read even by non programmers.
Vagrant uses a Vagrantfile to describe the type of machine you would like to build, and the file should be stored in the root directory of your source code. Next we create the Vagrantfile
1234567
$ mkdir ../vagrant-centos-oracle
$ cd ../vagrant-centos-oracle
$ vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please readthe comments in the Vagrantfile as well as documentation on
`vagrantup.com`for more information on using Vagrant.
Edit the Vagrantfile and change config.vm.box to:
1
config.vm.box="centos-64-x86_64"
Now we run:
12345678910111213141516171819
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'centos-64-x86_64'...
[default] Matching MAC address for NAT networking...
[default] Setting the name of the VM...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22=> 2222 (adapter 1)[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[default] Mounting shared folders...
[default] -- /vagrant
$ vagrant ssh
Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$
Great it works, we have a basic CentOS 6.4 Minimal install working, this is exactly like the box we created with veewee. Not too interesting just yet. We can add other customizations, like increase the memory size by adding this to the Vagrantfile
You will also notice, that /vagrant folder is a shared folder with your host machine, the root of the directory where the Vagrantfile is stored.
12345678910
[vagrant@localhost ~]$ ls /vagrant/
Vagrantfile
[vagrant@localhost ~]$ touch /vagrant/abd.txt
[vagrant@localhost ~]$ ls /vagrant/
abd.txt Vagrantfile
[vagrant@localhost ~]$ exitlogoutConnection to 127.0.0.1 closed.
$ ls
Vagrantfile abd.txt
Creating the playbook
Ansible has playbooks, which basically describe all the steps ansible needs to execute to get your system to the required state. All the steps are described in a yml file, with specific keywords for each task. You can read more at: http://www.ansibleworks.com/docs/playbooks.html
Before we start with our oracle playbook, we need to create a few directories.
We need to tell Vagrant to use the ansible playbook, by adding the following to the Vagrantfile. We also set the ansible verbose setting to extra, so we can see what is going on.
We can now test that oracle works from inside the VM:
12345678910111213
$ vagrant up
$ vagrant ssh
Last login: Sun Nov 10 11:35:22 2013 from 10.0.2.2
Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$ sqlplus system/manager@localhost
SQL*Plus: Release 11.2.0.2.0 Production on Sun Nov 10 12:37:23 2013
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
Vagrant port fowarding – connect from your host
If we try an connect from the host to the VM, it wont work. To get this to work we will use vagrant port forwarding by adding the following to our Vagrantfile.
We also need to modify our playbook, to disable iptables and to configure oracle to accept remote connections, from outside the VM.
oracle-xe.yml
123456
-name:stop ip tablesshell:service iptables stop-name:set oracle listenersudo:Falseshell:ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe /u01/app/oracle/product/11.2.0/xe/bin/sqlplussystem/manager@localhost < /vagrant/oracle/set_listener.sql
Also create a new file: oracle/set_listener.sql
set_listener.sql
123
EXECDBMS_XDB.SETLISTENERLOCALACCESS(FALSE);quit;/
Lets see if we can connect from our host to the VM:
12345678910111213
$ vagrant provision
$ sqlplus system/manager@localhost
SQL*Plus: Release 11.2.0.3.0 Production on Sun Nov 10 15:19:50 2013
Copyright (c) 1982, 2012, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> exit$ curl -v http://localhost:8080/apex/f?p=4950:1
Great, it works. This may seem like an awful amount of work just to setup a centos vm with oracle, though remember, Once you have done this once, no one else needs to follow the same steps again. All they need to do is issue a vagrant up from your source code repo.