From 796d87f585656ca0da65500cccd40a096c0a60e2 2024-09-07 14:48:33 From: Branko Majic Date: 2024-09-07 14:48:33 Subject: [PATCH] MAR-218: Fix the custom m_ldap_permissions module to work correctly with ansible-lint: - In order for things to behave correctly, module should not invoke the main part of code automatically during import, but only if run via CLI. - Without this the ansible-lint kept erroring out with: "missing required arguments: filter, rules" --- diff --git a/roles/ldap_server/library/m_ldap_permissions.py b/roles/ldap_server/library/m_ldap_permissions.py index 54b014876d8e01b8a86a95e8887138a6f6a6c5b7..58b4a4bba9a8ac72263ddbe9b4eb5fd42a0492cb 100644 --- a/roles/ldap_server/library/m_ldap_permissions.py +++ b/roles/ldap_server/library/m_ldap_permissions.py @@ -1,7 +1,10 @@ #!/usr/bin/python3 +from __future__ import (absolute_import, division, print_function) from ansible.module_utils.basic import AnsibleModule +__metaclass__ = type + # Try to load the Python LDAP module. try: import ldap @@ -256,7 +259,7 @@ class LDAPPermissions(object): return True -def main(): +def run_module(): """ Runs the module. """ @@ -298,5 +301,9 @@ def main(): module.exit_json(changed=changed) -# Import module snippets. -main() +def main(): + run_module() + + +if __name__ == '__main__': + main()