Skip to content

Commit

Permalink
oraswdb_manage_patches: refresh opatch lsinv after opatch rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
Rendanic committed Feb 2, 2024
1 parent adfa29d commit 861a8c8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 20 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/opatch_apply.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- "oraswdb_manage_patches: refresh opatch lsinv after opatch rollback (oravirt#405)"
24 changes: 4 additions & 20 deletions roles/oraswdb_manage_patches/tasks/loop_db-home-patch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@
- name: Upgrade OPatch
ansible.builtin.include_tasks: opatch-upgrade.yml

- name: Get list of current installed patches
ansible.builtin.command: "{{ oracle_home_db }}/OPatch/opatch lspatches -oh {{ oracle_home_db }}"
become: true
become_user: "{{ oracle_user }}"
changed_when: false
register: dbhome_patches

- name: List of current installed patches
ansible.builtin.debug:
var: dbhome_patches.stdout_lines
- name: opatch lspatches
ansible.builtin.include_tasks: opatch_lsinv.yml

- name: Configure ocm.rsp (1)
ansible.builtin.template:
Expand Down Expand Up @@ -132,13 +124,5 @@
vars:
__opatchauto_patchtype: false # opatch apply

- name: Check patches
ansible.builtin.command: "{{ oracle_home_db }}/OPatch/opatch lspatches -oh {{ oracle_home_db }}"
become: true
become_user: "{{ oracle_user }}"
changed_when: false
register: dbhome_patches

- name: Check patches
ansible.builtin.debug:
var: dbhome_patches.stdout_lines
- name: opatch lspatches
ansible.builtin.include_tasks: opatch_lsinv.yml
35 changes: 35 additions & 0 deletions roles/oraswdb_manage_patches/tasks/loop_patchid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
# - "{{ oracle_sw_patches | selectattr('patchid', 'equalto', dhc_opatch.patchid) }}"
# - "{{ dhc_opatch.patchid }}"

# Refresh opatch inventory in ansible before next apply
# but after a rollback in loop before
- name: Refresh opatch inventory after opatch rollback
when:
- dhc_opatch.state == 'present'
- _refresh_opatch_inv_before_apply | default(false)
ansible.builtin.include_tasks: opatch_lsinv.yml

- name: Set state for opatch inventory refresh before next apply
ansible.builtin.set_fact:
_refresh_opatch_inv_before_apply: true
when:
- dhc_opatch.state == 'absent'

- name: loop_Patchid | Work on oracle_sw_patches
ansible.builtin.include_tasks: loop_opatch_apply.yml
vars:
Expand Down Expand Up @@ -69,6 +83,27 @@
state: "{{ dhc_opatch.state }}"
become: true
become_user: "{{ __opatchauto_patchtype | ternary('root', oracle_user) }}"
register: _oracle_opatch_res
vars:
__patch_localsubdir: >-
{{ dhc_opatch.excludeUPI | default(dhc_opatch.patchid) }}/{{ dhc_opatch.patchid | string }}
when:
- (
dhc_opatch.state == 'absent'
or
(
dhc_opatch.state == 'present'
and not dbhome_patches.stdout_lines | select('match', dhc_opatch.patchid | string) | length > 0
)
)

# opatch rollback + opatch apply with same patchid but different unique_id possible
# => we need to refresh our inventory in ansible to reflect the changed situation in opathch inventory
# => Refresh only after 'absent' when next loop item is 'present'
# Prevent lots of refreshes, when multiple patches are removed!
- name: Set state for opatch inventory refresh before next apply
ansible.builtin.set_fact:
_refresh_opatch_inv_before_apply: true
when:
- dhc_opatch.state == 'absent'
- _oracle_opatch_res.changed
17 changes: 17 additions & 0 deletions roles/oraswdb_manage_patches/tasks/opatch_lsinv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
- name: Get list of current installed patches
ansible.builtin.command: "{{ oracle_home_db }}/OPatch/opatch lspatches -oh {{ oracle_home_db }}"
become: true
become_user: "{{ oracle_user }}"
changed_when: false
register: dbhome_patches

- name: List of current installed patches
ansible.builtin.debug:
var: dbhome_patches.stdout_lines

- name: reset state for opatch inventory refresh
ansible.builtin.set_fact:
_refresh_opatch_inv_before_apply: false
when:
- _refresh_opatch_inv_before_apply | default(true)

0 comments on commit 861a8c8

Please sign in to comment.