Skip to content

Commit 534e045

Browse files
authored
Merge pull request sap-linuxlab#1170 from marcelmamula/ha_firewall
sap_ha_pacemaker_cluster: Add firewall steps
2 parents b237360 + 7a3a750 commit 534e045

8 files changed

Lines changed: 191 additions & 0 deletions

File tree

roles/sap_ha_pacemaker_cluster/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,23 @@ sap_ha_pacemaker_cluster_cluster_properties:
284284
stonith-timeout: 150
285285
```
286286

287+
### sap_ha_pacemaker_cluster_configure_firewall
288+
- _Type:_ `bool`
289+
- _Default:_ `false`
290+
291+
Set this variable to `true` to configure the required firewall ports for Pacemaker/Corosync.<br>
292+
What this configuration includes:<br>
293+
- Installation of the `firewalld` package and starting the service.<br>
294+
- A Firewalld service definition is created with recommended ports:<br>
295+
5404-5405/udp for Corosync communication and 2224/tcp with 3121/tcp for Pacemaker remote communication.<br>
296+
Important: This does not include configuration of ports for SAP products, as they are not directly installed with this role.<br>
297+
For example:<br>
298+
- Firewall configuration for SAP HANA can be managed separately in the `sap_hana_install` role.<br>
299+
- Firewall configuration for SAP ASCS/ERS can be managed separately in the `sap_swpm` role.<br>
300+
Managing configured Firewall:<br>
301+
- Setting this variable to `false` does not remove any existing firewall configuration.<br>
302+
- For ongoing firewall management, consider using the `community.sap_operations.sap_firewall` role or the `firewall` Linux System Role.<br>
303+
287304
### sap_ha_pacemaker_cluster_corosync_totem
288305
- _Type:_ `dict`
289306
- _Default:_ `Specified in Operating System and Platform variables.`
@@ -356,6 +373,12 @@ For SAP clusters configured by this role, the relevant standard packages for the
356373
Additional fence agent packages to be installed.<br>
357374
This is automatically combined with default OS and Platform specific packages.<br>
358375

376+
### sap_ha_pacemaker_cluster_firewall_zone
377+
- _Type:_ `str`
378+
379+
Optional name of firewall zone where service or ports will be configured.<br>
380+
Default firewall zone, usually `public`, is used if this variable is undefined.<br>
381+
359382
### sap_ha_pacemaker_cluster_gcp_project
360383
- _Type:_ `string`
361384

roles/sap_ha_pacemaker_cluster/defaults/main.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ sap_ha_pacemaker_cluster_constraint_colo_base_score: 2000
8080
sap_ha_pacemaker_cluster_corosync_totem: {}
8181
sap_ha_pacemaker_cluster_corosync_transport: {}
8282

83+
### Firewall
84+
# Set this variable to `true` to configure the required firewall ports for Pacemaker/Corosync.
85+
# What this configuration includes:
86+
# - Installation of the `firewalld` package and starting the service.
87+
# - A Firewalld service definition is created with recommended ports:
88+
# 5404-5405/udp for Corosync communication and 2224/tcp with 3121/tcp for Pacemaker remote communication.
89+
# Important: This does not include configuration of ports for SAP products, as they are not directly installed with this role.
90+
# For example:
91+
# - Firewall configuration for SAP HANA can be managed separately in the `sap_hana_install` role.
92+
# - Firewall configuration for SAP ASCS/ERS can be managed separately in the `sap_swpm` role.
93+
# Managing configured Firewall:
94+
# - Setting this variable to `false` does not remove any existing firewall configuration.
95+
# - For ongoing firewall management, consider using the `community.sap_operations.sap_firewall` role or the `firewall` Linux System Role.
96+
sap_ha_pacemaker_cluster_configure_firewall: false
97+
98+
# Optional name of firewall zone where service or ports will be configured.
99+
# Default firewall zone, usually `public`, is used if this variable is undefined.
100+
# sap_ha_pacemaker_cluster_firewall_zone: ''
101+
83102
################################################################################
84103
# Inherit from 'ha_cluster' Linux System Role parameters when defined
85104
################################################################################

roles/sap_ha_pacemaker_cluster/meta/argument_specs.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,29 @@ argument_specs:
333333
- name: crypto_cipher
334334
value: aes256
335335

336+
sap_ha_pacemaker_cluster_configure_firewall:
337+
type: bool
338+
default: false
339+
description:
340+
- Set this variable to `true` to configure the required firewall ports for Pacemaker/Corosync.
341+
- "What this configuration includes:"
342+
- "- Installation of the `firewalld` package and starting the service."
343+
- "- A Firewalld service definition is created with recommended ports:"
344+
- " 5404-5405/udp for Corosync communication and 2224/tcp with 3121/tcp for Pacemaker remote communication."
345+
- "Important: This does not include configuration of ports for SAP products, as they are not directly installed with this role."
346+
- "For example:"
347+
- "- Firewall configuration for SAP HANA can be managed separately in the `sap_hana_install` role."
348+
- "- Firewall configuration for SAP ASCS/ERS can be managed separately in the `sap_swpm` role."
349+
- "Managing configured Firewall:"
350+
- "- Setting this variable to `false` does not remove any existing firewall configuration."
351+
- "- For ongoing firewall management, consider using the `community.sap_operations.sap_firewall` role or the `firewall` Linux System Role."
352+
353+
sap_ha_pacemaker_cluster_firewall_zone:
354+
type: str
355+
description:
356+
- Optional name of firewall zone where service or ports will be configured.
357+
- "Default firewall zone, usually `public`, is used if this variable is undefined."
358+
336359

337360
##########################################################################
338361
# Parameters that are optionally imported from 'ha_cluster' LSR parameters
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
---
3+
4+
- name: SAP HA Install Pacemaker - Firewall - Install packages
5+
ansible.builtin.package:
6+
name: "{{ __sap_ha_pacemaker_cluster_firewall_packages + __sap_ha_pacemaker_cluster_firewall_extra_packages }}"
7+
state: present
8+
9+
- name: SAP HA Install Pacemaker - Firewall - Start and enable firewalld service
10+
ansible.builtin.systemd_service:
11+
name: firewalld
12+
state: started
13+
enabled: true
14+
masked: false
15+
16+
17+
# Validate firewall zone if defined
18+
- name: Block for validation of firewall zone
19+
when: sap_ha_pacemaker_cluster_firewall_zone is defined
20+
block:
21+
- name: SAP HA Install Pacemaker - Firewall - Get list of configured zones from firewalld
22+
ansible.builtin.command:
23+
cmd: firewall-cmd --get-zones
24+
register: __sap_ha_pacemaker_cluster_register_firewall_zones
25+
changed_when: false
26+
27+
- name: SAP HA Install Pacemaker - Firewall - Assert that the firewall zone is available
28+
ansible.builtin.assert:
29+
that:
30+
- sap_ha_pacemaker_cluster_firewall_zone in __sap_ha_pacemaker_cluster_register_firewall_zones.stdout.split()
31+
success_msg: |
32+
PASS: The zone '{{ sap_ha_pacemaker_cluster_firewall_zone }}' is present in firewalld.
33+
fail_msg: |
34+
FAIL: The zone '{{ sap_ha_pacemaker_cluster_firewall_zone }}' is not preset in firewalld.
35+
Available zones: {{ __sap_ha_pacemaker_cluster_register_firewall_zones.stdout }}
36+
quiet: true
37+
38+
39+
# Proceed straight to firewall service configuration as custom ports are not an option.
40+
- name: SAP HA Install Pacemaker - Firewall - Generate service file from template
41+
ansible.builtin.template:
42+
src: firewall-ha-cluster.j2
43+
dest: "/etc/firewalld/services/{{ __sap_ha_pacemaker_cluster_firewall_service_name }}.xml"
44+
owner: 'root'
45+
group: 'root'
46+
mode: '0640'
47+
48+
- name: SAP HA Install Pacemaker - Firewall - Reload firewalld after creating service file
49+
ansible.builtin.command:
50+
cmd: firewall-cmd --reload
51+
changed_when: true
52+
53+
- name: SAP HA Install Pacemaker - Firewall - Configure service in firewall
54+
ansible.builtin.command:
55+
cmd: >-
56+
firewall-cmd
57+
{% if sap_ha_pacemaker_cluster_firewall_zone is defined %}
58+
--zone={{ sap_ha_pacemaker_cluster_firewall_zone }}
59+
{% endif %}
60+
--permanent
61+
--add-service={{ __sap_ha_pacemaker_cluster_firewall_service_name }}
62+
register: __sap_ha_pacemaker_cluster_register_firewall_add_service
63+
changed_when: true
64+
65+
66+
- name: SAP HA Install Pacemaker - Firewall - Reload firewalld after applying changes
67+
ansible.builtin.command:
68+
cmd: firewall-cmd --reload
69+
changed_when: true
70+
71+
- name: SAP HA Install Pacemaker - Firewall - Get current firewall configuration of the default zone
72+
ansible.builtin.command:
73+
cmd: firewall-cmd --list-all
74+
changed_when: false
75+
register: __sap_ha_pacemaker_cluster_register_current_firewall_configuration
76+
77+
78+
- name: SAP HA Install Pacemaker - Firewall - Show details of configured firewall
79+
ansible.builtin.debug:
80+
msg: |
81+
Firewall was configured for SAP High Availability Cluster and reloaded.
82+
Output of command 'firewall-cmd --list-all':
83+
{{ __sap_ha_pacemaker_cluster_register_current_firewall_configuration.stdout }}
84+
when: __sap_ha_pacemaker_cluster_register_current_firewall_configuration.stdout is defined

roles/sap_ha_pacemaker_cluster/tasks/pre_tasks/pre_main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
when: __task_file_path is file
1414
tags: pre_ha_cluster
1515

16+
# Firewall
17+
- name: SAP HA Install Pacemaker - Configure Firewall
18+
ansible.builtin.include_tasks:
19+
file: pre_firewall.yml
20+
when: sap_ha_pacemaker_cluster_configure_firewall | d(false)
21+
1622

1723
# ASCS/ERS
1824
- name: "SAP HA Install Pacemaker - Include NetWeaver (A)SCS/ERS pre-tasks"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<service>
3+
<short>SAP HA Cluster (Pacemaker/Corosync)</short>
4+
<description>Core ports required for SAP High Availability (HA) Cluster. Maintained by Ansible Role sap_install.sap_ha_pacemaker_cluster.</description>
5+
6+
{# Default UDP ports used by Corosync for inter-node communication and cluster heartbeats. -#}
7+
<port protocol="udp" port="5404-5405"/>
8+
9+
{# TCP ports used by the Pacemaker Remote service to manage remote nodes or containerized resources. -#}
10+
<port protocol="tcp" port="2224"/>
11+
<port protocol="tcp" port="3121"/>
12+
13+
</service>

roles/sap_ha_pacemaker_cluster/vars/SLES_15.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,18 @@ __sap_ha_pacemaker_cluster_sap_zypper_patterns_dict:
2424
hana_scaleout: []
2525
hana_scaleup: []
2626
nwas: []
27+
28+
# Firewall
29+
# NOTE: SLES 16 contains dependency between firewalld and python313-firewall package.
30+
31+
__sap_ha_pacemaker_cluster_firewall_extra_packages:
32+
"{{ __sap_ha_pacemaker_cluster_firewall_extra_packages_3
33+
if ansible_facts['distribution_version'].split('.')[1] | int < 6
34+
else __sap_ha_pacemaker_cluster_firewall_extra_packages_311 }}"
35+
36+
# The lists of bindings for specific python version
37+
__sap_ha_pacemaker_cluster_firewall_extra_packages_3:
38+
- "python3-firewall"
39+
40+
__sap_ha_pacemaker_cluster_firewall_extra_packages_311:
41+
- "python311-firewall"

roles/sap_ha_pacemaker_cluster/vars/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,11 @@ __sap_ha_pacemaker_cluster_resource_primitives: []
110110
# Pre-define this parameter in its dictionary format:
111111
__sap_ha_pacemaker_cluster_corosync_totem:
112112
options: []
113+
114+
# List of firewall packages
115+
__sap_ha_pacemaker_cluster_firewall_packages:
116+
- firewalld
117+
__sap_ha_pacemaker_cluster_firewall_extra_packages: []
118+
119+
# Predefined firewall service name.
120+
__sap_ha_pacemaker_cluster_firewall_service_name: "sap-ha-cluster"

0 commit comments

Comments
 (0)