generated from linux-system-roles/template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the firewall role and the selinux role from the ha_cluster role
- Introduce ha_cluster_manage_firewall to use the firewall role to manage the high-availability service and the fence-virt port. Default to false - means the firewall role is not used. - Introduce ha_cluster_manage_selinux to use the selinux role to manage the ports in the high-availability service. Assign cluster_port_t to the high-availability service ports. Default to false - means the selinux role is not used. - Add the test check task tasks/check_firewall_selinux.yml for verify the ports status. - Add meta/collection-requirements.yml. Note: This pr changes the ha_cluster role's behavior slightly. It used to configure firewall without any settings if the firewall service is enabled. With this change made by this pr, unless ha_cluster_manage_firewall is set to true, the firewall is not configured.
- Loading branch information
Showing
26 changed files
with
225 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# SPDX-License-Identifier: MIT | ||
collections: | ||
- fedora.linux_system_roles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,18 @@ | ||
# SPDX-License-Identifier: MIT | ||
--- | ||
- name: Get services status - detect firewall | ||
service_facts: | ||
|
||
- name: Configure firewalld | ||
block: | ||
- name: Enable service 'high-availability' in firewalld | ||
command: firewall-cmd --add-service high-availability | ||
when: ansible_facts.services['firewalld.service'].state == 'running' | ||
register: __ha_cluster_firewall_cmd | ||
failed_when: | ||
- __ha_cluster_firewall_cmd.rc != 0 | ||
- __ha_cluster_firewall_cmd.rc != 11 # already enabled | ||
|
||
- name: Enable service 'high-availability' in firewalld permanent config | ||
command: firewall-cmd --permanent --add-service high-availability | ||
register: __ha_cluster_firewall_cmd | ||
when: ansible_facts.services['firewalld.service'].state == 'running' | ||
failed_when: | ||
- __ha_cluster_firewall_cmd.rc != 0 | ||
- __ha_cluster_firewall_cmd.rc != 11 # already enabled | ||
|
||
- name: Enable service 'high-availability' in firewalld offline config | ||
command: firewall-offline-cmd --add-service high-availability | ||
register: __ha_cluster_firewall_cmd | ||
when: ansible_facts.services['firewalld.service'].state != 'running' | ||
failed_when: | ||
- __ha_cluster_firewall_cmd.rc != 0 | ||
- __ha_cluster_firewall_cmd.rc != 11 # already enabled | ||
|
||
- name: Enable fence-virt port in firewalld - all options | ||
when: | ||
- ansible_architecture == 'x86_64' | ||
- ( | ||
'fence-virt' in ha_cluster_fence_agent_packages | ||
or | ||
'fence-virt' in ha_cluster_extra_packages | ||
or | ||
'fence-agents-all' in ha_cluster_fence_agent_packages | ||
or | ||
'fence-agents-all' in ha_cluster_extra_packages | ||
) | ||
block: | ||
- name: Enable fence-virt port in firewalld | ||
command: firewall-cmd --add-port 1229/tcp | ||
when: ansible_facts.services['firewalld.service'].state == 'running' | ||
register: __ha_cluster_firewall_cmd | ||
failed_when: | ||
- __ha_cluster_firewall_cmd.rc != 0 | ||
- __ha_cluster_firewall_cmd.rc != 11 # already enabled | ||
|
||
- name: Enable fence-virt port in firewalld permanent config | ||
command: firewall-cmd --permanent --add-port 1229/tcp | ||
when: ansible_facts.services['firewalld.service'].state == 'running' | ||
register: __ha_cluster_firewall_cmd | ||
failed_when: | ||
- __ha_cluster_firewall_cmd.rc != 0 | ||
- __ha_cluster_firewall_cmd.rc != 11 # already enabled | ||
|
||
- name: Enable fence-virt port in firewalld offline config | ||
command: firewall-offline-cmd --add-port 1229/tcp | ||
when: ansible_facts.services['firewalld.service'].state != 'running' | ||
register: __ha_cluster_firewall_cmd | ||
failed_when: | ||
- __ha_cluster_firewall_cmd.rc != 0 | ||
- __ha_cluster_firewall_cmd.rc != 11 # already enabled | ||
|
||
- name: Ensure the service and the ports status with the firewall role | ||
include_role: | ||
name: fedora.linux_system_roles.firewall | ||
vars: | ||
__arch: "{{ ansible_facts['architecture'] }}" | ||
__use_fence_fw_port: "{{ __arch == 'x86_64' and | ||
('fence-virt' in ha_cluster_fence_agent_packages | ||
or 'fence-virt' in ha_cluster_extra_packages | ||
or 'fence-agents-all' in ha_cluster_fence_agent_packages | ||
or 'fence-agents-all' in ha_cluster_extra_packages) }}" | ||
__fence_fw_port: "{{ [{'port': '1229/tcp', 'state': 'enabled'}] | ||
if __use_fence_fw_port else [] }}" | ||
__ha_fw_service: [{'service': 'high-availability', 'state': 'enabled' }] | ||
firewall: "{{ __ha_fw_service + __fence_fw_port }}" | ||
when: | ||
- '"firewalld.service" in ansible_facts.services' | ||
- ha_cluster_manage_firewall | bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# SPDX-License-Identifier: MIT | ||
--- | ||
- name: Populate service facts | ||
service_facts: | ||
|
||
- block: | ||
- name: Set the fence-virt/fence-agents port to _ha_cluster_selinux | ||
set_fact: | ||
_ha_cluster_selinux: | ||
- {'ports': '1229', 'proto': 'tcp', 'setype': 'cluster_port_t', | ||
'state': 'present', 'local': true} | ||
when: | ||
- ( | ||
'fence-virt' in ha_cluster_fence_agent_packages | ||
or | ||
'fence-virt' in ha_cluster_extra_packages | ||
or | ||
'fence-agents-all' in ha_cluster_fence_agent_packages | ||
or | ||
'fence-agents-all' in ha_cluster_extra_packages | ||
) | ||
|
||
- name: Get associated selinux ports | ||
shell: |- | ||
set -euo pipefail | ||
firewall-cmd --info-service=high-availability | \ | ||
egrep " +ports: +" | sed -e "s/ *ports: //" | ||
register: __ports | ||
changed_when: false | ||
|
||
- name: Add the high-availability service ports to _ha_cluster_selinux | ||
set_fact: | ||
_ha_cluster_selinux: "{{ _ha_cluster_selinux | d([]) + | ||
[{'ports': _pair[0], 'proto': _pair[1], 'setype': 'cluster_port_t', | ||
'state': 'present', 'local': true}] }}" | ||
vars: | ||
_pair: "{{ item.split('/') }}" | ||
loop: "{{ __ports.stdout.split(' ') }}" | ||
|
||
- name: Ensure the service and the ports status with the selinux role | ||
include_role: | ||
name: fedora.linux_system_roles.selinux | ||
vars: | ||
selinux_ports: "{{ _ha_cluster_selinux }}" | ||
when: | ||
- '"firewalld.service" in ansible_facts.services' | ||
- ansible_facts.services["firewalld.service"]["state"] == "running" | ||
- ha_cluster_manage_selinux | bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# SPDX-License-Identifier: MIT | ||
--- | ||
- block: | ||
- name: Check firewall service status | ||
command: firewall-cmd --list-services | ||
register: _result | ||
failed_when: "'high-availability' not in _result.stdout" | ||
changed_when: false | ||
|
||
- name: Check firewall port status | ||
command: firewall-cmd --list-ports | ||
register: _result | ||
failed_when: "'1229/tcp' not in _result.stdout" | ||
changed_when: false | ||
when: ha_cluster_manage_firewall | bool | ||
|
||
- block: | ||
- name: Get associated selinux ports | ||
shell: |- | ||
set -euo pipefail | ||
firewall-cmd --info-service=high-availability | \ | ||
egrep " +ports: +" | sed -e "s/ *ports: //" | ||
register: __ports | ||
changed_when: false | ||
|
||
- name: Check associated selinux ports | ||
shell: |- | ||
set -euo pipefail | ||
sudo semanage port --list | grep cluster_port_t | \ | ||
grep "{{ _pair[0] }}" | grep "{{ _pair[1] }}" | ||
vars: | ||
_pair: "{{ item.split('/') }}" | ||
loop: "{{ __ports.stdout.split(' ') }}" | ||
changed_when: false | ||
when: | ||
- ha_cluster_manage_firewall | bool | ||
- ha_cluster_manage_selinux | bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.