AIAzureMicrosoftOracle

ChatGPT- Building Out Oracle with Templates and Ansible for a DataGuard Environment

This is a continuation of the evolution of AI with ChatGPT and how much it can be leveraged, allowing me to do more with less time.  As a DBA, many times I’m copying and pasting past versions of code, then making changes to do what needs to be done each day.  the idea that ChatGPT could do some of this FOR ME is very attractive.  It’s still in its infancy, but I’m thrilled to say, it’s getting better every day and you get out of it what you put in….as in prompts.

This week, one of my prompts with the new ChatGPT 4 was the following.  First of two requests:

Create an azure template with variables to create two Oracle Linux VMs with Oracle 19c image

{
“$schema”: “<>/schemas/2019-04-01/deploymentTemplate.json#”,
“contentVersion”: “1.0.0.0”,
“parameters”: {
“adminUsername”: {
“type”: “string”,
“metadata”: {
“description”: “Username for the Virtual Machines.”
}
},
“adminPassword”: {
“type”: “securestring”,
“metadata”: {
“description”: “Password for the Virtual Machines.”
}
},
“location”: {
“type”: “string”,
“defaultValue”: “[resourceGroup().location]”,
“metadata”: {
“description”: “Location for all resources.”
}
},
“vmSize”: {
“type”: “string”,
“defaultValue”: “Standard_D2s_v3”,
“metadata”: {
“description”: “Size for the Virtual Machines.”
}
}
},
“variables”: {
“vmNamePrefix”: “OracleLinuxVM”,
“networkInterfaceNamePrefix”: “OracleLinuxNIC”,
“virtualNetworkName”: “OracleLinuxVNet”,
“subnetName”: “OracleLinuxSubnet”,
“publicIPAddressNamePrefix”: “OracleLinuxPublicIP”,
“oracle19cImage”: {
“publisher”: “Oracle”,
“offer”: “Oracle-Linux”,
“sku”: “19c”,
“version”: “latest”
},
“copy”: [
{
“name”: “vmLoop”,
“count”: 2,
“input”: {
“vmName”: “[concat(variables(‘vmNamePrefix’), copyIndex(‘vmLoop’))]”,
“networkInterfaceName”: “[concat(variables(‘networkInterfaceNamePrefix’), copyIndex(‘vmLoop’))]”,
“publicIPAddressName”: “[concat(variables(‘publicIPAddressNamePrefix’), copyIndex(‘vmLoop’))]”
}
}
]
},
“resources”: [
{
“type”: “Microsoft.Network/virtualNetworks”,
“apiVersion”: “2020-08-01”,
“name”: “[variables(‘virtualNetworkName’)]”,
“location”: “[parameters(‘location’)]”,
“properties”: {
“addressSpace”: {
“addressPrefixes”: [
“10.0.0.0/16”
]
},
“subnets”: [
{
“name”: “[variables(‘subnetName’)]”,
“properties”: {
“addressPrefix”: “10.0.1.0/24”
}
}
]
}
},
{
“type”: “Microsoft.Network/publicIPAddresses”,
“apiVersion”: “2020-08-01”,
“name”: “[variables(‘vmLoop’)[copyIndex()].publicIPAddressName]”,
“location”: “[parameters(‘location’)]”,
“copy”: {
“name”: “publicIPCopy”,
“count”: 2
},
“properties”: {
“publicIPAddressVersion”: “IPv4”,
“publicIPAllocationMethod”: “Dynamic”
}
},
{
“type”: “Microsoft.Network/networkInterfaces”,
“apiVersion”: “2020-08-01”,
“name”: “[variables(‘vmLoop’)[copyIndex()].networkInterfaceName]”,
“location”: “[parameters(‘location’)]”,
“copy”: {
“name”: “networkInterfaceCopy”,
….

Second Request-  Create an Ansible Playbook to create a Dataguard environment from the VMs that the template builds.

ChatGPT 4: To create an Ansible playbook for setting up an Oracle Active Data Guard environment on two existing Azure Oracle Linux VMs, follow these steps:

    1. Install Ansible on your control machine if it’s not already installed.
    2. Create an inventory file named inventory.ini with the following contents:

[primary]
oracle_primary ansible_host=<Primary_VM_Public_IP>

[standby]
oracle_standby ansible_host=<Standby_VM_Public_IP>

 

ChatGPT 4: Replace <Primary_VM_Public_IP> and <Standby_VM_Public_IP> with the public IPs of your primary and standby VMs.

  1. Create an Ansible playbook named oracle_active_dataguard.yml with the following contents:

 


– name: Set up Oracle Active Data Guard
hosts: primary, standby
become: true
tasks:
– name: Install necessary packages
yum:
name:
– oracle-database-preinstall-19c
– oracle-database-ee-19c
– oracle-asm-19c
state: present

– name: Configure primary database
hosts: primary
become: true
tasks:
– name: Set up primary database
shell: |
# Your commands to configure the primary database, e.g.
# – Create directories
# – Set environment variables
# – Configure listener.ora, tnsnames.ora, and sqlnet.ora
# – Create a primary database
# – Enable Force Logging
# – Configure ARCHIVELOG mode
# – Configure Oracle Net Services
args:
executable: /bin/bash

– name: Configure standby database
hosts: standby
become: true
tasks:
– name: Set up standby database
shell: |
# Your commands to configure the standby database, e.g.
# – Create directories
# – Set environment variables
# – Configure listener.ora, tnsnames.ora, and sqlnet.ora
# – Create a standby database
# – Enable Managed Recovery Process (MRP)
# – Configure Oracle Net Services
args:
executable: /bin/bash

– name: Enable Data Guard Broker
hosts: primary
become: true
tasks:
– name: Set up Data Guard Broker
shell: |
# Your commands to configure Data Guard Broker, e.g.
# – Enable Data Guard Broker in primary and standby databases
# – Configure broker configuration files (dataguard_broker.ora)
# – Create a broker configuration
# – Add primary and standby databases to the broker configuration
# – Enable Fast-Start Failover (FSFO)
# – Validate the Data Guard configuration
args:
executable: /bin/bash

ChatGPT 4: Replace the comments under shell tasks with actual commands required to configure the primary, standby, and Data Guard Broker.

  1. Execute the playbook with the following command:

ansible-playbook -i inventory.ini oracle_active_dataguard.yml

This will configure the Oracle Active Data Guard environment on the two specified VMs we created with the template in the first part of this blog post.  Pretty cool and it’s coming along nicely!

 

 

Kellyn

http://about.me/dbakevlar

One thought on “ChatGPT- Building Out Oracle with Templates and Ansible for a DataGuard Environment

Comments are closed.