Automating Oracle Patching With Ansible

Recently I wrote a blog post for an Ansible module I wrote for Oracle patching. The blog post is published on Pythian’s blog.

You can read more at https://blog.pythian.com/automating-oracle-patching-with-an-ansible-module

The idea of the playbook and the module is to automate whole process when patching Oracle binaries with PSUs, BPs, RUs etc.

You can find the playbook and module on my GitHub page at https://github.com/iarsov/ansible-orapatch

README is available at https://github.com/iarsov/ansible-orapatch/blob/master/README.md

Expected actions performed by the module:

The module will identify what database instances, listeners and ASM instances are running.
The module will shutdown all listeners and database instances, only if the home from which services are running is being patched.
The module will start up all previously stopped services after it completes with patching*
The module will skip databases which are not in READ WRITE state**
The module will identify if a given database is in STANDBY or PRIMARY role***
The module always patches GI homes with opatchauto
The module always patches DB homes with opatch
The module will make multiple restarts of the databases and listeners during the process

*Assuming no error occurred and module did not fail during the patching process.
** Even if the databases are specified for patching
*** Databases in STANDBY role are not patched

3 Replies to “Automating Oracle Patching With Ansible”

  1. Hi Ivica,

    I got below syntax error.

    ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

    The error appears to have been in ‘/etc/ansible/roles/BP_conflict/tasks/main.yml’: line 36, column 11, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:

    always:
    – name: “[SYSTEM] End logger session”
    ^ here
    and play book is as below.

    – block:
    # MANDATORY
    #=====================================
    – name: “[SYSTEM] Ensure ‘orapatch’ log file exists”
    copy:
    content: “”
    dest: “{{ orapatch_logfile }}”
    force: no
    mode: 0666

    – name: “[SYSTEM] Start logger session”
    BP_conflict:
    function: START_LOGGER_SESSION
    no_log: True

    – name: Opatch version details
    include: bala.yml
    tags : opatc

    – name: Opatch lsinventory details
    include: lsinv.yml
    tags: lsinv

    – name: Conflict details for ORACLE And GRID Homes
    include: conflicts.yml
    tags: conflicts

    always:
    – name: “[SYSTEM] End logger session”
    BP_conflict:
    function: END_LOGGER_SESSION
    no_log: True

    – name: “[SYSTEM] Fetch orapatch logfile”
    fetch:
    fail_on_missing: yes

    1. Hi Balu,

      I have just tested the version uploaded to GitHub and it worked fine. Looks like you’ve made some changes to the file …tasks/main.yml. I see some new task items by your side in the output you’ve provided. If you can give me a link to download your version of the file I can take a look.

      First thing that comes to my mind is you can check the indentation, probably (maybe) you have forgotten some empty space or something related.

    2. https://github.com/balagred/ansible-orapatch, BP_Conflict.zip is the file name which is giving error and BP_conflict_bak is the working code but in this logging code is not written.

      I need the logging file should be transferred to control machine.

      Error Code as below:

      – block:
      # MANDATORY
      #=====================================
      – name: “[SYSTEM] Ensure ‘orapatch’ log file exists”
      copy:
      content: “”
      dest: “{{ orapatch_logfile }}”
      force: no
      mode: 0666

      – name: “[SYSTEM] Start logger session”
      BP_conflict:
      function: START_LOGGER_SESSION
      no_log: True

      – name: Opatch version details
      include: bala.yml
      tags : opatc

      – name: Opatch lsinventory details
      include: lsinv.yml
      tags: lsinv

      – name: Conflict details for ORACLE And GRID Homes
      include: conflicts.yml
      tags: conflicts

      always:
      – name: “[SYSTEM] End logger session”
      BP_conflict:
      function: END_LOGGER_SESSION
      no_log: True

      – name: “[SYSTEM] Fetch orapatch logfile”
      fetch:
      fail_on_missing: yes
      flat: yes
      src: “{{ orapatch_logfile }}”
      dest: “/tmp/orapatch-{{ inventory_hostname }}/”

      #

      Working Code:


      # tasks file for BP_conflict
      #
      – name: Opatch version details
      include: bala.yml
      tags : opatc

      – name: Opatch lsinventory details
      include: lsinv.yml
      tags: lsinv

      – name: Conflict details for ORACLE And GRID Homes
      include: conflicts.yml
      tags: conflicts

Leave a Reply

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