Getting started with Ansible and Oracle

Introduction

In my previous post An introduction to Ansible I shared some reasons why companies are adopting Ansible and described some of the advantages of using Ansible over other configuration management tools.

Now we know what Ansible is, let’s start using it.

Setting up an Ansible Control Machine

The simplest and quickest way to get up and running with Ansible is to use Vagrant to create a virtual machine. Vagrant ships with out of the box support for VirtualBox, Hyper-V and Docker. Vagrant supports other providers e.g. VMware but these are licenceable

So even though I mainly use VMware Fusion on my MacBook I used the links above to install Vagrant and the excellent Oracle VirtualBox to avoid any licensing requirements.

Using Vagrant

Run the following commands to create a Vagrantfile for an Ubuntu Vagrant machine.
$ mkdir ansible_oracle
$ cd ansible_oracle
$ vagrant init ubuntu/trusty64

A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant.

$ vagrant up
You should now be able to SSH into your Ubuntu VM using ‘vagrant ssh’, however before we try and connect to our new VM let’s check the status of all the local Vagrant machines using the following:
$ vagrant global-status

id       name    provider   state    directory
————————————————————————-
a1995ac  default virtualbox running  /Users/ronekins/ansible_oracle

The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date. To interact with any of the machines, you can go to
that directory and run Vagrant, or you can use the ID directly
with Vagrant commands from any directory. For example:
“vagrant destroy 1a2b3c4d”

$ vagrant status a1995ac
Current machine states:

default running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

$ vagrant ssh
If all has gone well you should be presented with your Ubuntu virtual machine.

Useful vagrant machine (vm) commands

destroy       : stops and deletes all traces of the vm 
global-status : outputs status Vagrant env's for this user 
halt          : stops the vm 
init          : initialises a new Vagrant environment 
provision     : provisions the vm 
reload        : restarts vm, loads new Vagrantfile config 
resume        : resume a suspended vm 
snapshot      : manages snapshots, saving, restoring, etc. 
ssh           : connects to vm via SSH 
status        : outputs status of the vm 
suspend       : suspends the vm 
up            : starts and provisions the vm

Ansible Installation

$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible

Update local host file

Add the IP address and database server names to your local host file.
$ sudo vi /etc/hosts

Getting Started

Create Ansible configuration file

$ vi ansible.cfg
[defaults]
hostfile = hosts
ansible_private_key_file=~/.ssh/id_rsa

Create Ansible host file

In the host file we can specify that we want ansible to default to the ‘oracle’ user, the first entry is a server alias, in the example below I have kept it the same as the server name but it can be useful if you have cryptic host names or want to refer to the server by it’s database or application name.
$ vi hosts
[dbservers]
z-oracle         ansible_host=z-oracle        ansible_user=oracle
z-oracle-dr  ansible_host=z-oracle-dr  ansible_user=oracle

Ansible Ping Test

Now let’s try using the Ansible ping module to try to connect to our database server and verify a usable version of python, the ping module will return ‘pong’ on success.
$ ansible all -m ping

Both servers will fail returning UNREACHABLE! as the ssh connection failed, to fix this add a public key to the database servers ‘authorized_keys’file.

Generating RSA Keys

Before we can use password-less SSH we need to create a pair of private and public RSA keys for our Ansible control machine.

$ cd ~/.ssh
$ ssh-keygen -t rsa
$ cat id_rsa.pub

‘Copy’ the id_rsa.pub into your client buffer and ssh onto the database servers as the ‘oracle’, cd to the .ssh directory and ‘paste’ the public key into the ‘authorized_keys’ file.

$ cd ~/.ssh
$ vi authorised_keys

Now return to your Ansible control machine to repeat the Ansible Ping Tests.

Ansible Ping Part II

Ok, now we are ready to check connectivity, first lets trying using the database server names individually.
ping_each
That was great, but as we defined a group ‘dbservers’ we can also perform a ‘ping’ test using the group name as we may want to perform an ansible play against a group of servers e.g. Production, Development, Test etc..

ping_group
Very cool, if required you can use the ‘all’ option to run against all entries in the host file.

ping_all
In my next blog post we will start to use our Ubuntu Ansible control machine to interact with our database servers.

An introduction to Ansible

Why this Blog

Over the last couple of years I have found myself increasingly working with DevOps teams and being exposed to the tools and techniques being adopted. However speaking to other DBA’s and Architects it appears that for many it’s still a bit of a ‘Dark Art’, so I thought it was about time I shared some the knowledge over a series of DevOps focused Blogs posts.

Why is Ansible, Ansible ?

The term Ansible is a Science Fiction reference for a ficitonal communications device that can transfer information faster than the speed of light.

The author Ursula LeGuin invented the concept in her 1966 book ‘Rocannon’s World’, subsequently other SciFi authors have borrowed the term.

Only for a moment, when he had located the control room and found the ansible and sat down before it, did he permit his mind-sense to drift over to the ship that sat east of this one. There he picked up a vivid sensation of a dubious hand hovering over a white Bishop. …

As his fingers (left hand only, awkwardly) struck each key, the letter appeared simultaneously on a small black screen in a room in a city on a planet eight lightyears distant:

From Rocannon’s World, by Ursula LeGuin.

Michael DeHaan the creator of Ansible took inspiration for the name Ansible from the book ‘Enders Game’ by Orson Scott Card (note to self must read book / watch the film) in the book Ansible is used to control a large number of remote ships at once, over large distances.  From now on whenever I mention Ansible it will be to control remote servers not ships, however it would be useful to be able to control my Elite Dangerous craft remotely.

What is Ansible ?

Ansible is often lumped into the DevOps tool category of ‘Configuration Management’ and compared to Puppet, Chef & Salt. The term ‘Configuration Management’ is generally used to describe the management of the state of IT infrastructure, which can include servers, storage arrays and databases etc…

When you need to deploy configuration change across multiple platforms ‘Orchestration’ is often required to ensure the correct sequence of events, e.g. you may need to configure storage volumes, Unix mount points all before you can start a database service. Ansible is pretty good a conductor, orchestrating actions across multiple servers.

Why use Ansible

Ansible and Salt both use a ‘Push’ method of communication that does not not require any agents to be installed on remote servers. Ansible’s only requirements are SSH connectivity to the remote servers and for the servers to have Python 2.5 installed. I have not yet had the opportunity to take Salt for a test ride, so I can’t comment on it’s requirements.

Puppet and Chef have taken a ‘Pull-based’ approach, where agents installed on the remote servers periodically check in with a central server and pull down configuration information.

The ‘Push-based’ approach has a significant advantage over ‘Pull-based’ solutions as you can control when a configuration change is implemented rather than having to wait for a timer to expire in a ‘Pull-based’ solution.

My next Blog Post will be ‘Getting Started with Ansible and Oracle’.

Hope to get it out very soon, if you want to know when it’s ready use the below to follow me.

Downloading Oracle E-Business Suite R12.2.6 using wget

When it’s time for you to next download the Oracle E-Business Suite media you better plan ahead as it’s getting big, really big, R12.2.6 is now over 83GB and could take a considerable amount of time if your downloading it interactively.

Fortunately Oracle’s e-delivery website can help out.

Select your Options

Firstly, uncheck all the ‘Oracle E-Business Suite Languages (12.2.0.0.0)’ and ‘Oracle E-Business Suite Languages (12.2.6.0.0)’ not required.

Now, if you are only performing a ‘VISION’ installation you can uncheck the all files labeled ‘Oracle E-Business Suite Release 12.2.0 for Linux x86-64 Rapid Install Databases PROD – Disk X’.

Alternatively, if you don’t want the ‘VISION’ database uncheck all the files labeled ‘Oracle E-Business Suite Release 12.2.0 for Linux x86-64 Rapid Install Databases VISION – Disk X’.

WGET Options

Now we have selected our files, look for ‘WGET Options’ in the bottom left corner and click the link.

edelivery

This opens up a new window allowing you to download a wget script, hit ‘Download.sh’ to download the script to your desktop.

wget_options

Great, you now have a script you can run on your Linux/Unix server to ‘pull’ back all the files, you now need to copy the wget script to your server using scp for example.

Once copied over, open the script in your editor of choice, and find the references to ‘SSO_USERNAME’ and ‘SSO_PASSWORD’.

Update these to your Oracle SSO (Single Sign-On) credentials, save the file and then change the permissions to 755 to make it executable and your now good to go.

# SSO username and password
#read -p ‘SSO User Name:’ SSO_USERNAME
#read -sp ‘SSO Password:’ SSO_PASSWORD
SSO_USERNAME=john.smith@oracle.com
SSO_PASSWORD=maryjane

Note: The WGET download script does not provide any feedback about whether or not the script was successful. Therefore you need to view the log file to verify the download was a successful or to troubleshoot any issues. The log file by default will be called wgetlog-.log, however you can change the name and location in the wget script file by setting the following:

# Log directory and file
LOGDIR=.
LOGFILE=$LOGDIR/wgetlog-`date +%m-%d-%y-%H:%M`.log

Resizing Oracle ASM disks

Today I though I would share with how easy it is to resize Oracle ASM volumes with Pure Storage.

Ok, lets first check the Oracle ASM disk sizes using ‘asmcmd -p’

asmcli_pre.png

As you can see from the above, I have 3 volumes each of 100GB, for this test let’s increase them all to 1TB using the purevol command from with the CLI.

Pure_resize.png

Great, my volumes have now al been resized, I could have achieved the same results with the Pure UI or Web Services, but that’s something for another day.

Linux device rescan

Ok, we now need to let Linux and Oracle know about our resized volumes.

As root rescan the SCSI devices to identify which volumes which have been resized using:

rescan-scsi-bus.sh -s

Use ‘multipathd -k ‘resize map ‘ to resize the multipath devices e.g.

multipathd -k'resize map slob-data'

Before you moving onto resizing the Oracle ASM disk groups check your updated multi path configuration with ‘multipath -ll’, look for your device name and size e.g.

slob-data (3624a937050c939582b0f46c000059779) dm-5 PURE,FlashArray      size=1.0T features='0' hwhandler='0' wp=rw
`-+- policy='queue-length 0' prio=1 status=active
...

Oracle ASM resize

As your ‘grid’ user connect as sysasm from sqlplus e.g. sqlplus / as sysasm and perform ‘alter disk group <dg_name> resize all’

sqlplus_resize

Great, job done, but before we more on let’s check out work first using sqlplus as sysasm

SQL>  select name, total_mb/(1024) "Total GiB" from v$asm_diskgroup;
NAME                           Total GiB
------------------------------ ----------
CONTROL_REDO                   1024
FRA                            1024
DATA                           1024

And, now with the ASM command line utility ‘asmcmd’

asmcli_post.png

Or if you prefer the ASM UI ‘asmca’.

asmca.png