Skip to content

Commit 94dda06

Browse files
committed
oraswdb_manage_patches: refresh opatch lsinv after opatch rollback
1 parent adfa29d commit 94dda06

File tree

4 files changed

+59
-20
lines changed

4 files changed

+59
-20
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
bugfixes:
3+
- "oraswdb_manage_patches: refresh opatch lsinv after opatch rollback (oravirt#405)"

roles/oraswdb_manage_patches/tasks/loop_db-home-patch.yml

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,8 @@
88
- name: Upgrade OPatch
99
ansible.builtin.include_tasks: opatch-upgrade.yml
1010

11-
- name: Get list of current installed patches
12-
ansible.builtin.command: "{{ oracle_home_db }}/OPatch/opatch lspatches -oh {{ oracle_home_db }}"
13-
become: true
14-
become_user: "{{ oracle_user }}"
15-
changed_when: false
16-
register: dbhome_patches
17-
18-
- name: List of current installed patches
19-
ansible.builtin.debug:
20-
var: dbhome_patches.stdout_lines
11+
- name: opatch lspatches
12+
ansible.builtin.include_tasks: opatch_lsinv.yml
2113

2214
- name: Configure ocm.rsp (1)
2315
ansible.builtin.template:
@@ -132,13 +124,5 @@
132124
vars:
133125
__opatchauto_patchtype: false # opatch apply
134126

135-
- name: Check patches
136-
ansible.builtin.command: "{{ oracle_home_db }}/OPatch/opatch lspatches -oh {{ oracle_home_db }}"
137-
become: true
138-
become_user: "{{ oracle_user }}"
139-
changed_when: false
140-
register: dbhome_patches
141-
142-
- name: Check patches
143-
ansible.builtin.debug:
144-
var: dbhome_patches.stdout_lines
127+
- name: opatch lspatches
128+
ansible.builtin.include_tasks: opatch_lsinv.yml

roles/oraswdb_manage_patches/tasks/loop_patchid.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@
2525
# - "{{ oracle_sw_patches | selectattr('patchid', 'equalto', dhc_opatch.patchid) }}"
2626
# - "{{ dhc_opatch.patchid }}"
2727

28+
# Refresh opatch inventory in ansible before next apply
29+
# but after a rollback in loop before
30+
- name: Refresh opatch inventory after opatch rollback
31+
when:
32+
- dhc_opatch.state == 'present'
33+
- _refresh_opatch_inv_before_apply | default(false)
34+
ansible.builtin.include_tasks: opatch_lsinv.yml
35+
36+
- name: Set state for opatch inventory refresh before next apply
37+
ansible.builtin.set_fact:
38+
_refresh_opatch_inv_before_apply: true
39+
when:
40+
- dhc_opatch.state == 'absent'
41+
2842
- name: loop_Patchid | Work on oracle_sw_patches
2943
ansible.builtin.include_tasks: loop_opatch_apply.yml
3044
vars:
@@ -69,6 +83,27 @@
6983
state: "{{ dhc_opatch.state }}"
7084
become: true
7185
become_user: "{{ __opatchauto_patchtype | ternary('root', oracle_user) }}"
86+
register: _oracle_opatch_res
7287
vars:
7388
__patch_localsubdir: >-
7489
{{ dhc_opatch.excludeUPI | default(dhc_opatch.patchid) }}/{{ dhc_opatch.patchid | string }}
90+
when:
91+
- (
92+
dhc_opatch.state == 'absent'
93+
or
94+
(
95+
dhc_opatch.state == 'present'
96+
and not dbhome_patches.stdout_lines | select('match', dhc_opatch.patchid | string) | length > 0
97+
)
98+
)
99+
100+
# opatch rollback + opatch apply with same patchid but different unique_id possible
101+
# => we need to refresh our inventory in ansible to reflect the changed situation in opathch inventory
102+
# => Refresh only after 'absent' when next loop item is 'present'
103+
# Prevent lots of refreshes, when multiple patches are removed!
104+
- name: Set state for opatch inventory refresh before next apply
105+
ansible.builtin.set_fact:
106+
_refresh_opatch_inv_before_apply: true
107+
when:
108+
- dhc_opatch.state == 'absent'
109+
- _oracle_opatch_res.changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
- name: Get list of current installed patches
3+
ansible.builtin.command: "{{ oracle_home_db }}/OPatch/opatch lspatches -oh {{ oracle_home_db }}"
4+
become: true
5+
become_user: "{{ oracle_user }}"
6+
changed_when: false
7+
register: dbhome_patches
8+
9+
- name: List of current installed patches
10+
ansible.builtin.debug:
11+
var: dbhome_patches.stdout_lines
12+
13+
- name: reset state for opatch inventory refresh
14+
ansible.builtin.set_fact:
15+
_refresh_opatch_inv_before_apply: false
16+
when:
17+
- _refresh_opatch_inv_before_apply | default(true)

0 commit comments

Comments
 (0)