From 1faf8ef08b130ecd8bfde4e4306308cabf8109f5 Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Wed, 23 Dec 2020 03:56:46 +1300 Subject: [PATCH] Ensured ``changed`` returns ``False``. (#1530) * Ensured ``changed`` returns ``False``. - Added small improvement on the ``_load_scope()`` method. * yamllint caught it * Rephrased changelog fragment --- ...040-ldap_search-changed-must-be-false.yaml | 2 ++ plugins/modules/net_tools/ldap/ldap_search.py | 22 ++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) create mode 100644 changelogs/fragments/1040-ldap_search-changed-must-be-false.yaml diff --git a/changelogs/fragments/1040-ldap_search-changed-must-be-false.yaml b/changelogs/fragments/1040-ldap_search-changed-must-be-false.yaml new file mode 100644 index 0000000000..6fc23f705b --- /dev/null +++ b/changelogs/fragments/1040-ldap_search-changed-must-be-false.yaml @@ -0,0 +1,2 @@ +bugfixes: + - ldap_search - the module no longer incorrectly reports a change (https://github.com/ansible-collections/community.general/issues/1040). diff --git a/plugins/modules/net_tools/ldap/ldap_search.py b/plugins/modules/net_tools/ldap/ldap_search.py index b89d9a0c97..3b1a283338 100644 --- a/plugins/modules/net_tools/ldap/ldap_search.py +++ b/plugins/modules/net_tools/ldap/ldap_search.py @@ -112,7 +112,7 @@ def main(): except Exception as exception: module.fail_json(msg="Attribute action failed.", details=to_native(exception)) - module.exit_json(changed=True) + module.exit_json(changed=False) def _extract_entry(dn, attrs): @@ -144,24 +144,20 @@ class LdapSearch(LdapGeneric): self.attrsonly = 0 def _load_scope(self): - scope = self.module.params['scope'] - if scope == 'base': - self.scope = ldap.SCOPE_BASE - elif scope == 'onelevel': - self.scope = ldap.SCOPE_ONELEVEL - elif scope == 'subordinate': - self.scope = ldap.SCOPE_SUBORDINATE - elif scope == 'children': - self.scope = ldap.SCOPE_SUBTREE - else: - raise AssertionError('Implementation error') + spec = dict( + base=ldap.SCOPE_BASE, + onelevel=ldap.SCOPE_ONELEVEL, + subordinate=ldap.SCOPE_SUBORDINATE, + children=ldap.SCOPE_SUBTREE, + ) + self.scope = spec[self.module.params['scope']] def _load_attrs(self): self.attrlist = self.module.params['attrs'] or None def main(self): results = self.perform_search() - self.module.exit_json(changed=True, results=results) + self.module.exit_json(changed=False, results=results) def perform_search(self): try: