|
| 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