Automating Oracle 23ai DB Deployment with Ansible Playbooks across Hosts

Prerequisites

  1. Install Python 3 and Ansible on the source (control) host.
  2. Install Python 3 on the destination (target) host (Ansible requires Python on the target).
  3. Ensure the source machine has passwordless SSH access to the destination machine as the appropriate user (oracle or via sudo).
  4. Create the oracle user on the destination machine and assign it to the dba and oinstall
  5. Ensure the oracle user has ownership and correct permissions on the default installation directory for the RPM method.

 

User Case:

Source host: oracle19c (Control machine where Ansible runs)

Destination host: localhost (Target machine where Oracle 23ai will be deployed)

Steps to prepare the Ansible inventory and playbook.

1,  Create the main folder manually (e.g., mkdir ansible-oracle-23ai-rpm)

2,  Create the sub-items:

  • inventory → Your inventory file or directory
  • yml → Your playbook file
  • files/ → A directory for any RPM files, templates, or scripts

Below snip for reference

3 – Copy the 23ai RPM file to Ansible files directory

Bash : cp /tmp/oracle-database-free-23ai-23.8-1.el9.x86_64.rpm / /home/oracle19c/ansible-oracle-23ai-rpm/files

And confirm that the .rpm file is exist on files directory.

4 – Inventory File (Inventory file will tell the Ansible on which host the playbook should run) Create the Inventory file to get the target machine detail by playbook

Example snip below.

5 – Create the Ansible playbook to install the 23ai on target machine

Below sample playbook for installing the 23ai DB using rpm file.

Yaml.

– name: Install Oracle 23ai Database RPM (Installation Only)
hosts: destination
become: true
vars:
oracle_rpm: “oracle-database-free-23ai-23.8-1.el9.x86_64.rpm”

tasks:
– name: Install preinstall package for Oracle 23ai
yum:
name: oracle-database-preinstall-23ai
state: present

– name: Copy Oracle 23ai RPM to target
copy:
src: “files/{{ oracle_rpm }}”
dest: “/tmp/{{ oracle_rpm }}”
mode: ‘0644’

– name: Install Oracle 23ai RPM
yum:
name: “/tmp/{{ oracle_rpm }}”
state: present

– name: Open port 1521 in firewall
firewalld:
port: 1521/tcp
permanent: true
state: enabled
immediate: yes

 

6 – Run the play book using the below cmd.

Bash : ansible-playbook -i inventory install_oracle_rpm.yml

7 – Create Configuration playbook under the Ansible directory.

Below sample yml for reference.

Yaml


– name: Configure Oracle 23ai Database after RPM installation
hosts: destination
become: false
vars:
oracle_password: “MySecurePass123” # Change to your secure password

tasks:
– name: Configure Oracle 23ai silently with password
shell: |
echo -e “{{ oracle_password }}\n{{ oracle_password }}” | sudo /etc/init.d/oracle-free-23ai configure
async: 1800 # Allow up to 30 minutes
poll: 5 # Poll every 5 seconds

– name: Enable and start Oracle database service
systemd:
name: oracle-free-23ai
enabled: true
state: started

– name: Open port 1521 in firewall
firewalld:
port: 1521/tcp
permanent: true
state: enabled
immediate: yes

8 – Run the configuration playbook cmd to configure the DB.

Bash : ansible-playbook -i inventory configure_oracle_23ai.yml

9 – Now check the target machine that the DB and listener is running.

Below snip for reference.

Now the 23ai has been deployed to the target host.

You can confirm by checking the Database  name and open_mode status in target host.

Below snip for reference.

Recent Posts