Oracle Home Installation with Ansible Role

As mentioned in the previous post (https://www.julianfrey.ch/2018/09/10/18-3-silent-installation-including-patching/ ), I provide the ansible Role for executing the installation in a automated way.

Fort this Role I defined a default file with the following variables which are needed for the binary installation.

filepath: is the location of the rdbms binaries. This path is located in the role directory in a folder called files
psupath: is the path to the latest patch, which should be applied. This path is located in the role directory in a folder called files
tmppsu: is the path on the server where the psu (or the RU) should be extracted
ORACLE_INVENTORY: is the location on the server of the oracle inventory
ORACLE_HOME: is the path where the binaries will be installed
ORACLE_HOME_NAME: is the name for the ORACLE_HOME in the Oracle Inventory
ORACLE_BASE: is the location of the ORACLE_BASE where the diag directory and many more will be located
DBA_GROUP: OS User Group for the DBAs
OPER_GROUP: OS User Group for the Operators
OSBACKUPDBA_GROUP: OS User Group for the BACKUP DBAs (SYSBACKUP will be granted)
OSDGDBA_GROUP:  OS User Group for the Dataguard Admins (SYSDG will be granted)
OSKMDBA_GROUP: OS User Group for encryption (SYSKM will be granted)
OSRACDBA_GROUP: OS User Group for RAC Admins (SYSRAC will be granted)

All these variables can be set in a playbook which invokes this role or can be set directly in this role. According to the documentation the following precedence is in place:

  • role defaults [1]
  • inventory file or script group vars [2]
  • inventory group_vars/all [3]
  • playbook group_vars/all [3]
  • inventory group_vars/* [3]
  • playbook group_vars/* [3]
  • inventory file or script host vars [2]
  • inventory host_vars/*
  • playbook host_vars/*
  • host facts / cached set_facts [4]
  • inventory host_vars/* [3]
  • playbook host_vars/* [3]
  • host facts
  • play vars
  • play vars_prompt
  • play vars_files
  • role vars (defined in role/vars/main.yml)
  • block vars (only for tasks in block)
  • task vars (only for the task)
  • include_vars
  • set_facts / registered vars
  • role (and include_role) params
  • include params
  • extra vars (always win precedence)
---
filepath: rdbms
psupath: psu
tmppsu: /u01/install
ORACLE_INVENTORY: /u01/app/oraInventory
ORACLE_HOME: /u01/app/oracle/product/18.3/dbhome_1
ORACLE_HOME_NAME: "RDBMS183"
ORACLE_BASE: /u01/app/oracle
edition: EE
DBA_GROUP: dba
OPER_GROUP: oper
OSBACKUPDBA_GROUP: backupdba
OSDGDBA_GROUP: dgdba
OSKMDBA_GROUP: kmdba
OSRACDBA_GROUP: racdba

The Role itself contains multiple tasks which either creates directories or installs the ORACLE HOME. All tasks are described below.

Check if Binaries already installed: This tasks checks if the binaries with the same ORACLE_HOME_NAME are already present in the Oracle Inventory.
Oracle Home installation: This is a named block. This block is only executed if the return code of the shell command in the first task is not equals to 1. As defined in the last line: “when: binary_available.rc != 1”
Create directory for installation files: Due to the circumstances that since Oracle 18c the directory where the ORACLE_HOME will be is the same as the extraction directory, the ORACLE HOME directory is created.
Create directory for psu files: This task creates the directory where the PSU or RU will be extracted (if there is a Patch located in psupath directory
Extract install binaries {{ ORACLE_HOME }}: This task extracts Oracle Binaries to the ORACLE_HOME
Extract PSU {{ tmppsu }}”: This task extracts the PSU or RU to the previously created directory
Rename PatchSearch.xml to bundle.xml (Installer does search for bundle.xml): Due to the circumstances that the Oracle installer is searching for a file called bundle.xml we have to rename the PatchSearch.xml to bundle.xml
Install oracle {{ ORACLE_HOME_NAME }}: In this Task the ORACLE_HOME will be installed according to the defined variables
Run orainstRoot.sh if required: If the execution of orainstRoot.sh is required (if the string “/u01/app/oraInventory/orainstRoot.sh” is shown in the output) then the orainstRoot.sh will be executed
Run root.sh: This task executes the root.sh

---
- name: "Check if Binaries already installed"
  shell: grep "={{ ORACLE_HOME_NAME }}" {{ ORACLE_INVENTORY }}/ContentsXML/inventory.xml
  register: binary_available
  failed_when: false

- name: "Oracle Home installation"
  block:
  - name: "Create directory for installation files"
  action: file dest={{ ORACLE_HOME }} state=directory owner=oracle group=oinstall
  become: true

  - name: "Create directory for psu files"
    action: file dest={{ tmppsu }} state=directory owner=oracle group=oinstall
    become: true

  - name: "Extract install binaries {{ ORACLE_HOME }}"
    become: true
    become_user: oracle
    unarchive:
      src: "{{ item }}"
      dest: "{{ ORACLE_HOME }}"
    with_fileglob: '{{ filepath }}/*.zip'

  - name: "Extract PSU {{ tmppsu }}"
    become: true
    become_user: oracle
    unarchive:
      src: "{{ item }}"
      dest: "{{ tmppsu }}"
    with_fileglob: '{{ psupath }}/*.zip'

  - name: "Rename PatchSearch.xml to bundle.xml (Installer does search for bundle.xml)"
    command: mv {{ tmppsu }}/PatchSearch.xml {{ tmppsu }}/bundle.xml

  - name: "Install oracle {{ ORACLE_HOME_NAME }}"
    shell: |
      {{ ORACLE_HOME }}/runInstaller -silent \
      -force -waitforcompletion oracle.install.option=INSTALL_DB_SWONLY UNIX_GROUP_NAME=oinstall \
      INVENTORY_LOCATION={{ ORACLE_INVENTORY }} \
      ORACLE_BASE={{ ORACLE_BASE }} \
      ORACLE_HOME_NAME={{ ORACLE_HOME_NAME }} \
      oracle.install.db.InstallEdition={{ edition }} \
      oracle.install.db.DBA_GROUP={{ DBA_GROUP }} \
      oracle.install.db.OPER_GROUP={{ OPER_GROUP }} \
      oracle.install.db.BACKUPDBA_GROUP={{ OSBACKUPDBA_GROUP }} \
      oracle.install.db.DGDBA_GROUP={{ OSDGDBA_GROUP }}\
      oracle.install.db.KMDBA_GROUP={{ OSKMDBA_GROUP }} \
      oracle.install.db.OSRACDBA_GROUP={{ OSRACDBA_GROUP }} \
      DECLINE_SECURITY_UPDATES=true \
      -applyRU {{ tmppsu }}
    become: true
    become_user: oracle
    register: database_install
    failed_when: "'Successfully Setup Software.' not in database_install.stdout"

  - name: "Run orainstRoot.sh if required"
    shell: " /u01/app/oraInventory/orainstRoot.sh"
    when: "'/u01/app/oraInventory/orainstRoot.sh' in database_install.stdout"
    become: true

  - name: "Run root.sh"
    shell: "{{ ORACLE_HOME }}/root.sh -silent"
    become: true
  when: binary_available.rc != 1

Now we have installed an ORACLE_HOME in this case 18.4 totally autonomous.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.