Skip to content

Commit b2320d3

Browse files
committed
oraswdb_manage_patches: Improved execution times
The installation time has been improved. Patches are only copied und unarchived when installation is needed. Cleanup of patch stage at end of role has been added.
1 parent ba5d6d8 commit b2320d3

File tree

9 files changed

+364
-302
lines changed

9 files changed

+364
-302
lines changed

roles/oraswdb_manage_patches/README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Manage Patch Installation in Database ORACLE_HOMEs.
55
## Table of content
66

77
- [Requirements](#requirements)
8+
- [Default Variables](#default-variables)
9+
- [oraswdb_manage_patches_cleanup_staging](#oraswdb_manage_patches_cleanup_staging)
810
- [Discovered Tags](#discovered-tags)
911
- [Dependencies](#dependencies)
1012
- [License](#license)
@@ -17,8 +19,24 @@ Manage Patch Installation in Database ORACLE_HOMEs.
1719
- Minimum Ansible version: `2.9.0`
1820

1921

22+
## Default Variables
23+
24+
### oraswdb_manage_patches_cleanup_staging
25+
26+
Remove following list of directories after DB-Patching when `oracle_sw_copy: true`:
27+
28+
- "{{ oracle_stage }}/patches"
29+
30+
#### Default value
31+
32+
```YAML
33+
oraswdb_manage_patches_cleanup_staging: true
34+
```
35+
2036
## Discovered Tags
2137
38+
**_always_**
39+
2240
**_apply_patch_db_**
2341
2442
**_autopatch_**
@@ -27,6 +45,8 @@ Manage Patch Installation in Database ORACLE_HOMEs.
2745
2846
**_directories_**
2947
48+
**_molecule-idempotence-notest_**
49+
3050
**_nfsmountdb_**
3151
3252
**_nfsumountdb_**
@@ -35,16 +55,12 @@ Manage Patch Installation in Database ORACLE_HOMEs.
3555
3656
**_oragridopatchget_**
3757
38-
**_oragridpatchget_**
39-
4058
**_oragridpatchpush_**
4159
4260
**_oragridpatchunpack_**
4361
4462
**_oraswdbpsuunpack1_**
4563
46-
**_oraswdbpsuunpack2_**
47-
4864
4965
## Dependencies
5066
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
---
2+
# @var oraswdb_manage_patches_cleanup_staging:description: >
3+
# Remove following list of directories after DB-Patching when `oracle_sw_copy: true`:
4+
#
5+
# - "{{ oracle_stage }}/patches"
6+
# @end
7+
oraswdb_manage_patches_cleanup_staging: true

roles/oraswdb_manage_patches/tasks/db-home-patch.yml renamed to roles/oraswdb_manage_patches/tasks/loop_db-home-patch.yml

Lines changed: 48 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@
55
msg: "Managing patches for {{ oracle_home_db }}"
66
when: apply_patches_db
77

8-
- name: Transfer files
9-
ansible.builtin.include_tasks: transfer-files.yml
10-
when: oracle_sw_copy
11-
12-
- name: Unpack uploaded files
13-
ansible.builtin.include_tasks: unpack-files.yml
14-
when: oracle_sw_unpack and apply_patches_db
15-
168
- name: Upgrade OPatch
179
ansible.builtin.include_tasks: opatch-upgrade.yml
18-
when: apply_patches_db
1910

20-
- name: db_opatch | Configure ocm.rsp (1)
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
21+
22+
- name: Configure ocm.rsp (1)
2123
ansible.builtin.template:
2224
src: ocmrsp.expect.j2
2325
dest: "={{ oracle_patch_stage }}/{{ db_version }}/ocmrsp.expect"
24-
mode: "0777"
26+
mode: "0644"
2527
force: true
2628
when:
2729
- apply_patches_db
@@ -31,9 +33,8 @@
3133
tags:
3234
- ocmconfig
3335

34-
- name: db_opatch | Configure ocm.rsp (2)
35-
ansible.builtin.shell: "{{ oracle_patch_stage }}/{{ db_version }}/ocmrsp.expect"
36-
# noqa command-instead-of-shell
36+
- name: Configure ocm.rsp (2)
37+
ansible.builtin.command: "{{ oracle_patch_stage }}/{{ db_version }}/ocmrsp.expect"
3738
when:
3839
- apply_patches_db
3940
- current_opatch_version.msg is version_compare('12.2.0.1.5', '<')
@@ -43,7 +44,7 @@
4344
tags:
4445
- ocmconfig
4546

46-
- name: db_opatch | Remove unwanted patches from DB
47+
- name: Remove unwanted patches from DB
4748
opitzconsulting.ansible_oracle.oracle_opatch:
4849
oracle_home: "{{ oracle_home_db }}"
4950
patch_base: "{{ oracle_patch_install }}/{{ db_version }}/{{ item.path | default(item.patchid) }}/"
@@ -65,9 +66,10 @@
6566
when:
6667
- apply_patches_db | bool
6768
- db_homes_config[dbh.home]['opatch'] is defined
69+
- dbhome_patches.stdout_lines | select('match', item.patchid | string) | length > 0
6870
register: psuapplym
6971

70-
- name: db_opatch | Manage opatchauto patches for DB (non-gi)
72+
- name: Manage opatchauto patches for DB (non-gi)
7173
opitzconsulting.ansible_oracle.oracle_opatch:
7274
oracle_home: "{{ oracle_home_db }}"
7375
patch_base: "{{ oracle_patch_install }}/{{ db_version }}/{{ item.0.path | default (item.0.patchid) }}/{{ item.1 }}"
@@ -95,63 +97,48 @@
9597
- not olrloc.stat.exists
9698
register: psuapplym
9799

98-
- name: db_opatch | Manage opatchauto patches for DB (gi)
99-
opitzconsulting.ansible_oracle.oracle_opatch:
100-
oracle_home: "{{ oracle_home_db }}"
101-
patch_base: "{{ oracle_patch_install }}/{{ db_version }}/{{ item.path | default(item.patchid) }}/"
102-
patch_id: "{{ item.patchid }}"
103-
patch_version: "{{ item.patchversion | default(omit) }}"
104-
opatchauto: true
105-
conflict_check: true
106-
ocm_response_file: "{{ ocm_response_file | default(omit) }}"
107-
output: verbose
108-
state: "{{ item.state }}"
100+
- name: Manage Patch from db_home_config with opatchauto
101+
ansible.builtin.include_tasks: loop_patchid.yml
109102
with_items:
110103
- "{{ db_homes_config[dbh.home]['opatchauto'] }}"
111-
# run_once: "{{ _oraswgi_meta_configure_cluster}}"
112-
become: true
113-
tags:
114-
- apply_patch_db
104+
loop_control:
105+
loop_var: dhc_opatch
106+
label: >-
107+
home: {{ dbh.home | default('') }}
108+
patchid: {{ dhc_opatch.patchid | default('') }}
109+
state: {{ dhc_opatch.state | default('') }}
110+
excludeUPI: {{ dhc_opatch.excludeUPI | default('') }}
115111
when:
116-
- apply_patches_db and db_homes_config[dbh.home]['opatchauto'] is defined
117-
- olrloc.stat.exists
118-
register: psuapplym
112+
- db_homes_config[dbh.home]['opatchauto'] is defined
113+
- dhc_opatch.state | default('') == 'present'
114+
vars:
115+
__opatchauto_patchtype: true # opatch opatchauto
119116

120-
# Do not try to revert patches here
121-
# => That was done with a previous task!
122-
- name: db_opatch | Manage patches for DB
123-
opitzconsulting.ansible_oracle.oracle_opatch:
124-
oracle_home: "{{ oracle_home_db }}"
125-
patch_base: "{{ oracle_patch_install }}/{{ db_version }}/{{ item.path | default(item.patchid) }}/"
126-
patch_id: "{{ item.patchid }}"
127-
patch_version: "{{ item.patchversion | default(omit) }}"
128-
exclude_upi: "{{ item.excludeUPI | default(omit) }}"
129-
opatchauto: false
130-
conflict_check: true
131-
stop_processes: "{{ item.stop_processes | default(False) }}"
132-
ocm_response_file: "{{ ocm_response_file | default(omit) }}"
133-
output: verbose
134-
state: "{{ item.state }}"
117+
# manage-patch does everything for 1 patch in a loop
118+
- name: Manage Patch from db_home_config with opatch
119+
ansible.builtin.include_tasks: loop_patchid.yml
135120
with_items:
136-
- "{{ db_homes_config[dbh.home]['opatch'] | selectattr('state', 'match', 'present') }}"
137-
# run_once: "{{ _oraswgi_meta_configure_cluster }}"
138-
become: true
139-
become_user: "{{ oracle_user }}"
140-
tags:
141-
- apply_patch_db
121+
- "{{ db_homes_config[dbh.home]['opatch'] }}"
122+
loop_control:
123+
loop_var: dhc_opatch
124+
label: >-
125+
home: {{ dbh.home | default('') }}
126+
patchid: {{ dhc_opatch.patchid | default('') }}
127+
state: {{ dhc_opatch.state | default('') }}
128+
excludeUPI: {{ dhc_opatch.excludeUPI | default('') }}
142129
when:
143-
- apply_patches_db
144130
- db_homes_config[dbh.home]['opatch'] is defined
145-
register: psuapplym
131+
- dhc_opatch.state | default('') == 'present'
132+
vars:
133+
__opatchauto_patchtype: false # opatch apply
146134

147-
- name: db_opatch | Check patches
148-
ansible.builtin.shell: "{{ oracle_home_db }}/OPatch/opatch lspatches -oh {{ oracle_home_db }}"
149-
# noqa command-instead-of-shell
135+
- name: Check patches
136+
ansible.builtin.command: "{{ oracle_home_db }}/OPatch/opatch lspatches -oh {{ oracle_home_db }}"
150137
become: true
151138
become_user: "{{ oracle_user }}"
152139
changed_when: false
153140
register: dbhome_patches
154141

155-
- name: db_opatch | Check patches
142+
- name: Check patches
156143
ansible.builtin.debug:
157144
var: dbhome_patches.stdout_lines
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
# Copy and create Stage-Directory for given Patch.
3+
# See main.yml for loop decriptions
4+
#
5+
6+
- name: State data for loop_opatch_apply.yml
7+
ansible.builtin.debug:
8+
msg:
9+
- >-
10+
patchid: {{ dhc_opatch.patchid | default('') }}
11+
unique_patchid: {{ osp_loop.unique_patchid | default('') }}
12+
- >-
13+
oracle_patch_stage: {{ oracle_patch_stage }}
14+
oracle_sw_copy: {{ oracle_sw_copy | bool }}
15+
is_sw_source_local: {{ is_sw_source_local | bool }}
16+
- >-
17+
creates: {{ __sw_patches_filename_creates }}
18+
patch_unarchive_dir: {{ __patch_unarchive_dir }}
19+
20+
- name: Become User to oracle
21+
become: true
22+
become_user: "{{ oracle_user }}"
23+
block:
24+
- name: db_opatch | Copy oracle DB patch (opatch) to server
25+
when:
26+
- oracle_sw_copy | bool
27+
- dhc_opatch.state == 'present'
28+
block:
29+
30+
- name: db_opatch | Check for unarchived patch archive
31+
ansible.builtin.stat:
32+
path: "{{ __patch_unarchive_dir }}/{{ __sw_patches_filename_creates }}"
33+
register: checkpatcharchiveres
34+
vars:
35+
__sw_patches_filename_creates: "{{ osp_loop.creates | default((dhc_opatch.patchid | string) + '/README.txt') }}"
36+
37+
- name: db_opatch | Copy oracle DB patch (opatch) to server (local)
38+
ansible.builtin.copy:
39+
src: "{{ oracle_sw_source_local }}/{{ osp_loop.filename }}"
40+
dest: "{{ oracle_stage }}/{{ osp_loop.filename }}"
41+
mode: "0644"
42+
force: false
43+
when:
44+
- is_sw_source_local | bool
45+
- not checkpatcharchiveres.stat.exists
46+
47+
- name: db_opatch | Copy oracle DB patch (opatch) to server (www)
48+
ansible.builtin.get_url:
49+
url: "{{ oracle_sw_source_www }}/{{ osp_loop.filename }}"
50+
dest: "{{ oracle_stage }}/{{ osp_loop.filename }}"
51+
mode: "0644"
52+
force: false
53+
when:
54+
- not is_sw_source_local | bool
55+
- not checkpatcharchiveres.stat.exists | bool
56+
57+
- name: db_opatch | Extract one-off patch files to patch base
58+
when:
59+
- oracle_sw_copy | bool
60+
- oracle_sw_unpack | bool
61+
- dhc_opatch.state == 'present'
62+
tags:
63+
- oraswdbpsuunpack1
64+
block:
65+
- name: db_opatch | Create destination folder for unarchive
66+
ansible.builtin.file:
67+
dest: "{{ __patch_unarchive_dir }}"
68+
mode: 0755
69+
state: directory
70+
71+
- name: db_opatch | Extract one-off patch files to patch base
72+
ansible.builtin.unarchive:
73+
src: "{{ oracle_stage }}/{{ osp_loop.filename }}"
74+
dest: "{{ __patch_unarchive_dir }}"
75+
creates: "{{ __patch_unarchive_dir }}/{{ __sw_patches_filename_creates }}"
76+
copy: false
77+
78+
- name: db_opatch | Remove patch archive from stage
79+
ansible.builtin.file:
80+
path: "{{ oracle_stage }}/{{ osp_loop.filename }}"
81+
state: absent
82+
when:
83+
- oracle_sw_copy | bool
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
- name: Work on Patch {{ dhc_opatch.patchid }}
3+
ansible.builtin.debug:
4+
msg:
5+
- >-
6+
name: {{ dbh.home }}
7+
home: {{ db_homes_config[dbh.home]['oracle_home'] | default('') }}
8+
- >-
9+
patchid: {{ dhc_opatch.patchid }}
10+
state: {{ dhc_opatch.state }}
11+
- >-
12+
stop_processes: {{ dhc_opatch.stop_processes | default('') }}
13+
opatch os user: {{ __opatchauto_patchtype | ternary('root', oracle_user) }}
14+
opatchauto: {{ __opatchauto_patchtype }}
15+
- >-
16+
excludeUPI: {{ dhc_opatch.excludeUPI | default('') }}
17+
patchsubdir: {{ __oraswdb_manage_patches_patchsubdir | default('') }}
18+
19+
- name: Work on oracle_sw_patches
20+
ansible.builtin.include_tasks: loop_opatch_apply.yml
21+
vars:
22+
__sw_patches_filename_creates: "{{ osp_loop.creates | default((dhc_opatch.patchid | string) + '/README.txt') }}"
23+
__patch_unarchive_dir: "{{ oracle_patch_stage }}/{{ db_version }}/{{ __patch_upisubdir }}/"
24+
__patch_upisubdir: >-
25+
{%- if osp_loop.unique_patchid is defined -%}
26+
upi_{{ osp_loop.unique_patchid -}}/{% endif -%}
27+
with_items:
28+
- "{{ oracle_sw_patches | selectattr('patchid', 'equalto', dhc_opatch.patchid) }}"
29+
loop_control:
30+
loop_var: osp_loop
31+
label: >-
32+
patchid: {{ osp_loop.patchid }}
33+
filename: {{ osp_loop.filename }}
34+
unique_patchid: {{ osp_loop.unique_patchid | default('') }}
35+
when:
36+
- apply_patches_db
37+
- dhc_opatch.state == 'present'
38+
- not dbhome_patches.stdout_lines | select('match', osp_loop.patchid | string) | length > 0
39+
- osp_loop.unique_patchid | default(0) == dhc_opatch.excludeUPI | default(0)
40+
41+
- name: Info
42+
ansible.builtin.debug:
43+
msg: Starting opatch apply. This could take some time to complete...
44+
45+
# opatchauto needs root user for execution
46+
- name: Manage patch for DB
47+
opitzconsulting.ansible_oracle.oracle_opatch:
48+
oracle_home: "{{ oracle_home_db }}"
49+
patch_base: >-
50+
{{ oracle_patch_install }}/{{ db_version }}/{{ dhc_opatch.path | default(__patch_upisubdir + (dhc_opatch.patchid | string)) }}
51+
patch_id: "{{ dhc_opatch.patchid }}"
52+
patch_version: "{{ dhc_opatch.patchversion | default(omit) }}"
53+
exclude_upi: "{{ dhc_opatch.excludeUPI | default(omit) }}"
54+
opatchauto: "{{ __opatchauto_patchtype }}"
55+
conflict_check: true
56+
stop_processes: "{{ dhc_opatch.stop_processes | default(False) }}"
57+
ocm_response_file: "{{ ocm_response_file | default(omit) }}"
58+
output: verbose
59+
state: "{{ dhc_opatch.state }}"
60+
become: true
61+
become_user: "{{ __opatchauto_patchtype | ternary('root', oracle_user) }}"
62+
vars:
63+
__patch_upisubdir: >-
64+
{%- if dhc_opatch.excludeUPI is defined -%}
65+
upi_{{ dhc_opatch.excludeUPI -}}/{% endif -%}

0 commit comments

Comments
 (0)