From 6011a2b53974d61569431223c465110b5c775af5 Mon Sep 17 00:00:00 2001 From: Shawn Wilsher <656602+sdwilsh@users.noreply.github.com> Date: Mon, 13 Dec 2021 15:12:53 -0800 Subject: [PATCH 1/2] Support diff mode when using `vyos_firewall_rules` This change adds support for [diff mode](https://docs.ansible.com/ansible/latest/user_guide/playbooks_checkmode.html#using-diff-mode) to `vyos_firewall_rules`. This can aide someone into understanding what will check when using [check mode](https://docs.ansible.com/ansible/latest/user_guide/playbooks_checkmode.html#using-check-mode), and can help someone know what has changed when running their play (using just `--diff` without `--check`). --- changelogs/fragments/diff-mode-firewall_rules.yml | 3 +++ .../vyos/config/firewall_rules/firewall_rules.py | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 changelogs/fragments/diff-mode-firewall_rules.yml diff --git a/changelogs/fragments/diff-mode-firewall_rules.yml b/changelogs/fragments/diff-mode-firewall_rules.yml new file mode 100644 index 00000000..de007efb --- /dev/null +++ b/changelogs/fragments/diff-mode-firewall_rules.yml @@ -0,0 +1,3 @@ +--- +major_changes: + - Support [diff mode](https://docs.ansible.com/ansible/latest/user_guide/playbooks_checkmode.html#using-diff-mode) in `vyos_firewall_rules` diff --git a/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py b/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py index 3c56626f..9a4bb9c5 100644 --- a/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py +++ b/plugins/module_utils/network/vyos/config/firewall_rules/firewall_rules.py @@ -114,6 +114,17 @@ def execute_module(self): result["gathered"] = changed_firewall_rules_facts result["warnings"] = warnings + + if self.state in self.ACTION_STATES and self._module._diff: + result["diff"] = { + "after": "\n".join( + sorted(self.set_state(self._module.params["config"], {})) + ), + "before": "\n".join( + sorted(self.set_state(existing_firewall_rules_facts, {})) + ), + } + return result def set_config(self, existing_firewall_rules_facts): From e86f042194aab7fcb55c524fbbba2ccee06ad558 Mon Sep 17 00:00:00 2001 From: Shawn Wilsher <656602+sdwilsh@users.noreply.github.com> Date: Mon, 13 Dec 2021 16:08:23 -0800 Subject: [PATCH 2/2] use RST, not markdown, in the changelog fragment --- changelogs/fragments/diff-mode-firewall_rules.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/diff-mode-firewall_rules.yml b/changelogs/fragments/diff-mode-firewall_rules.yml index de007efb..b5ecf15a 100644 --- a/changelogs/fragments/diff-mode-firewall_rules.yml +++ b/changelogs/fragments/diff-mode-firewall_rules.yml @@ -1,3 +1,3 @@ --- major_changes: - - Support [diff mode](https://docs.ansible.com/ansible/latest/user_guide/playbooks_checkmode.html#using-diff-mode) in `vyos_firewall_rules` + - Support `diff mode ` in ``vyos_firewall_rules``