|
16 | 16 | msg: "FAIL: The SAPCAR EXE file '{{ __sap_hana_install_fact_software_directory }}/{{ sap_hana_install_sapcar_filename }}' does not exist!"
|
17 | 17 | when: not __sap_hana_install_register_sapcar_stat.stat.exists
|
18 | 18 |
|
19 |
| -# We cannot always use the SAPCAR executable in __sap_hana_install_fact_software_directory because there are |
20 |
| -# some configurations in which executing files in this directory is not possible. So we always copy SAPCAR |
21 |
| -# to directory 'sapcar' in sap_hana_install_software_extract_directory. We do not copy the SAPCAR checksum file. |
| 19 | + # We cannot always use the SAPCAR executable in __sap_hana_install_fact_software_directory because there are |
| 20 | + # some configurations in which executing files in this directory is not possible. So we always copy SAPCAR |
| 21 | + # to directory 'sapcar' in sap_hana_install_software_extract_directory. We do not copy the SAPCAR checksum file. |
22 | 22 | - name: SAP HANA hdblcm prepare - SAPCAR defined - Copy the SAPCAR executable to '{{ sap_hana_install_software_extract_directory }}/sapcar'
|
23 | 23 | ansible.builtin.copy:
|
24 | 24 | src: "{{ __sap_hana_install_fact_software_directory }}/{{ sap_hana_install_sapcar_filename }}"
|
|
63 | 63 | ansible.builtin.set_fact:
|
64 | 64 | __sap_hana_install_fact_selected_sapcar_filename: "{{ sap_hana_install_sapcar_filename }}"
|
65 | 65 |
|
66 |
| -- name: SAP HANA hdblcm prepare - SAPCAR autodetection - Prepare the SAPCAR executable if 'sap_hana_install_sapcar_filename' is not defined |
| 66 | +- name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Prepare the SAPCAR executable if 'sap_hana_install_sapcar_filename' is not defined |
67 | 67 | when: sap_hana_install_sapcar_filename is not defined
|
68 | 68 | block:
|
69 | 69 |
|
70 |
| -# We need the 'file' package for the 'file' command, which we need in the next task. |
71 |
| -# RHEL: The 'file' package is contained in the Base software group, which should be installed already. |
72 |
| - |
73 |
| -# In the first step, we execute the file command for each of the SAPCAR EXE files. It displays the |
74 |
| -# hardware architecture in the second output field, using a string which is different from the output |
75 |
| -# of the 'uname -m' command. So we replace those strings by the "correct" ones. For ppc64 and ppc64le, |
76 |
| -# the second output field is identical. So in this case, we also look at the third and forth output field, |
77 |
| -# to handle cases where a ppc64 SAPCAR executable is present in the software directory. |
78 |
| -# After selecting the SAPCAR EXE files for the current architecture, we copy them to a temporary |
79 |
| -# directory sapcar_tmp in the software extract directory and then perform a checksum verification |
80 |
| -# for these files if the corresponding variable is set. |
81 |
| - - name: SAP HANA hdblcm prepare - SAPCAR autodetection - Create directory '{{ sap_hana_install_software_extract_directory }}/sapcar_tmp' |
| 70 | + # Package 'file' is present in Base system, but this task ensures next task does not fail on hardened images. |
| 71 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Ensure file package is present |
| 72 | + ansible.builtin.package: |
| 73 | + name: file |
| 74 | + state: present |
| 75 | + |
| 76 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Create directory '{{ sap_hana_install_software_extract_directory }}/sapcar_tmp' |
82 | 77 | ansible.builtin.file:
|
83 | 78 | path: "{{ sap_hana_install_software_extract_directory }}/sapcar_tmp"
|
84 | 79 | state: directory
|
85 | 80 | mode: '0755'
|
86 | 81 |
|
87 |
| -# Reason for noqa: There are pipe symbols - as part of an or statement - in an awk command sequence. |
88 |
| - - name: SAP HANA hdblcm prepare - SAPCAR autodetection - Identify matching SAR executables in '{{ __sap_hana_install_fact_software_directory }}' # noqa jinja[spacing] |
89 |
| - ansible.builtin.shell: | |
90 |
| - set -o pipefail && |
91 |
| - for sapcar_any in SAPCAR*EXE; do |
92 |
| - file ${sapcar_any} | awk '{ |
93 |
| - split ($0, a, ":"); split (a[2], b, ","); sub ("^ ", "", b[2]); |
94 |
| - sub ("x86-64", "x86_64", b[2]); |
95 |
| - if (index (b[2], "64-bit PowerPC") > 0) { |
96 |
| - if ((index (b[3], "GNU/Linux") > 0)||(index (b[4], "GNU/Linux") > 0)) {sub ("64-bit PowerPC", "ppc64le", b[2])}; |
97 |
| - if ((index (b[3], "SYSV") > 0)||(index (b[4], "SYSV") > 0)) {sub ("64-bit PowerPC", "ppc64", b[2])}; |
98 |
| - } |
99 |
| - sub ("IBM S/390", "s390x", b[2]); |
100 |
| - printf ("%s %s %s\n", a[1], b[2], b[3])}' |
101 |
| - done | awk '$2=="{{ ansible_architecture }}"{printf ("%s\n", $1)}' |
| 82 | + # In the first step, we execute the file command for each of the SAPCAR EXE files. It displays the |
| 83 | + # hardware architecture in the second output field, using a string which is different from the output |
| 84 | + # of the 'uname -m' command. |
| 85 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Find matching SAPCAR executables in '{{ __sap_hana_install_fact_software_directory }}' |
| 86 | + ansible.builtin.shell: |
| 87 | + cmd: set -o pipefail && find . -name 'SAPCAR*EXE' -exec file {} + | sed 's|^\./||' |
102 | 88 | args:
|
103 | 89 | chdir: "{{ __sap_hana_install_fact_software_directory }}"
|
104 |
| - register: __sap_hana_install_register_sapcar_matching_arch |
105 |
| - changed_when: no |
| 90 | + register: __sap_hana_install_register_sapcar_file_contents |
| 91 | + changed_when: false |
106 | 92 |
|
107 |
| - - name: SAP HANA hdblcm prepare - SAPCAR autodetection - Fail if no matching SAPCAR executable could be found |
| 93 | + # Loop through found files and compare them against search keywords for ansible_architecture. |
| 94 | + # Supported combinations are defined in the variable '__sap_hana_install_architecture_matrix' in vars/main.yml file. |
| 95 | + # Each platform can contain multiple search words. AND operator is achieved by counting all found keywords. |
| 96 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Compare found files against the variable ansible_architecture |
| 97 | + ansible.builtin.set_fact: |
| 98 | + __sap_hana_install_fact_sapcar_matching_arch: | |
| 99 | + {%- set matching_files = [] -%} |
| 100 | + {%- set rule_sets = __sap_hana_install_architecture_matrix.get(ansible_architecture, []) -%} |
| 101 | + {%- if rule_sets -%} |
| 102 | + {%- for line in __sap_hana_install_register_sapcar_file_contents.stdout_lines -%} |
| 103 | + {%- set parts = line.split(': ', 1) -%} |
| 104 | + {%- if parts | length > 1 -%} |
| 105 | + {%- set filename = parts[0] -%} |
| 106 | + {%- set file_info = parts[1] -%} |
| 107 | +
|
| 108 | + {# Create a list of boolean results for each rule set #} |
| 109 | + {%- set rule_results = [] -%} |
| 110 | + {%- for keyword_list in rule_sets -%} |
| 111 | + {%- set all_keywords_found = (keyword_list | select('in', file_info) | list | length) == (keyword_list | length) -%} |
| 112 | + {%- set _ = rule_results.append(all_keywords_found) -%} |
| 113 | + {%- endfor -%} |
| 114 | +
|
| 115 | + {%- if true in rule_results -%} |
| 116 | + {%- set _ = matching_files.append(filename) -%} |
| 117 | + {%- endif -%} |
| 118 | + {%- endif -%} |
| 119 | + {%- endfor -%} |
| 120 | + {%- endif -%} |
| 121 | + {{- matching_files -}} |
| 122 | +
|
| 123 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Fail if no matching SAPCAR executable could be found |
108 | 124 | ansible.builtin.fail:
|
109 | 125 | msg: "FAIL: No SAPCAR EXE file for architecture '{{ ansible_architecture }}' was found in
|
110 | 126 | {{ __sap_hana_install_fact_software_directory }}!"
|
111 |
| - when: __sap_hana_install_register_sapcar_matching_arch.stdout | length == 0 |
112 |
| - |
113 |
| - - name: SAP HANA hdblcm prepare - SAPCAR autodetection - Create a list of files from SAPCAR executables of the matching architecture |
114 |
| - ansible.builtin.set_fact: |
115 |
| - __sap_hana_install_fact_sapcar_filenames_matching_arch: "{{ __sap_hana_install_fact_sapcar_filenames_matching_arch | d([]) + [item] }}" |
116 |
| - loop: "{{ __sap_hana_install_register_sapcar_matching_arch.stdout_lines }}" |
| 127 | + when: __sap_hana_install_fact_sapcar_matching_arch | length == 0 |
117 | 128 |
|
118 |
| - - name: SAP HANA hdblcm prepare - SAPCAR autodetection - Copy matching SAPCAR executables to '{{ sap_hana_install_software_extract_directory }}/sapcar_tmp/' |
| 129 | + # After selecting the SAPCAR EXE files for the current architecture, we copy them to a temporary |
| 130 | + # directory sapcar_tmp in the software extract directory and then perform a checksum verification |
| 131 | + # for these files if the corresponding variable is set. |
| 132 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Copy matching SAPCAR executables to '{{ sap_hana_install_software_extract_directory }}/sapcar_tmp/' |
119 | 133 | ansible.builtin.copy:
|
120 | 134 | src: "{{ __sap_hana_install_fact_software_directory }}/{{ item }}"
|
121 | 135 | dest: "{{ sap_hana_install_software_extract_directory }}/sapcar_tmp/{{ item }}"
|
122 | 136 | remote_src: true
|
123 | 137 | owner: 'root'
|
124 | 138 | group: 'root'
|
125 | 139 | mode: '0755'
|
126 |
| - with_items: "{{ __sap_hana_install_fact_sapcar_filenames_matching_arch }}" |
| 140 | + loop: "{{ __sap_hana_install_fact_sapcar_matching_arch }}" |
127 | 141 |
|
128 |
| - - name: SAP HANA hdblcm prepare - SAPCAR autodetection - Fill list of dicts containing dir, file, and global checksum file |
| 142 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Fill list of dicts containing dir, file, and global checksum file |
129 | 143 | ansible.builtin.set_fact:
|
130 | 144 | __sap_hana_install_fact_sapcar_dict: "{{ __sap_hana_install_fact_sapcar_dict | d([]) + [__sap_hana_install_tmp_sapcar_dict] }}"
|
131 |
| - with_items: "{{ __sap_hana_install_fact_sapcar_filenames_matching_arch }}" |
| 145 | + loop: "{{ __sap_hana_install_fact_sapcar_matching_arch }}" |
132 | 146 | vars:
|
133 | 147 | __sap_hana_install_tmp_sapcar_dict:
|
134 | 148 | dir: "{{ sap_hana_install_software_extract_directory }}/sapcar_tmp"
|
135 | 149 | file: "{{ item }}"
|
136 | 150 | checksum_file: "{{ sap_hana_install_global_checksum_file }}"
|
137 | 151 | when: sap_hana_install_global_checksum_file is defined
|
138 | 152 |
|
139 |
| - - name: SAP HANA hdblcm prepare - SAPCAR autodetection - Fill list of dicts containing dir, file, and specific checksum file |
| 153 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Fill list of dicts containing dir, file, and specific checksum file |
140 | 154 | ansible.builtin.set_fact:
|
141 | 155 | __sap_hana_install_fact_sapcar_dict: "{{ __sap_hana_install_fact_sapcar_dict | d([]) + [__sap_hana_install_tmp_sapcar_dict] }}"
|
142 |
| - with_items: "{{ __sap_hana_install_fact_sapcar_filenames_matching_arch }}" |
| 156 | + loop: "{{ __sap_hana_install_fact_sapcar_matching_arch }}" |
143 | 157 | vars:
|
144 | 158 | __sap_hana_install_tmp_sapcar_dict:
|
145 | 159 | dir: "{{ sap_hana_install_software_extract_directory }}/sapcar_tmp"
|
146 | 160 | file: "{{ item }}"
|
147 | 161 | checksum_file: "{{ __sap_hana_install_fact_software_directory }}/{{ item }}.sha256"
|
148 | 162 | when: sap_hana_install_global_checksum_file is not defined
|
149 | 163 |
|
150 |
| - - name: SAP HANA hdblcm prepare - SAPCAR autodetection - Display __sap_hana_install_fact_sapcar_dict |
151 |
| - ansible.builtin.debug: |
152 |
| - var: __sap_hana_install_fact_sapcar_dict |
153 |
| - |
154 |
| - - name: SAP HANA hdblcm prepare - SAPCAR autodetection - Verify checksum for SAPCAR executables |
| 164 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Verify checksum for SAPCAR executables |
155 | 165 | ansible.builtin.include_tasks: verify_checksum.yml
|
156 | 166 | loop: "{{ __sap_hana_install_fact_sapcar_dict }}"
|
157 | 167 | loop_control:
|
|
160 | 170 | - __sap_hana_install_fact_sapcar_dict | length > 0
|
161 | 171 | - sap_hana_install_verify_checksums
|
162 | 172 |
|
163 |
| -# For each file in temporary directory sapcar_tmp in the software extract directory, we run it with option |
164 |
| -# --version and then identify the most recent one, which is then copied to directory sapcar. |
165 |
| - - name: SAP HANA hdblcm prepare - SAPCAR autodetection - Identify the SAPCAR executable with the latest version |
166 |
| - ansible.builtin.shell: | |
167 |
| - set -o pipefail && |
168 |
| - for sapcar_matching_arch in "{{ __sap_hana_install_fact_sapcar_filenames_matching_arch | map('quote') | join(' ') }}"; do |
169 |
| - ( printf "%s " $(basename ${sapcar_matching_arch}) |
170 |
| - {{ sap_hana_install_software_extract_directory }}/sapcar_tmp/$(basename ${sapcar_matching_arch}) --version | |
171 |
| - awk '/kernel release/{rel=$NF}/patch number/{printf ("%s %s\n", rel, $NF)}' |
172 |
| - ) |
173 |
| - done | sort -k 2 -nr -k 3 -nr | awk 'NR==1{printf ("%s - SAP kernel: %s; Patch number: %s\n", $1, $2, $3)}' |
| 173 | + |
| 174 | + # For each file in temporary directory sapcar_tmp in the software extract directory, we run it with option |
| 175 | + # --version and then identify the most recent one, which is then copied to directory sapcar. |
| 176 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Get version of all SAPCAR executable files |
| 177 | + ansible.builtin.command: |
| 178 | + cmd: "./{{ item }} --version" |
174 | 179 | args:
|
175 | 180 | chdir: "{{ sap_hana_install_software_extract_directory }}/sapcar_tmp"
|
176 |
| - register: __sap_hana_install_register_latest_sapcar_file |
177 |
| - changed_when: no |
| 181 | + loop: "{{ __sap_hana_install_fact_sapcar_matching_arch }}" |
| 182 | + register: __sap_hana_install_register_sapcar_versions |
| 183 | + ignore_errors: true |
| 184 | + changed_when: false |
| 185 | + |
| 186 | + # Loop through found files and extract kernel and patch values before sorting them in descending order. |
| 187 | + # Resulting variable is used together with '| trim' to ensure that empty spaces are removed from shell command output. |
| 188 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Identify the SAPCAR executable with the latest version |
| 189 | + ansible.builtin.set_fact: |
| 190 | + __sap_hana_install_fact_latest_sapcar_file: | |
| 191 | + {%- set files_with_versions = [] -%} |
| 192 | + {%- for result in __sap_hana_install_register_sapcar_versions.results -%} |
| 193 | + {%- if not result.failed -%} |
| 194 | + {# Use regex to find the kernel and patch numbers, defaulting to 0 if not found #} |
| 195 | + {%- set kernel = result.stdout | regex_search('kernel release\s+(\d+)', '\\1') | first | default(0) | int -%} |
| 196 | + {%- set patch = result.stdout | regex_search('patch number\s+(\d+)', '\\1') | first | default(0) | int -%} |
| 197 | +
|
| 198 | + {# Append the structured data to our list #} |
| 199 | + {%- set _ = files_with_versions.append({'kernel': kernel, 'patch': patch, 'filename': result.item}) -%} |
| 200 | + {%- endif -%} |
| 201 | + {%- endfor -%} |
| 202 | +
|
| 203 | + {# Sort by patch (secondary) then by kernel (primary) in descending order and return first one #} |
| 204 | + {%- set sorted_files = files_with_versions | sort(attribute='patch', reverse=true) | sort(attribute='kernel', reverse=true) -%} |
| 205 | + {{- sorted_files[0].filename if sorted_files else 'none' -}} |
| 206 | +
|
| 207 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Set fact for SAPCAR executable from auto-detection |
| 208 | + ansible.builtin.set_fact: |
| 209 | + __sap_hana_install_fact_selected_sapcar_filename: "{{ __sap_hana_install_fact_latest_sapcar_file | trim }}" |
178 | 210 |
|
179 |
| - - name: SAP HANA hdblcm prepare - SAPCAR autodetection - Display SAPCAR executable file name, SAP kernel release, and patch number |
| 211 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Display SAPCAR executable file name |
180 | 212 | ansible.builtin.debug:
|
181 |
| - msg: "Using SAPCAR executable: {{ __sap_hana_install_register_latest_sapcar_file.stdout }}" |
182 |
| - |
183 |
| - - name: SAP HANA hdblcm prepare - SAPCAR autodetection - Set fact for SAPCAR executable from autodetection |
184 |
| - ansible.builtin.set_fact: |
185 |
| - __sap_hana_install_fact_selected_sapcar_filename: "{{ __sap_hana_install_register_latest_sapcar_file.stdout.split(' ').0 }}" |
| 213 | + msg: "Using SAPCAR executable: {{ __sap_hana_install_fact_selected_sapcar_filename }}" |
186 | 214 |
|
187 |
| - - name: SAP HANA hdblcm prepare - SAPCAR autodetection - Copy the autodetected SAPCAR executable to '{{ sap_hana_install_software_extract_directory }}/sapcar' |
| 215 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Copy the autodetected SAPCAR executable to '{{ sap_hana_install_software_extract_directory }}/sapcar' |
188 | 216 | ansible.builtin.copy:
|
189 | 217 | src: "{{ sap_hana_install_software_extract_directory }}/sapcar_tmp/{{ __sap_hana_install_fact_selected_sapcar_filename }}"
|
190 | 218 | dest: "{{ sap_hana_install_software_extract_directory }}/sapcar/{{ __sap_hana_install_fact_selected_sapcar_filename }}"
|
|
194 | 222 | mode: '0755'
|
195 | 223 | when: not ansible_check_mode
|
196 | 224 |
|
197 |
| - - name: SAP HANA hdblcm prepare - SAPCAR autodetection - Remove directory '{{ sap_hana_install_software_extract_directory }}/sapcar_tmp' |
| 225 | + - name: SAP HANA hdblcm prepare - SAPCAR auto-detection - Remove directory '{{ sap_hana_install_software_extract_directory }}/sapcar_tmp' |
198 | 226 | ansible.builtin.file:
|
199 | 227 | path: "{{ sap_hana_install_software_extract_directory }}/sapcar_tmp"
|
200 | 228 | state: absent
|
|
0 commit comments