giovedì 6 marzo 2014

PowerCLI: Automate Oracle DB install using Invoke-VMScript

I only recently discovered how cool and powerful is Invoke-VMScript, a VMware PowerCLI cmdlet that allows you to run scripts inside the guest VM operating system.
It requires VMware Tools installed and running inside the guest OS in order to successfully inject commands and scripts from the ESXi host to the VM and it is noteworthy to say that not all operating systems are supported by Invoke-VMScript cmdlet.
Supported ones, according to official documentation, are: Windows XP 32bit SP3, Windows Server 2003 32bit SP2, Windows Server 2003 64bit SP2, Windows 7 64bit, Windows Server 2008 R2 64bit and RHEL 5.

Invoke-VMScript syntax is:

Invoke-VMScript [-ScriptText] <String> [-VM] <VirtualMachine[]> [-HostCredential <PSCredential>] [-HostUser <String>] [-HostPassword <SecureString>] [-GuestCredential <PSCredential>] [-GuestUser <String>] [-GuestPassword <SecureString>] [-ToolsWaitSecs <Int32>] [-ScriptType <ScriptType>] [-RunAsync] [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]


HostCredential: username and password for the ESXi host on which resides the virtual machine.
GuestCredential: username and password for the guest OS. The user must have administrative access.
ScriptType: what kind of script you want to invoke: PowerShell, Bat or Bash.

In this article I provide a simple PowerCLI script which allows you to deploy virtual machines from a Win2008 R2 template and perform an automated silent install of Oracle Database 11g R2.

This is just an example of Invoke-VMScript usage and this only provides a software install, neither listener neither instance are configured. This script could also be readapted/improved for RHEL installs.

How this script works:

-Connects to a vCenter or ESXi host.
-Deploys "N" virtual machines from a properly prepared (read a few lines below to find how) Win2008 template.
-Power on the virtual machine.
-Perform a silent, fully automated, install of Oracle Database 11g R2 software by using Invoke-VMScript cmdlet.

Preprequisite for this PowerCLI script are:

-A Windows 2008 R2 virtual machine
-Oracle Database 11g R2 11.2.0.X. Unzip installation files on the Desktop. This script assumes that your installation directory is placed on: C:\Users\Administrator\Desktop\database
-Response file: a response file is a text file which is used by Oracle to perform silent installs. It contains all infos that usually are inserted by the user in a common GUI installation. This script assumes that your response file is: C:\Users\Administrator\Desktop\install.rsp

This is the content of my install.rsp response file.

 INVENTORY_LOCATION=C:\Program Files\Oracle\Inventory\logs  

So, to recap: unzip Oracle DB installation files on the Desktop and place install.rsp in the same location as depicted by the following image.

This is the PowerCLI code, as usual you can also find it on my GitHub repository: Invoking Scripts in Guest-VM.ps1

Run it and deployment of virtual machines from template begins:

After script completion VMs are correctly added to vCenter Server inventory

and Oracle Database is installed inside guest OS.

To perform a full install of Oracle Database the listener and an instance must also be configured. This can be done using a response file and run using PowerCLI Invoke-VMScript.

If you need a standard listener configuration netca.rsp file provided in database\response installation directory does the job.

Listener silent install is performed by running:

 netca -silent -responseFile C:\Users\Administrator\Desktop\database\response\netca.rsp  

Similarly database instance can be added by invoking the Database Configuration Assistant (dbca) in silent install mode using a response file or passing all required configurations as parameters.

For example:

 dbca -silent -createDatabase -templateName General_Purpose.dbc -gdbname orcl -sid orcl -gdbName orcl -memoryPercentage 30 -sysPassword welcome1 -systemPassword welcome1 -dbsnmppassword welcome1 -emConfiguration LOCAL -redoLogFileSize 100 -storageType FS -datafileDestination C:\app\Administrator\oradata -datafileJarLocation C:\app\Administrator\product\11.2.0\dbhome_1\assistants\dbca\templates -characterSet AL32UTF8 -sampleSchema false -totalMemory 512  

That's all!!

2 commenti:

  1. Thanks for the great article. i really appreciate it. I have been making research on the internet for a very long time and now come up with something useful.Application Release Management

  2. Really excellent job u have done... All informations at a hand... Really good. Thank u.i have set up using the same, but everything goes perfect. Thanks
    Software Installation Automation