Skip to content

Commit 520c594

Browse files
bartowlRendanic
authored andcommitted
new role orasw_download_patches
1 parent 7854272 commit 520c594

File tree

4 files changed

+180
-0
lines changed

4 files changed

+180
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
minor_changes:
3+
- "added new orasw_download_patches role (oravirt#332)"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
# @var mos_login:description: Login name for My Oracle Support (required)
3+
# @var mos_password:description: Password for My Oracle Support (required)
4+
5+
# proxy support
6+
use_proxy: false
7+
http_proxy:
8+
https_proxy:
9+
no_proxy:
10+
11+
proxy_env:
12+
http_proxy: "{{ http_proxy }}"
13+
https_proxy: "{{ https_proxy }}"
14+
no_proxy: "{{ no_proxy }}"
15+
16+
oracle_plat_lang: 226P # Linux x86-64
17+
18+
opatchinfo: []
19+
20+
oracle_patch_download_dir: "{{ oracle_sw_source_local }}" # by default download to ansible controller stage area
21+
oracle_patch_download_host: "localhost" # by default download on ansible controller
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
galaxy_info:
3+
role_name: orasw_download_patches
4+
author: bartowl <[email protected]>
5+
description: Download all patches from Oracle
6+
company: OPITZ CONSULTING
7+
8+
license: license (MIT)
9+
10+
min_ansible_version: 2.9.0
11+
12+
platforms:
13+
- name: EL
14+
versions:
15+
- "6"
16+
- "7"
17+
- "8"
18+
19+
galaxy_tags:
20+
- oracle
21+
22+
dependencies:
23+
- role: orasw_meta
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
---
2+
- name: Download patches from Oracle on ansible-controller just once
3+
run_once: true
4+
delegate_to: "{{ oracle_patch_download_host }}"
5+
block:
6+
- name: Check if credentials are known
7+
ansible.builtin.assert:
8+
that:
9+
- mos_login is defined
10+
- mos_password is defined
11+
- oracle_patch_download_dir is defined
12+
13+
- name: Ensure destination directory exists
14+
ansible.builtin.file:
15+
path: "{{ oracle_patch_download_dir }}"
16+
state: directory
17+
mode: 0755
18+
19+
- name: Login to Oracle
20+
ansible.builtin.uri:
21+
url: https://updates.oracle.com/Orion/Services/download
22+
url_username: "{{ mos_login }}"
23+
url_password: "{{ mos_password }}"
24+
force_basic_auth: true
25+
http_agent: "Wget/1.14 (linux-gnu)"
26+
use_proxy: "{{ use_proxy }}"
27+
return_content: true
28+
environment: "{{ proxy_env }}"
29+
register: mos_cookies
30+
31+
- name: Prepare list of OPatch patches needed
32+
vars:
33+
opatch:
34+
patchid: 6880880
35+
filename: "{{ oracle_opatch_patch | selectattr('version', 'equalto', db_version) | map(attribute='filename') | join }}"
36+
description: "Current OPatch for {{ db_version }}"
37+
ansible.builtin.set_fact:
38+
opatchinfo: "{{ opatchinfo + [opatch] }}"
39+
with_items:
40+
- "{{ db_homes_installed }}"
41+
when:
42+
- opatch.filename | length > 0
43+
- "opatch.filename not in (opatchinfo | map(attribute='filename'))" # do not create duplicates
44+
loop_control:
45+
label: "{{ item.home }}: {{ opatch.filename | d('cannot find oracle_opatch_patch entry for ' + db_version, true) }}"
46+
47+
- name: Get ARU and URL
48+
vars:
49+
url: "https://updates.oracle.com/Orion/SimpleSearch/process_form?search_type=patch&plat_lang={{ oracle_plat_lang }}&patch_number={{ item.patchid }}"
50+
aru: "{{ aru_list.content | regex_findall(item.filename + '[^ ]+aru=(\\d+)') | d(['missing'], true) | first }}"
51+
password_required: "{{ aru_list.content is regex('password is required') }}"
52+
summary: >-
53+
{% if password_required %}
54+
Password is needed for download, yet currently not supported. Please open Issue.
55+
{% elif aru == 'missing' %}
56+
Could not determine ARU - is patch number valid? see URL {{ url }}
57+
{% else %}
58+
ARU={{ aru }}
59+
{% endif %}
60+
ansible.builtin.uri:
61+
url: "{{ url }}"
62+
http_agent: "Wget/1.14 (linux-gnu)"
63+
return_content: true
64+
headers:
65+
Cookie: "{{ mos_cookies.cookies_string }}"
66+
use_proxy: "{{ use_proxy }}"
67+
environment: "{{ proxy_env }}"
68+
with_items:
69+
- "{{ opatchinfo }}"
70+
- "{{ oracle_sw_patches }}"
71+
failed_when: "aru == 'missing' or password_required"
72+
loop_control:
73+
label: "{{ item.filename }} {{ summary }}"
74+
register: aru_list
75+
76+
- name: Get Digest checksums
77+
vars:
78+
url: "https://updates.oracle.com//Orion/ViewDigest/get_form?aru={{ aru }}"
79+
aru: "{{ aru_list.results[idx].content | d('') | regex_findall(item.filename + '[^ ]+aru=(\\d+)') | first }}"
80+
sha256: "{{ sha_list.content | regex_findall('([A-F0-9]{64})') | d(['missing'], true) | first }}"
81+
summary: >-
82+
{% if sha256 == 'missing' %}
83+
Could not get SHA256. Check URL output: {{ url }}
84+
{% else %}
85+
SHA256:{{ sha256 | lower }}
86+
{% endif %}
87+
ansible.builtin.uri:
88+
url: "{{ url }}"
89+
http_agent: "Wget/1.14 (linux-gnu)"
90+
return_content: true
91+
headers:
92+
Cookie: "{{ mos_cookies.cookies_string }}"
93+
use_proxy: "{{ use_proxy }}"
94+
environment: "{{ proxy_env }}"
95+
register: sha_list
96+
when: aru != 'missing'
97+
failed_when: sha256 == 'missing'
98+
with_items:
99+
- "{{ aru_list.results | map(attribute='item') }}" # use original loop
100+
loop_control:
101+
index_var: idx
102+
label: "{{ item.filename }} {{ summary }}"
103+
104+
- name: Download Patches
105+
vars:
106+
aru: "{{ aru_list.results[idx].content | regex_findall(item.filename + '[^ ]+aru=(\\d+)') | first }}"
107+
download_url: "{{ aru_list.results[idx].content | regex_findall('(https://[^ ]+/process_form/' + item.filename + '[^ ]+). ') | first }}"
108+
sha256: "{{ sha_list.results[idx].content | regex_findall('([A-F0-9]{64})') | first }}"
109+
summary: >-
110+
{% if download_patches.msg is search('exists') %}
111+
Already downloaded (SHA256 match)
112+
{% else %}
113+
{{ item.description | d('no description available') }} {{ download_patches.msg | default('') }}
114+
{% endif %}
115+
ansible.builtin.get_url:
116+
url: "{{ download_url }}"
117+
dest: "{{ oracle_sw_source_local }}/{{ item.filename }}"
118+
http_agent: "Wget/1.14 (linux-gnu)"
119+
headers:
120+
Cookie: "{{ mos_cookies.cookies_string }}"
121+
Accept: "application/zip"
122+
checksum: "sha256:{{ sha256 }}"
123+
use_proxy: "{{ use_proxy }}"
124+
# owner: "{{ oracle_user }}" # not always ansible contorller knows this user
125+
# group: "{{ oracle_group }}" # not always ansible contorller knows this group
126+
mode: 0644
127+
environment: "{{ proxy_env }}"
128+
register: download_patches
129+
with_items:
130+
- "{{ aru_list.results | map(attribute='item') }}" # use original loop
131+
loop_control:
132+
index_var: idx
133+
label: "{{ item.filename }} - {{ summary }}"

0 commit comments

Comments
 (0)