|
1 | 1 | # SPDX-License-Identifier: Apache-2.0 |
2 | 2 | --- |
3 | 3 |
|
4 | | -## Try to use saphostctrl to figure out if HANA or other SID is installed |
| 4 | +# Required to reset status if the role is used multiple times in one playbook. |
| 5 | +- name: SAP HANA Checks - Reset the status variable if defined from previous run |
| 6 | + ansible.builtin.set_fact: |
| 7 | + __sap_hana_install_fact_is_installed: false |
| 8 | + when: __sap_hana_install_fact_is_installed is defined |
| 9 | + |
5 | 10 | - name: SAP HANA Checks - Check if saphostctrl is installed |
6 | 11 | ansible.builtin.stat: |
7 | 12 | path: /usr/sap/hostctrl/exe/saphostctrl |
8 | 13 | check_mode: false |
9 | 14 | register: __sap_hana_install_register_stat_saphostctrl |
10 | 15 | failed_when: false |
11 | 16 |
|
| 17 | + |
| 18 | +# Check 1: Use found sapcontrol to get list of SAP instances. |
| 19 | +# Only valid combination of SID and Instance Number will pass. |
12 | 20 | - name: SAP HANA Checks - Check if SAP instances are installed with saphostctrl |
13 | 21 | when: __sap_hana_install_register_stat_saphostctrl.stat.exists |
14 | 22 | block: |
15 | 23 |
|
16 | 24 | - name: SAP HANA Checks - Get list of installed SAP instances |
17 | | - ansible.builtin.shell: set -o pipefail && /usr/sap/hostctrl/exe/saphostctrl -function ListInstances | cut -d":" -f2- |
| 25 | + ansible.builtin.shell: |
| 26 | + cmd: set -o pipefail && /usr/sap/hostctrl/exe/saphostctrl -function ListInstances | cut -d":" -f2- |
18 | 27 | register: __sap_hana_install_register_instancelist |
19 | 28 | changed_when: false |
20 | 29 |
|
|
23 | 32 | var: __sap_hana_install_register_instancelist.stdout_lines |
24 | 33 | verbosity: 1 |
25 | 34 |
|
26 | | - - name: SAP HANA Checks - Desired HANA is installed and running |
| 35 | + - name: SAP HANA Checks - Desired SAP HANA is installed and running |
27 | 36 | ansible.builtin.set_fact: |
28 | 37 | __sap_hana_install_fact_is_installed: true |
29 | 38 | when: |
|
34 | 43 | loop_var: __sap_hana_install_loop_instance |
35 | 44 | label: "{{ __sap_hana_install_loop_instance.split('-')[0] | trim }}" |
36 | 45 |
|
37 | | - - name: SAP HANA Checks - Fail if existing HANA was detected with same instance number but different SID |
| 46 | + - name: SAP HANA Checks - Fail if existing SAP HANA was detected with same instance number but different SID |
38 | 47 | ansible.builtin.fail: |
39 | | - msg: "The instance number {{ sap_hana_install_number }} is already used by |
40 | | - HANA system {{ __sap_hana_install_loop_instance.split('-')[0] | trim }}!" |
| 48 | + msg: >- |
| 49 | + The instance number {{ sap_hana_install_number }} is already used by |
| 50 | + SAP HANA system {{ __sap_hana_install_loop_instance.split('-')[0] | trim }}! |
41 | 51 | when: |
42 | 52 | - __sap_hana_install_loop_instance.split('-')[0] | trim != sap_hana_install_sid |
43 | 53 | - __sap_hana_install_loop_instance.split('-')[1] | trim == sap_hana_install_number |
|
46 | 56 | loop_var: __sap_hana_install_loop_instance |
47 | 57 | label: "{{ __sap_hana_install_loop_instance.split('-')[0] | trim }}" |
48 | 58 |
|
49 | | - - name: SAP HANA Checks - Fail if existing HANA was detected with same SID but different instance number |
| 59 | + - name: SAP HANA Checks - Fail if existing SAP HANA was detected with same SID but different instance number |
50 | 60 | ansible.builtin.fail: |
51 | | - msg: "HANA system {{ sap_hana_install_sid }} already exists with different instance number |
52 | | - {{ __sap_hana_install_loop_instance.split('-')[1] | trim }}!" |
| 61 | + msg: >- |
| 62 | + The SAP HANA system {{ sap_hana_install_sid }} already exists with different instance number |
| 63 | + {{ __sap_hana_install_loop_instance.split('-')[1] | trim }}!" |
53 | 64 | when: |
54 | 65 | - __sap_hana_install_loop_instance.split('-')[0] | trim == sap_hana_install_sid |
55 | 66 | - __sap_hana_install_loop_instance.split('-')[1] | trim != sap_hana_install_number |
|
59 | 70 | label: "{{ __sap_hana_install_loop_instance.split('-')[0] | trim }}" |
60 | 71 |
|
61 | 72 |
|
| 73 | +# Check 2: Check presence of directories if saphostctrl was not found. |
| 74 | +# These checks do not set '__sap_hana_install_fact_is_installed' as they pass only if directories are empty. |
62 | 75 | - name: SAP HANA Checks - Check directories if no saphostctrl is found |
63 | 76 | when: not __sap_hana_install_register_stat_saphostctrl.stat.exists |
64 | 77 | block: |
|
74 | 87 | ansible.builtin.find: |
75 | 88 | paths: "{{ sap_hana_install_shared_path }}/{{ sap_hana_install_sid }}" |
76 | 89 | patterns: '*' |
| 90 | + file_type: 'any' # New install does not have files and default 'file' will ignore directories. |
77 | 91 | register: __sap_hana_install_register_files_in_hana_shared_sid_assert |
78 | 92 | when: __sap_hana_install_register_stat_hana_shared_sid_assert.stat.exists |
79 | 93 |
|
80 | | - - name: SAP HANA Checks - Fail if directory '{{ sap_hana_install_shared_path }}/{{ sap_hana_install_sid }}' exists and is not empty |
| 94 | + - name: SAP HANA Checks - Fail if the directory '{{ sap_hana_install_shared_path }}/{{ sap_hana_install_sid }}' exists and is not empty |
81 | 95 | ansible.builtin.fail: |
82 | | - msg: "FAIL: Directory '{{ sap_hana_install_shared_path }}/{{ sap_hana_install_sid }}' exists and is not empty!" |
| 96 | + msg: "FAIL: The directory '{{ sap_hana_install_shared_path }}/{{ sap_hana_install_sid }}' exists and is not empty!" |
83 | 97 | when: |
84 | 98 | - __sap_hana_install_register_stat_hana_shared_sid_assert.stat.exists |
85 | 99 | - __sap_hana_install_register_files_in_hana_shared_sid_assert.matched | int != 0 |
|
95 | 109 | ansible.builtin.find: |
96 | 110 | paths: "/usr/sap/{{ sap_hana_install_sid }}" |
97 | 111 | patterns: '*' |
| 112 | + file_type: 'any' # New install does not have files and default 'file' will ignore directories. |
98 | 113 | register: __sap_hana_install_register_files_in_usr_sap_sid_assert |
99 | 114 | when: __sap_hana_install_register_stat_usr_sap_sid_assert.stat.exists |
100 | 115 |
|
101 | | - - name: SAP HANA Checks - Fail if directory '/usr/sap/{{ sap_hana_install_sid }}' exists and is not empty |
| 116 | + - name: SAP HANA Checks - Fail if the directory '/usr/sap/{{ sap_hana_install_sid }}' exists and is not empty |
102 | 117 | ansible.builtin.fail: |
103 | | - msg: "FAIL: Directory '/usr/sap/{{ sap_hana_install_sid }}' exists and is not empty!" |
| 118 | + msg: "FAIL: The directory '/usr/sap/{{ sap_hana_install_sid }}' exists and is not empty!" |
104 | 119 | when: |
105 | 120 | - __sap_hana_install_register_stat_usr_sap_sid_assert.stat.exists |
106 | 121 | - __sap_hana_install_register_files_in_usr_sap_sid_assert.matched | int != 0 |
107 | 122 |
|
108 | | -- name: SAP HANA Checks - HANA admin user check |
109 | | - when: |
110 | | - - sap_hana_install_check_sidadm_user | d(true) |
111 | | - - not __sap_hana_install_fact_is_installed | d(false) |
112 | | - block: |
113 | | - |
114 | | - - name: SAP HANA Checks - Get info about '{{ sap_hana_install_sid | lower }}adm' user |
115 | | - ansible.builtin.command: getent passwd {{ sap_hana_install_sid | lower }}adm |
116 | | - check_mode: false |
117 | | - register: __sap_hana_install_register_getent_passwd_sidadm |
118 | | - changed_when: false |
119 | | - failed_when: false |
120 | | - |
121 | | - - name: SAP HANA Checks - Fail if the user '{{ sap_hana_install_sid | lower }}adm' exists |
122 | | - ansible.builtin.fail: |
123 | | - msg: "FAIL: User '{{ sap_hana_install_sid | lower }}adm' exists!" |
124 | | - when: __sap_hana_install_register_getent_passwd_sidadm.rc == 0 |
125 | 123 |
|
| 124 | +# Check 3: Check if the group 'sapsys' exists with correct ID. |
126 | 125 | # The role supports specifying the SAP HANA group id in variable `sap_hana_install_groupid`, which is the id of the sapsys group. |
127 | 126 | # The SAP HANA installation will fail if there is already a group named sapsys but with a different ID. Let's better fail before. |
128 | | -- name: SAP HANA Checks - Check HANA admin group |
| 127 | +- name: SAP HANA Checks - Check SAP HANA admin group |
129 | 128 | when: |
130 | 129 | - sap_hana_install_groupid is defined |
131 | | - - sap_hana_install_groupid | string != "None" |
132 | | - - sap_hana_install_groupid | string | length > 0 |
| 130 | + - sap_hana_install_groupid is string |
| 131 | + - sap_hana_install_groupid | trim | length > 0 |
133 | 132 | - not __sap_hana_install_fact_is_installed | d(false) |
134 | 133 | block: |
135 | 134 |
|
136 | | - - name: SAP HANA Checks - Get info about the ID of the 'sapsys' group |
137 | | - ansible.builtin.command: getent group sapsys |
138 | | - check_mode: false |
139 | | - register: __sap_hana_install_register_getent_group_sapsys |
140 | | - changed_when: false |
| 135 | + # getent_groups will be populated, with fields: |
| 136 | + # [0] - 'X' if the password is set. |
| 137 | + # [1] - Group ID. |
| 138 | + # [2] - Group members. |
| 139 | + - name: SAP HANA Checks - Get details of the 'sapsys' group |
| 140 | + ansible.builtin.getent: |
| 141 | + database: group |
| 142 | + key: sapsys |
141 | 143 | failed_when: false |
142 | 144 |
|
143 | | - - name: SAP HANA Checks - Define new variable for the assertion |
144 | | - ansible.builtin.set_fact: |
145 | | - __sap_hana_install_existing_sapsys_gid: "{{ __sap_hana_install_register_getent_group_sapsys.stdout.split(':')[2] }}" |
146 | | - when: __sap_hana_install_register_getent_group_sapsys.rc == 0 |
147 | | - |
148 | 145 | - name: SAP HANA Checks - In case there is a group 'sapsys', assert that its group ID is identical to 'sap_hana_install_groupid' |
149 | 146 | ansible.builtin.assert: |
150 | | - that: (__sap_hana_install_existing_sapsys_gid | int) == (sap_hana_install_groupid | int) |
| 147 | + that: |
| 148 | + - getent_group['sapsys'][1] | int == sap_hana_install_groupid | int |
151 | 149 | success_msg: "PASS: The group ID of 'sapsys' is identical to the value of variable |
152 | 150 | sap_hana_install_groupid, which is '{{ sap_hana_install_groupid }}'" |
153 | | - fail_msg: "FAIL: Group 'sapsys' exists but with a different group ID than '{{ sap_hana_install_groupid }}' |
154 | | - (specified in variable sap_hana_install_groupid)!" |
155 | | - when: __sap_hana_install_register_getent_group_sapsys.rc == 0 |
| 151 | + fail_msg: >- |
| 152 | + FAIL: Group 'sapsys' exists but with a different group ID than '{{ sap_hana_install_groupid }}' |
| 153 | + defined in the variable 'sap_hana_install_groupid'! |
| 154 | + when: |
| 155 | + - getent_group is defined |
| 156 | + - "'sapsys' in getent_group" |
| 157 | + |
| 158 | + |
| 159 | +# Check 4: Check if the user 'sidadm' exists. |
| 160 | +- name: SAP HANA Checks - SAP HANA admin user check |
| 161 | + when: |
| 162 | + - sap_hana_install_check_sidadm_user | d(true) |
| 163 | + - not __sap_hana_install_fact_is_installed | d(false) |
| 164 | + vars: |
| 165 | + __sap_hana_install_sidadm: "{{ sap_hana_install_sid | lower }}adm" |
| 166 | + block: |
| 167 | + |
| 168 | + - name: SAP HANA Checks - Get info about user '{{ __sap_hana_install_sidadm }}' |
| 169 | + ansible.builtin.getent: |
| 170 | + database: passwd |
| 171 | + key: "{{ __sap_hana_install_sidadm }}" |
| 172 | + failed_when: false |
| 173 | + |
| 174 | + - name: SAP HANA Checks - Fail if the user '{{ __sap_hana_install_sidadm }}' exists |
| 175 | + ansible.builtin.fail: |
| 176 | + msg: "FAIL: The user '{{ __sap_hana_install_sidadm }}' already exists!" |
| 177 | + when: |
| 178 | + - getent_passwd is defined |
| 179 | + - __sap_hana_install_sidadm in getent_passwd |
| 180 | + |
| 181 | + |
| 182 | +- name: SAP HANA Checks - Fail if SAP HANA is not found when addhosts is used |
| 183 | + ansible.builtin.fail: |
| 184 | + msg: | |
| 185 | + FAIL: The existing SAP HANA System was not detected when adding new hosts! |
| 186 | + This is required when the variable 'sap_hana_install_new_system' is set to false. |
| 187 | + when: |
| 188 | + - not sap_hana_install_new_system |
| 189 | + - not __sap_hana_install_fact_is_installed | d(false) |
0 commit comments