Skip to content

Commit e88b15e

Browse files
martinpittrichm
authored andcommitted
fix: Make disabling of conflicting services work in container environments
Cause: The `firewall_disable_conflicting_services` option did not work in container build environments, as Ansible's `service_facts` completely fail there. Consequence: Running the role with that option during e.g. a bootc image build errored out with "Failed to find any services". Fix: The role only actually needs to know about the status of a small list of known conflicting services. Query these with `systemctl is-enabled` which works fine in container builds. Drop the obsolete `service_mgr == 'systemd'` check. All our supported platforms run systemd, and we don't test anything else.
1 parent d2b633e commit e88b15e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

tasks/main.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22
- name: Setup firewalld
33
include_tasks: firewalld.yml
44

5-
- name: Collect service facts
6-
service_facts:
5+
- name: Check which conflicting services are enabled
6+
# noqa command-instead-of-module
7+
command: systemctl is-enabled "{{ item }}"
8+
register: __firewall_conflicting_services_status
9+
changed_when: false
10+
failed_when: false
11+
loop: "{{ __firewall_conflicting_services }}"
712
when: firewall_disable_conflicting_services | bool
813

914
- name: Attempt to stop and disable conflicting services
1015
service:
11-
name: "{{ item }}"
16+
name: "{{ item.item }}"
1217
state: stopped
1318
enabled: false
14-
loop: "{{ __firewall_conflicting_services }}"
15-
vars:
16-
__service_name: "{{ (ansible_facts.service_mgr == 'systemd') |
17-
ternary(item ~ '.service', item) }}"
19+
loop: "{{ __firewall_conflicting_services_status.results }}"
1820
when:
1921
- firewall_disable_conflicting_services | bool
20-
- __service_name | string in ansible_facts.services
21-
- ansible_facts.services[__service_name]["status"] == "enabled"
22+
- item.rc == 0
2223

2324
- name: Unmask firewalld service
2425
systemd:

0 commit comments

Comments
 (0)