Skip to content

Commit 681d424

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.
1 parent fd8bea6 commit 681d424

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

ansible/playbooks/roles/sap_hana_install/README.md

Lines changed: 2 additions & 1 deletion
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 `yes` (default is `no`, 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

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
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+
# Controlled by sap-hana-preconfigure.yaml playbook
4+
#- name: SAP HANA Post Install - Enable and start the firewalld service
5+
# ansible.builtin.systemd:
6+
# name: firewalld
7+
# state: started
8+
# enabled: yes
9+
# tags: sap_hana_install_configure_firewall
910

1011
- name: SAP HANA Post Install - Set LogDenied to all in firewalld.conf
1112
ansible.builtin.lineinfile:

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)