From 1d22909f7cb6e6faedc5cdd8db3a7c8f0a646744 Mon Sep 17 00:00:00 2001 From: Tyler Hartley Date: Tue, 28 May 2019 11:54:11 -0700 Subject: [PATCH] Make second group match of ufw status output optional (#56678) * Make second group match of ufw status output optional Fixes #56674 * Fix comparison logic. * Add changelog fragment --- changelogs/fragments/56678-ufw-status-change-detection.yaml | 2 ++ lib/ansible/modules/system/ufw.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/56678-ufw-status-change-detection.yaml diff --git a/changelogs/fragments/56678-ufw-status-change-detection.yaml b/changelogs/fragments/56678-ufw-status-change-detection.yaml new file mode 100644 index 0000000000..3c567e14d9 --- /dev/null +++ b/changelogs/fragments/56678-ufw-status-change-detection.yaml @@ -0,0 +1,2 @@ +bugfixes: + - ufw - correctly check status when logging is off (https://github.com/ansible/ansible/issues/56674) diff --git a/lib/ansible/modules/system/ufw.py b/lib/ansible/modules/system/ufw.py index fbcf7a03dc..762a1c6c51 100644 --- a/lib/ansible/modules/system/ufw.py +++ b/lib/ansible/modules/system/ufw.py @@ -445,12 +445,14 @@ def main(): execute(cmd + [['-f'], [states[value]]]) elif command == 'logging': - extract = re.search(r'Logging: (on|off) \(([a-z]+)\)', pre_state) + extract = re.search(r'Logging: (on|off)(?: \(([a-z]+)\))?', pre_state) if extract: current_level = extract.group(2) current_on_off_value = extract.group(1) if value != "off": - if value != "on" and (value != current_level or current_on_off_value == "off"): + if current_on_off_value == "off": + changed = True + elif value != "on" and value != current_level: changed = True elif current_on_off_value != "off": changed = True