Skip to content

Commit d148ca1

Browse files
committed
Refactor firewall management
Introduces a new variable `firewall_cfg` in the `sap-hana-preconfigure` playbook to provide more explicit control over the firewalld service. This new variable allows to 'enable', 'disable', or 'ignore' the firewall configuration. The `sap_hana_install` role is updated to delegate the firewall service management to the preconfigure playbook, avoiding conflicts and centralizing the configuration. The documentation has been updated to reflect these changes. Softfail for bsc#1254356 in 16.0
1 parent 602ea78 commit d148ca1

5 files changed

Lines changed: 71 additions & 36 deletions

File tree

ansible/playbooks/roles/sap_hana_install/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ or if it will add further hosts to an existing SAP HANA system as specified by v
140140
`sap_hana_install_addhosts`. Default is `yes` for a fresh SAP HANA installation.
141141
142142
The role can be configured to also set the required firewall ports for SAP HANA. If this is desired, set
143-
the variable `sap_hana_install_update_firewall` to `yes` (default is `no`). The firewall ports are defined
143+
the variable `sap_hana_install_update_firewall` to `true` (default is `false` that means the role will not touch
144+
any firewall related system settings, leaving whatever the system has unchanged). The firewall ports are defined
144145
in a variable which is compatible with the variable structure used by Linux System Role `firewall`.
145146
The firewall ports for SAP HANA are defined in member `port` of the first field of variable
146147
`sap_hana_install_firewall` (`sap_hana_install_firewall[0].port`), see file `defaults/main.yml`. If the
@@ -257,7 +258,7 @@ You can find more complex playbooks in directory `playbooks` of the collection `
257258
- Extract all SAR files into `sap_hana_install_software_extract_directory`.
258259

259260
Note: For each SAPCAR or SAR file called or used by the role, if variable `sap_hana_install_verify_checksums`
260-
is set to `yes`, the role will perform a checksum verification against a specific or global checksum file.
261+
is set to `true`, the role will perform a checksum verification against a specific or global checksum file.
261262

262263
- Check existence of `hdblcm` in `SAP_HANA_DATABASE` directory from the extracted SAR files.
263264

@@ -327,7 +328,7 @@ With the following tags, the role can be called to perform certain activities on
327328
with `--skip-tags`, to skip modifying these directories. This can be useful when using tag
328329
`sap_hana_install_preinstall`.
329330
- tag `sap_hana_install_configure_firewall`: Use this flag to only configure the firewall ports for
330-
SAP HANA. Note: The role variable `sap_hana_install_update_firewall` has to be set to `yes` as
331+
SAP HANA. Note: The role variable `sap_hana_install_update_firewall` has to be set to `true` as
331332
well.
332333
- tag `sap_hana_install_extract_sarfiles`: Use this flag with `--skip-tags` to run the SAR file
333334
preparation steps of tag `sap_hana_install_prepare_sarfiles` without extracting the SAR files.

ansible/playbooks/roles/sap_hana_install/defaults/main.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ sap_hana_install_software_directory: '/software/hana'
1111
# created again before the extraction starts.
1212
sap_hana_install_software_extract_directory: "{{ sap_hana_install_software_directory }}/extracted"
1313

14-
# Set this variabe to `yes` if you want to copy the SAR files from `sap_hana_install_software_directory`
14+
# Set this variabe to `true` if you want to copy the SAR files from `sap_hana_install_software_directory`
1515
# to `sap_hana_install_software_extract_directory/sarfiles` before extracting.
1616
# This might be useful if the SAR files are on a slow fileshare.
17-
sap_hana_install_copy_sarfiles: no
17+
sap_hana_install_copy_sarfiles: false
1818

19-
# Set the following variable to `yes` if you want to keep the copied SAR files. By default, the SAR files will be
19+
# Set the following variable to `true` if you want to keep the copied SAR files. By default, the SAR files will be
2020
# removed after extraction.
21-
sap_hana_install_keep_copied_sarfiles: no
21+
sap_hana_install_keep_copied_sarfiles: false
2222

2323
# File name of SAPCAR*EXE in the software directory. If the variable is not set and there is more than one SAPCAR executable
2424
# in the software directory, the latest SAPCAR executable for the CPU architecture will be selected automatically.
@@ -30,9 +30,9 @@ sap_hana_install_keep_copied_sarfiles: no
3030
# - SAPHOSTAGENT54_54-80004822.SAR
3131
# - IMDB_SERVER20_060_0-80002031.SAR
3232

33-
# Set the following variable to `yes` to let the role abort if checksum verification fails for any SAPCAR or SAR file
33+
# Set the following variable to `true` to let the role abort if checksum verification fails for any SAPCAR or SAR file
3434
# called or used by the role.
35-
sap_hana_install_verify_checksums: no
35+
sap_hana_install_verify_checksums: false
3636

3737
# Checksum algorithm for checksum verification. Default is sha256, for which a checksum is available in the SAP software
3838
# download pages.
@@ -41,9 +41,9 @@ sap_hana_install_checksum_algorithm: sha256
4141
# In case a global checksum file is present, use the following variable to specify the full path to this file:
4242
#sap_hana_install_global_checksum_file: "{{ sap_hana_install_software_directory }}/SHA256"
4343

44-
# Set the following variable to `yes` to let hdbclm verify SAR file signatures. This corresponds to the hdblcm command line
44+
# Set the following variable to `true` to let hdbclm verify SAR file signatures. This corresponds to the hdblcm command line
4545
# argument `--verify_signature`.
46-
sap_hana_install_verify_signature: no
46+
sap_hana_install_verify_signature: false
4747

4848
# hdblcm configfile related variables:
4949
# Directory where to store the hdblcm configfile template and the Jinja2 template:
@@ -57,31 +57,31 @@ sap_hana_install_local_configfile_directory: '/tmp'
5757

5858
# If you would like to perform an installation check after the installation, set the following variable to 'yes'.
5959
# Note: This only works if there is no static configfile available in sap_hana_install_configfile_directory.
60-
sap_hana_install_check_installation: no
60+
sap_hana_install_check_installation: false
6161

62-
# Only if sap_hana_install_check_installation (above) is set to 'yes', you can select which command to use by setting the
63-
# following variable to `yes` or `no`.
62+
# Only if sap_hana_install_check_installation (above) is set to 'true', you can select which command to use by setting the
63+
# following variable to `true` or `false`.
6464
# yes: use the command 'hdbcheck', with parameters `--remote_execution=ssh` and `--scope=system`
6565
# no: use the command `hdblcm --action=check_installation`
66-
sap_hana_install_use_hdbcheck: yes
66+
sap_hana_install_use_hdbcheck: true
6767

68-
# If the following variable is set to `no`, the role will attempt to install SAP HANA even if there is already a sidadm user.
69-
# Default is `yes`.
70-
sap_hana_install_check_sidadm_user: yes
68+
# If the following variable is set to `false`, the role will attempt to install SAP HANA even if there is already a sidadm user.
69+
# Default is `true`.
70+
sap_hana_install_check_sidadm_user: true
7171

72-
# If the following variable is undefined or set to `yes`, the role will perform a fresh SAP HANA installation.
73-
# If set to `no`, additional hosts as specified by variable sap_hana_install_addhosts will be added to
72+
# If the following variable is undefined or set to `true`, the role will perform a fresh SAP HANA installation.
73+
# If set to `false`, additional hosts as specified by variable sap_hana_install_addhosts will be added to
7474
# an existing HANA system.
75-
sap_hana_install_new_system: yes
75+
sap_hana_install_new_system: true
7676

7777
# The first tenant database is using a port range not within the range of the ports of additional tenant databases.
7878
# In case this is not desired, you can set the following parameter to `yes` to recreate the initial tenant database.
79-
sap_hana_install_recreate_tenant_database: no
79+
sap_hana_install_recreate_tenant_database: false
8080

8181
# The following parameter controls if the log_mode should be set to overwrite following the installation of the database.
8282
# log_mode overwrite is useful in non-prod testing as log backups are not created and disk use is kept low
8383
# However, log_mode overwrite disabled to ability to do point-in-time restores and is not supported in production
84-
sap_hana_set_log_mode_overwrite: no
84+
sap_hana_set_log_mode_overwrite: false
8585

8686
################
8787
# Parameters for hdblcm:
@@ -123,7 +123,7 @@ sap_hana_install_use_master_password: 'y'
123123
#sap_hana_install_xs_org_password:
124124

125125
# Optional steps
126-
sap_hana_install_update_firewall: no
126+
sap_hana_install_update_firewall: false
127127

128128
# List of firewall ports for SAP HANA. Note: The structure of the variable is compatible
129129
# with the variable `firewall` of Linux System Role `firewall`.
@@ -156,7 +156,7 @@ sap_hana_install_hdbuserstore_key: 'HDB_SYSTEMDB'
156156
sap_hana_install_nw_input_location: '/tmp'
157157

158158
# License
159-
sap_hana_install_apply_license: no
159+
sap_hana_install_apply_license: false
160160
#sap_hana_install_license_path:
161161
#sap_hana_install_license_file_name:
162162

ansible/playbooks/roles/sap_hana_install/tasks/post_install/firewall.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22

3-
- name: SAP HANA Post Install - Enable and start the firewalld service
4-
ansible.builtin.systemd:
5-
name: firewalld
6-
state: started
7-
enabled: yes
8-
tags: sap_hana_install_configure_firewall
3+
# - name: SAP HANA Post Install - Enable and start the firewalld service
4+
# ansible.builtin.systemd:
5+
# name: firewalld
6+
# state: started
7+
# enabled: true
8+
# tags: sap_hana_install_configure_firewall
99

1010
- name: SAP HANA Post Install - Construct the argument list for 'firewall-cmd --add-port'
1111
ansible.builtin.set_fact:
@@ -37,12 +37,12 @@
3737
# of the no-changed-when rule, we just set changed_when to true here.
3838
- name: SAP HANA Post Install - Enable the required ports immediately
3939
ansible.builtin.command: "{{ __sap_hana_install_fact_firewall_cmd_command }}"
40-
changed_when: yes
40+
changed_when: true
4141
tags: sap_hana_install_configure_firewall
4242

4343
- name: SAP HANA Post Install - Get the current firewall configuration of the default zone
4444
ansible.builtin.command: firewall-cmd --list-all
45-
changed_when: no
45+
changed_when: false
4646
register: __sap_hana_install_register_current_firewall_ports
4747
tags: sap_hana_install_configure_firewall
4848

@@ -56,12 +56,12 @@
5656
# of the no-changed-when rule, we just set changed_when to true here.
5757
- name: SAP HANA Post Install - Enable the required ports permanently
5858
ansible.builtin.command: "{{ __sap_hana_install_fact_firewall_cmd_command }} --permanent"
59-
changed_when: yes
59+
changed_when: true
6060
tags: sap_hana_install_configure_firewall
6161

6262
- name: SAP HANA Post Install - Get the permanent firewall configuration of the default zone
6363
ansible.builtin.command: firewall-cmd --list-all
64-
changed_when: no
64+
changed_when: false
6565
register: __sap_hana_install_register_permanent_firewall_ports
6666
tags: sap_hana_install_configure_firewall
6767

ansible/playbooks/roles/sap_hana_install/tasks/pre_install/prepare_sarfiles.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
when: sap_hana_install_sarfiles is not defined
3939

40-
- name: Copy SAR files to final destination if 'sap_hana_install_copy_sarfiles' is 'yes'
40+
- name: Copy SAR files to final destination if 'sap_hana_install_copy_sarfiles' is 'true'
4141
block:
4242

4343
- name: SAP HANA hdblcm prepare - Create directory '{{ sap_hana_install_software_extract_directory }}/sarfiles'

ansible/playbooks/sap-hana-preconfigure.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use_connecttimeout: 10
2525
saptune_solution: HANA
2626
cluster_node: true
27+
firewall_cfg: 'ignore'
2728

2829
tasks:
2930
# Ensure required installation of required packages
@@ -75,6 +76,39 @@
7576
state: present
7677
when: cluster_node | bool
7778

79+
- name: Validate firewall_cfg
80+
ansible.builtin.assert:
81+
that:
82+
- firewall_cfg is defined
83+
- firewall_cfg in ['ignore', 'enable', 'disable']
84+
fail_msg: "Variable 'firewall_cfg' must be 'ignore', 'enable' or 'disable'. Found '{{ firewall_cfg }}'"
85+
86+
- name: Get service facts
87+
ansible.builtin.service_facts:
88+
89+
- name: Debug firewall status on specific OS version
90+
ansible.builtin.debug:
91+
msg:
92+
- "[OSADO][softfail] bsc#1254356"
93+
- "The firewalld service is not stopped and disabled on this system."
94+
when:
95+
- ansible_distribution_major_version == '16'
96+
- firewall_cfg != 'ignore' # avoid to hide the bug by forcing the firewall state
97+
- "'firewalld' in ansible_facts.services"
98+
- ansible_facts.services['firewalld'].state != 'stopped' or ansible_facts.services['firewalld'].status != 'disabled'
99+
100+
- name: Set firewall service state and enabled status
101+
ansible.builtin.set_fact:
102+
firewall_service_state: "{{ 'started' if firewall_cfg == 'enable' else 'stopped' }}"
103+
firewall_service_enabled: "{{ 'yes' if firewall_cfg == 'enable' else 'no' }}"
104+
105+
- name: Configure the firewall service state
106+
ansible.builtin.systemd:
107+
name: firewalld
108+
state: "{{ firewall_service_state }}"
109+
enabled: "{{ firewall_service_enabled }}"
110+
when: firewall_cfg != 'ignore'
111+
78112
- name: Configure sapconf based systems
79113
ansible.builtin.include_tasks: ./tasks/sapconf.yaml
80114
when: use_sapconf | bool

0 commit comments

Comments
 (0)