Skip to content

Commit 75d25d6

Browse files
authored
Merge pull request sap-linuxlab#1114 from marcelmamula/enhance_validations
sap_hana_install: Enhance variable validation and account for missed variable combinations
2 parents 9171f72 + b1e1442 commit 75d25d6

7 files changed

Lines changed: 255 additions & 186 deletions

File tree

roles/sap_hana_install/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ in a temporary directory for use by the hdblcm command in the next step.
265265
name: community.sap_install.sap_hana_install
266266
vars:
267267
sap_hana_install_software_directory: /software/hana
268-
sap_hana_install_common_master_password: 'My SAP HANA Master Password'
268+
sap_hana_install_master_password: 'My SAP HANA Master Password'
269269
sap_hana_install_sid: 'H01'
270270
sap_hana_install_instance_nr: '00'
271271
```
@@ -284,7 +284,7 @@ Installs SAP HANA on `host0` and other hosts listed in `sap_hana_install_addhost
284284
name: community.sap_install.sap_hana_install
285285
vars:
286286
sap_hana_install_software_directory: /software/hana
287-
sap_hana_install_common_master_password: 'My SAP HANA Master Password'
287+
sap_hana_install_master_password: 'My SAP HANA Master Password'
288288
sap_hana_install_root_password: 'My root password'
289289
sap_hana_install_addhosts: 'host0:role=worker,host1:role=worker:group=g02,host2:role=standby:group=g02'
290290
sap_hana_install_sid: 'H01'
@@ -307,7 +307,7 @@ Installs SAP HANA on `host1` and `host2`, while running on host `host0` where ex
307307
sap_hana_install_software_directory: /software/hana
308308
sap_hana_install_new_system: false
309309
sap_hana_install_addhosts: 'host0:role=worker,host1:role=worker:group=g02,host2:role=standby:group=g02'
310-
sap_hana_install_common_master_password: 'My SAP HANA Master Password'
310+
sap_hana_install_master_password: 'My SAP HANA Master Password'
311311
sap_hana_install_root_password: 'My root password'
312312
sap_hana_install_sid: 'H01'
313313
sap_hana_install_instance_nr: '00'

roles/sap_hana_install/tasks/assert-addhosts-loop-block.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99
- name: SAP HANA Add Hosts - Show the path name of the instance profile
1010
ansible.builtin.debug:
11-
msg: "Instance profile: '{{ sap_hana_install_shared_path }}/{{ sap_hana_install_sid }}/profile/\
12-
{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_number }}_{{ line_item }}'"
11+
msg: >-
12+
Instance profile: '{{ sap_hana_install_shared_path }}/{{ sap_hana_install_sid }}/profile/
13+
{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_number }}_{{ line_item }}'
1314
1415
- name: SAP HANA Add Hosts - Assert that there is no instance profile for the additional hosts
1516
ansible.builtin.assert:
1617
that: not __sap_hana_install_register_instance_profile_addhost.stat.exists
17-
fail_msg:
18-
- "FAIL: There is already an instance profile for host '{{ line_item }}', at location:"
19-
- " '{{ sap_hana_install_shared_path }}/{{ sap_hana_install_sid }}/profile/{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_number }}_{'{ line_item }}."
20-
- "Because of this, the addhost operation will not be performed."
18+
fail_msg: >-
19+
FAIL: Addhost operation will not be performed because there is already an instance profile for host {{ line_item }} at
20+
{{ sap_hana_install_shared_path }}/{{ sap_hana_install_sid }}/profile/{{ sap_hana_install_sid }}_HDB{{ sap_hana_install_number }}_{{ line_item }}
2121
success_msg: "PASS: No instance profile was found for host '{{ line_item }}'."
2222

2323
- name: SAP HANA Add Hosts - Check for SAP HANA instance directory in '/usr/sap'
@@ -32,8 +32,7 @@
3232
- name: SAP HANA Add Hosts - Assert that there is no SAP HANA instance directory in '/usr/sap' for the additional hosts
3333
ansible.builtin.assert:
3434
that: not __sap_hana_install_register_usr_sap_instance_directory.stat.exists
35-
fail_msg:
36-
- "FAIL: There is already an instance directory for host '{{ sap_hana_install_addhosts.split(':')[0] }}', at location:"
37-
- " '/usr/sap/{{ sap_hana_install_sid }}/HDB{{ sap_hana_install_number }}/{{ line_item }}' ."
38-
- "Because of this, the addhost operation will not be performed."
35+
fail_msg: >-
36+
FAIL: Addhost operation will not be performed because there is already an instance directory for host {{ line_item }} at location
37+
/usr/sap/{{ sap_hana_install_sid }}/HDB{{ sap_hana_install_number }}/{{ line_item }}
3938
success_msg: "PASS: No instance directory was found for host '{{ line_item }}' in /usr/sap."
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
---
3+
4+
- name: Assert that the variable 'sap_hana_install_sid' is defined as String consisting of 3 characters
5+
ansible.builtin.assert:
6+
that:
7+
- sap_hana_install_sid is defined
8+
- sap_hana_install_sid is string
9+
- sap_hana_install_sid | trim | length == 3
10+
success_msg: |
11+
PASS: The length of SAP HANA System ID '{{ sap_hana_install_sid }}' is 3 characters.
12+
fail_msg: |
13+
{% if sap_hana_install_sid is not string %}
14+
FAIL: The variable 'sap_hana_install_sid' is not String.
15+
{% elif sap_hana_install_sid | length == 0 %}
16+
FAIL: The variable 'sap_hana_install_sid' is empty.
17+
{% else %}
18+
FAIL: The length of SAP HANA System ID '{{ sap_hana_install_sid }}' is not 3 characters!
19+
{% endif %}
20+
21+
- name: Assert that the variable 'sap_hana_install_sid' is not in the list of reserved SAP SIDs
22+
ansible.builtin.assert:
23+
that: sap_hana_install_sid not in __sap_hana_install_sid_prohibited
24+
success_msg: |
25+
PASS: The SAP HANA System ID '{{ sap_hana_install_sid }}' is not in the list of reserved SAP SIDs in SAP note 1979280 v.20.
26+
fail_msg: |
27+
FAIL: The SAP HANA System ID '{{ sap_hana_install_sid }}' is in the list of reserved SAP SIDs in SAP note 1979280 v.20!
28+
29+
- name: Assert that the variable 'sap_hana_install_number' is defined as String consisting of 2 digits
30+
ansible.builtin.assert:
31+
that:
32+
- sap_hana_install_number is defined
33+
- sap_hana_install_number is string
34+
- sap_hana_install_number | trim | length == 2
35+
- sap_hana_install_number is match('^[0-9]{2}$')
36+
success_msg: |
37+
PASS: The SAP HANA Instance Number '{{ sap_hana_install_number }}' is defined as String consisting of 2 digits.
38+
fail_msg: |
39+
{% if sap_hana_install_number is not string %}
40+
FAIL: The variable 'sap_hana_install_number' is not String.
41+
{% elif sap_hana_install_number | length == 0 %}
42+
FAIL: The variable 'sap_hana_install_number' is empty.
43+
{% else %}
44+
FAIL: The SAP HANA Instance Number '{{ sap_hana_install_number }}' is not 2 digits!
45+
{% endif %}
46+
47+
- name: Assert that the variable 'sap_hana_install_master_password' is defined as String and not empty
48+
ansible.builtin.assert:
49+
that:
50+
- sap_hana_install_master_password is defined
51+
- sap_hana_install_master_password is string
52+
- sap_hana_install_master_password | trim | length > 0
53+
success_msg: |
54+
PASS: The variable 'sap_hana_install_master_password' is defined as String and not empty.
55+
fail_msg: |
56+
{% if sap_hana_install_master_password is not defined %}
57+
FAIL: The variable 'sap_hana_install_master_password' is not defined.
58+
{% elif sap_hana_install_master_password is not string %}
59+
FAIL: The variable 'sap_hana_install_master_password' is not String.
60+
{% else %}
61+
FAIL: The variable 'sap_hana_install_master_password' is empty.
62+
{% endif %}
63+
64+
65+
- name: Assert that the variable 'sap_hana_install_addhosts' is defined as String and not empty
66+
ansible.builtin.assert:
67+
that:
68+
- sap_hana_install_addhosts is defined
69+
- sap_hana_install_addhosts is string
70+
- sap_hana_install_addhosts | trim | length > 0
71+
success_msg: |
72+
PASS: The variable 'sap_hana_install_addhosts' is defined as String and not empty.
73+
fail_msg: |
74+
{% if sap_hana_install_addhosts is not defined %}
75+
FAIL: The variable 'sap_hana_install_addhosts' is not defined.
76+
{% elif sap_hana_install_addhosts is not string %}
77+
FAIL: The variable 'sap_hana_install_addhosts' is not String.
78+
{% else %}
79+
FAIL: The variable 'sap_hana_install_addhosts' is empty.
80+
{% endif %}
81+
when:
82+
- not sap_hana_install_new_system

roles/sap_hana_install/tasks/hana_addhosts.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
- name: SAP HANA Add Hosts - Assert that the additional hosts are not shown in hdblcm --list_systems
4444
ansible.builtin.assert:
4545
that: line_item not in __sap_hana_install_register_hdblcm_list_systems.stdout
46-
fail_msg:
47-
- "FAIL: Host '{{ line_item }}' is already part of system '{{ sap_hana_install_sid }}'"
48-
- "Because of this, the addhost operation will not be performed."
46+
fail_msg: >-
47+
FAIL: The host '{{ line_item }}' is already part of system '{{ sap_hana_install_sid }}'
48+
and addhosts operation will not be performed.
4949
success_msg: "PASS: Host '{{ line_item }}' is not yet part of system '{{ sap_hana_install_sid }}'."
5050
loop: "{{ __sap_hana_install_addhosts_hosts }}"
5151
loop_control:
Lines changed: 81 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
# SPDX-License-Identifier: Apache-2.0
22
---
33

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+
510
- name: SAP HANA Checks - Check if saphostctrl is installed
611
ansible.builtin.stat:
712
path: /usr/sap/hostctrl/exe/saphostctrl
813
check_mode: false
914
register: __sap_hana_install_register_stat_saphostctrl
1015
failed_when: false
1116

17+
18+
# Check 1: Use found sapcontrol to get list of SAP instances.
19+
# Only valid combination of SID and Instance Number will pass.
1220
- name: SAP HANA Checks - Check if SAP instances are installed with saphostctrl
1321
when: __sap_hana_install_register_stat_saphostctrl.stat.exists
1422
block:
1523

1624
- 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-
1827
register: __sap_hana_install_register_instancelist
1928
changed_when: false
2029

@@ -23,7 +32,7 @@
2332
var: __sap_hana_install_register_instancelist.stdout_lines
2433
verbosity: 1
2534

26-
- name: SAP HANA Checks - Desired HANA is installed and running
35+
- name: SAP HANA Checks - Desired SAP HANA is installed and running
2736
ansible.builtin.set_fact:
2837
__sap_hana_install_fact_is_installed: true
2938
when:
@@ -34,10 +43,11 @@
3443
loop_var: __sap_hana_install_loop_instance
3544
label: "{{ __sap_hana_install_loop_instance.split('-')[0] | trim }}"
3645

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
3847
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 }}!
4151
when:
4252
- __sap_hana_install_loop_instance.split('-')[0] | trim != sap_hana_install_sid
4353
- __sap_hana_install_loop_instance.split('-')[1] | trim == sap_hana_install_number
@@ -46,10 +56,11 @@
4656
loop_var: __sap_hana_install_loop_instance
4757
label: "{{ __sap_hana_install_loop_instance.split('-')[0] | trim }}"
4858

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
5060
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 }}!"
5364
when:
5465
- __sap_hana_install_loop_instance.split('-')[0] | trim == sap_hana_install_sid
5566
- __sap_hana_install_loop_instance.split('-')[1] | trim != sap_hana_install_number
@@ -59,6 +70,8 @@
5970
label: "{{ __sap_hana_install_loop_instance.split('-')[0] | trim }}"
6071

6172

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.
6275
- name: SAP HANA Checks - Check directories if no saphostctrl is found
6376
when: not __sap_hana_install_register_stat_saphostctrl.stat.exists
6477
block:
@@ -74,12 +87,13 @@
7487
ansible.builtin.find:
7588
paths: "{{ sap_hana_install_shared_path }}/{{ sap_hana_install_sid }}"
7689
patterns: '*'
90+
file_type: 'any' # New install does not have files and default 'file' will ignore directories.
7791
register: __sap_hana_install_register_files_in_hana_shared_sid_assert
7892
when: __sap_hana_install_register_stat_hana_shared_sid_assert.stat.exists
7993

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
8195
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!"
8397
when:
8498
- __sap_hana_install_register_stat_hana_shared_sid_assert.stat.exists
8599
- __sap_hana_install_register_files_in_hana_shared_sid_assert.matched | int != 0
@@ -95,61 +109,81 @@
95109
ansible.builtin.find:
96110
paths: "/usr/sap/{{ sap_hana_install_sid }}"
97111
patterns: '*'
112+
file_type: 'any' # New install does not have files and default 'file' will ignore directories.
98113
register: __sap_hana_install_register_files_in_usr_sap_sid_assert
99114
when: __sap_hana_install_register_stat_usr_sap_sid_assert.stat.exists
100115

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
102117
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!"
104119
when:
105120
- __sap_hana_install_register_stat_usr_sap_sid_assert.stat.exists
106121
- __sap_hana_install_register_files_in_usr_sap_sid_assert.matched | int != 0
107122

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
125123

124+
# Check 3: Check if the group 'sapsys' exists with correct ID.
126125
# The role supports specifying the SAP HANA group id in variable `sap_hana_install_groupid`, which is the id of the sapsys group.
127126
# 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
129128
when:
130129
- 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
133132
- not __sap_hana_install_fact_is_installed | d(false)
134133
block:
135134

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
141143
failed_when: false
142144

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-
148145
- name: SAP HANA Checks - In case there is a group 'sapsys', assert that its group ID is identical to 'sap_hana_install_groupid'
149146
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
151149
success_msg: "PASS: The group ID of 'sapsys' is identical to the value of variable
152150
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

Comments
 (0)