-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathhana_exists.yml
150 lines (129 loc) · 7.21 KB
/
hana_exists.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
---
## Try to use saphostctrl to figure out if HANA or other SID is installed
- name: SAP HANA Checks - Check if saphostctrl is installed
ansible.builtin.stat:
path: /usr/sap/hostctrl/exe/saphostctrl
check_mode: no
register: __sap_hana_install_register_stat_saphostctrl
failed_when: no
- name: SAP HANA Checks - Check if SAP instances are installed with saphostctrl
when: __sap_hana_install_register_stat_saphostctrl.stat.exists
block:
- name: SAP HANA Checks - Get list of installed SAP instances
ansible.builtin.shell: /usr/sap/hostctrl/exe/saphostctrl -function ListInstances | cut -d":" -f2-
register: __sap_hana_install_register_instancelist
changed_when: false
- name: SAP HANA Checks - Display instances
ansible.builtin.debug:
var: __sap_hana_install_register_instancelist.stdout_lines
verbosity: 1
- name: SAP HANA Checks - Desired HANA is installed and running
ansible.builtin.set_fact:
__sap_hana_install_fact_is_installed: true
when:
- __sap_hana_install_loop_instance.split('-')[0] | trim == sap_hana_install_sid
- __sap_hana_install_loop_instance.split('-')[1] | trim == sap_hana_install_number
loop: "{{ __sap_hana_install_register_instancelist.stdout_lines }}"
loop_control:
loop_var: __sap_hana_install_loop_instance
label: "{{ __sap_hana_install_loop_instance.split('-')[0] | trim }}"
- name: SAP HANA Checks - Trying to install HANA with other SID and existing instance number
ansible.builtin.fail:
msg: "The instance number {{ sap_hana_install_number }} is already used by
HANA system {{ __sap_hana_install_loop_instance.split('-')[0] | trim }}!"
when:
- __sap_hana_install_loop_instance.split('-')[0] | trim != sap_hana_install_sid
- __sap_hana_install_loop_instance.split('-')[1] | trim == sap_hana_install_number
loop: "{{ __sap_hana_install_register_instancelist.stdout_lines }}"
loop_control:
loop_var: __sap_hana_install_loop_instance
label: "{{ __sap_hana_install_loop_instance.split('-')[0] | trim }}"
- name: SAP HANA Checks - Trying to install HANA with existing SID and other instance number
ansible.builtin.fail:
msg: "HANA system {{ sap_hana_install_sid }} already exists with different instance number
{{ __sap_hana_install_loop_instance.split('-')[1] | trim }}!"
when:
- __sap_hana_install_loop_instance.split('-')[0] | trim == sap_hana_install_sid
- __sap_hana_install_loop_instance.split('-')[1] | trim != sap_hana_install_number
loop: "{{ __sap_hana_install_register_instancelist.stdout_lines }}"
loop_control:
loop_var: __sap_hana_install_loop_instance
label: "{{ __sap_hana_install_loop_instance.split('-')[0] | trim }}"
## If saphostcontrol is not installed
- name: SAP HANA Checks - Check directories if no saphostctrl is found
when: not __sap_hana_install_register_stat_saphostctrl.stat.exists
block:
- name: SAP HANA Checks - Get status of '/hana/shared/{{ sap_hana_install_sid }}'
ansible.builtin.stat:
path: "/hana/shared/{{ sap_hana_install_sid }}"
check_mode: no
register: __sap_hana_install_register_stat_hana_shared_sid_assert
failed_when: no
- name: SAP HANA Checks - Get contents of '/hana/shared/{{ sap_hana_install_sid }}'
ansible.builtin.find:
paths: "/hana/shared/{{ sap_hana_install_sid }}"
patterns: '*'
register: __sap_hana_install_register_files_in_hana_shared_sid_assert
when: __sap_hana_install_register_stat_hana_shared_sid_assert.stat.exists
- name: SAP HANA Checks - Fail if directory '/hana/shared/{{ sap_hana_install_sid }}' exists and is not empty
ansible.builtin.fail:
msg: "FAIL: Directory '/hana/shared/{{ sap_hana_install_sid }}' exists and is not empty!"
when:
- __sap_hana_install_register_stat_hana_shared_sid_assert.stat.exists
- __sap_hana_install_register_files_in_hana_shared_sid_assert.matched | int != 0
- name: SAP HANA Checks - Get status of '/usr/sap/{{ sap_hana_install_sid }}'
ansible.builtin.stat:
path: "/usr/sap/{{ sap_hana_install_sid }}"
check_mode: no
register: __sap_hana_install_register_stat_usr_sap_sid_assert
failed_when: no
- name: SAP HANA Checks - Get contents of '/usr/sap/{{ sap_hana_install_sid }}'
ansible.builtin.find:
paths: "/usr/sap/{{ sap_hana_install_sid }}"
patterns: '*'
register: __sap_hana_install_register_files_in_usr_sap_sid_assert
when: __sap_hana_install_register_stat_usr_sap_sid_assert.stat.exists
- name: SAP HANA Checks - Fail if directory '/usr/sap/{{ sap_hana_install_sid }}' exists and is not empty
ansible.builtin.fail:
msg: "FAIL: Directory '/usr/sap/{{ sap_hana_install_sid }}' exists and is not empty!"
when:
- __sap_hana_install_register_stat_usr_sap_sid_assert.stat.exists
- __sap_hana_install_register_files_in_usr_sap_sid_assert.matched | int != 0
- name: SAP HANA Checks - HANA admin user check
when:
- sap_hana_install_check_sidadm_user | d(true)
- not __sap_hana_install_fact_is_installed | d(false)
block:
- name: SAP HANA Checks - Get info about '{{ sap_hana_install_sid | lower }}adm' user
ansible.builtin.command: getent passwd {{ sap_hana_install_sid | lower }}adm
check_mode: no
register: __sap_hana_install_register_getent_passwd_sidadm
changed_when: no
failed_when: no
- name: SAP HANA Checks - Fail if the user '{{ sap_hana_install_sid | lower }}adm' exists
ansible.builtin.fail:
msg: "FAIL: User '{{ sap_hana_install_sid | lower }}adm' exists!"
when: __sap_hana_install_register_getent_passwd_sidadm.rc == 0
# The role supports specifying the SAP HANA group id in variable `sap_hana_install_groupid`, which is the id of the sapsys group.
# The SAP HANA installation will fail if there is already a group named sapsys but with a different ID. Let's better fail before.
- name: SAP HANA Checks - Check HANA admin group
when:
- sap_hana_install_groupid is defined
- sap_hana_install_groupid | string != "None"
- sap_hana_install_groupid | string | length > 0
- not __sap_hana_install_fact_is_installed | d(false)
block:
- name: SAP HANA Checks - Get info about the ID of the 'sapsys' group
ansible.builtin.command: getent group sapsys
check_mode: no
register: __sap_hana_install_register_getent_group_sapsys
changed_when: no
failed_when: no
- name: SAP HANA Checks - In case there is a group 'sapsys', assert that its group ID is identical to 'sap_hana_install_groupid'
ansible.builtin.assert:
that: "{{ __sap_hana_install_register_getent_group_sapsys.stdout.split(':')[2] }} == {{ sap_hana_install_groupid }}"
success_msg: "PASS: The group ID of 'sapsys' is identical to the value of variable
sap_hana_install_groupid, which is '{{ sap_hana_install_groupid }}'"
fail_msg: "FAIL: Group 'sapsys' exists but with a different group ID than '{{ sap_hana_install_groupid }}'
(specified in variable sap_hana_install_groupid)!"
when: __sap_hana_install_register_getent_group_sapsys.rc == 0