From 926134cc3653fc3c4fcabb341227c2c7d947fbcb Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman Date: Fri, 25 Jun 2021 09:14:04 -0300 Subject: [PATCH 1/2] FreeIPABaseModule: Add support for check_mode. All ansible-freeipa modules should support 'check_mode: yes', but the support for creating modules with this was absent in the base class. This patch adds such support, to use it, 'supports_check_mode=True' must be passed to the constructor when creating the module object. --- plugins/module_utils/ansible_freeipa_module.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/module_utils/ansible_freeipa_module.py b/plugins/module_utils/ansible_freeipa_module.py index 71ce4063..36f78c01 100644 --- a/plugins/module_utils/ansible_freeipa_module.py +++ b/plugins/module_utils/ansible_freeipa_module.py @@ -786,6 +786,10 @@ else: def _run_ipa_commands(self): """Execute commands in self.ipa_commands.""" + if self.check_mode: + self.changed = len(self.ipa_commands) > 0 + return + result = None for name, command, args in self.ipa_commands: From a84071b8a965fb654c569070d65107d0f60d9986 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman Date: Fri, 25 Jun 2021 09:18:09 -0300 Subject: [PATCH 2/2] dnszone: Add support for check_mode. This patch adds support for check_mode to the dnszone management module, and provides tests to verify the behavior. --- plugins/modules/ipadnszone.py | 1 + tests/dnszone/test_dnszone.yml | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/plugins/modules/ipadnszone.py b/plugins/modules/ipadnszone.py index ae8ed93a..f8b11999 100644 --- a/plugins/modules/ipadnszone.py +++ b/plugins/modules/ipadnszone.py @@ -570,6 +570,7 @@ def main(): argument_spec=get_argument_spec(), mutually_exclusive=[["name", "name_from_ip"]], required_one_of=[["name", "name_from_ip"]], + supports_check_mode=True, ).ipa_run() diff --git a/tests/dnszone/test_dnszone.yml b/tests/dnszone/test_dnszone.yml index d7860aae..39f9cf38 100644 --- a/tests/dnszone/test_dnszone.yml +++ b/tests/dnszone/test_dnszone.yml @@ -11,6 +11,24 @@ include_tasks: env_setup.yml # Tests + - name: Check if zone is present, when in shouldn't be. + ipadnszone: + ipaadmin_password: SomeADMINpassword + name: testzone.local + state: present + check_mode: yes + register: result + failed_when: not result.changed or result.failed + + - name: Check if zone is present again, when in shouldn't be. + ipadnszone: + ipaadmin_password: SomeADMINpassword + name: testzone.local + state: present + check_mode: yes + register: result + failed_when: not result.changed or result.failed + - name: Ensure zone is present. ipadnszone: ipaadmin_password: SomeADMINpassword @@ -19,6 +37,15 @@ register: result failed_when: not result.changed or result.failed + - name: Check if zone is present, when in should be. + ipadnszone: + ipaadmin_password: SomeADMINpassword + name: testzone.local + state: present + check_mode: yes + register: result + failed_when: result.changed or result.failed + - name: Ensure zone is present, again. ipadnszone: ipaadmin_password: SomeADMINpassword