firewalld_info: fail cleanly when D-Bus is unavailable (#805)

python-firewall wraps a missing D-Bus socket in FirewallError, which the module did not catch, so Ansible reported a module crash instead of a normal failure.

Fixes #678


Assisted-by: Grok 4.7

Signed-off-by: Nikhil Jain <nikhjain@redhat.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nikhil Jain
2026-10-19 17:05:46 +09:00
committed by GitHub
co-authored by Cursor
parent d5699a3fcf
commit dddd6c9b35
2 changed files with 8 additions and 0 deletions
@@ -0,0 +1,4 @@
bugfixes:
- firewalld_info - return a module failure instead of a traceback when python-firewall raises
``FirewallError``, for example when D-Bus is unavailable
(https://github.com/ansible-collections/ansible.posix/issues/678).
+4
View File
@@ -224,9 +224,11 @@ except ImportError:
try:
import firewall.client as fw_client
import firewall.config as fw_config
import firewall.errors as fw_errors
HAS_FIREWALLD = True
except ImportError:
HAS_FIREWALLD = False
fw_errors = None
def get_version():
@@ -387,6 +389,8 @@ def main():
module.fail_json(msg=('Unable to gather firewalld settings.'
' You may need to run as the root user or'
' use become. (Error: %s)' % to_native(e)))
except fw_errors.FirewallError as e:
module.fail_json(msg='Unable to gather firewalld settings. (Error: %s)' % to_native(e))
result['collected_zones'] = collect_zones
result['undefined_zones'] = ignore_zones