From ec51a15f69460b14b5f156535cfe93a925e4eb62 Mon Sep 17 00:00:00 2001 From: Hideki Saito Date: Mon, 18 May 2026 11:58:00 +0900 Subject: [PATCH] [Backport][Stable-2] Backport for #715 and #719 (#735) * firewalld_info: Use module.warn (#715) * Use module.warn to display warnings instead of module.exit_json Fixes: #710 Signed-off-by: Abhijeet Kasurde (cherry picked from commit d88a3c833cc883fc52177427cdf2a8297e526ddb) * firewalld_info: Use PY2 compatible syntax (#719) Signed-off-by: Abhijeet Kasurde (cherry picked from commit dbeb4a861db89346738acf22d7285801a590d866) --------- Signed-off-by: Abhijeet Kasurde Co-authored-by: Abhijeet Kasurde --- changelogs/fragments/firewalld_info_warnings.yml | 3 +++ plugins/modules/firewalld_info.py | 8 +------- .../targets/firewalld_info/tasks/run_tests_in_started.yml | 4 ++++ 3 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/firewalld_info_warnings.yml diff --git a/changelogs/fragments/firewalld_info_warnings.yml b/changelogs/fragments/firewalld_info_warnings.yml new file mode 100644 index 0000000..c214964 --- /dev/null +++ b/changelogs/fragments/firewalld_info_warnings.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - firewalld_info - use module.warn instead of passing ``warnings`` to ``exit_json`` (https://github.com/ansible-collections/ansible.posix/issues/710). diff --git a/plugins/modules/firewalld_info.py b/plugins/modules/firewalld_info.py index 94654ee..8c5536e 100644 --- a/plugins/modules/firewalld_info.py +++ b/plugins/modules/firewalld_info.py @@ -333,10 +333,6 @@ def main(): if not HAS_FIREWALLD: module.fail_json(msg=missing_required_lib('python-firewall')) - # If you want to show warning messages in the task running process, - # you can append the message to the 'warn' list. - warn = list() - try: client = fw_client.FirewallClient() @@ -356,8 +352,7 @@ def main(): collect_zones = list(set(specified_zones) & set(all_zones)) ignore_zones = list(set(specified_zones) - set(collect_zones)) if ignore_zones: - warn.append( - 'Please note: zone:(%s) have been ignored in the gathering process.' % ','.join(ignore_zones)) + module.warn('Please note: zone:(%s) have been ignored in the gathering process.' % ", ".join(ignore_zones)) else: collect_zones = get_all_zones(client) @@ -396,7 +391,6 @@ def main(): result['collected_zones'] = collect_zones result['undefined_zones'] = ignore_zones result['firewalld_info'] = firewalld_info - result['warnings'] = warn module.exit_json(**result) diff --git a/tests/integration/targets/firewalld_info/tasks/run_tests_in_started.yml b/tests/integration/targets/firewalld_info/tasks/run_tests_in_started.yml index 3b73845..83e1910 100644 --- a/tests/integration/targets/firewalld_info/tasks/run_tests_in_started.yml +++ b/tests/integration/targets/firewalld_info/tasks/run_tests_in_started.yml @@ -20,6 +20,7 @@ - name: Assert turn active_zones true ansible.builtin.assert: that: + - result.collected_zones == ['public'] - name: Ensure firewalld_zones with zone list ansible.posix.firewalld_info: @@ -31,3 +32,6 @@ - name: Assert specified zones ansible.builtin.assert: that: + - result.collected_zones == ['public'] + - result.undefined_zones == ['invalid_zone'] + - '"invalid_zone" in result.warnings[0]'