Changeset - 796d87f58565
[Not reviewed]
0 1 0
Branko Majic (branko) - 12 days ago 2024-09-07 14:48:33
branko@majic.rs
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"
1 file changed with 9 insertions and 2 deletions:
0 comments (0 inline, 0 general)
roles/ldap_server/library/m_ldap_permissions.py
Show inline comments
 
#!/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
 
    import ldap.sasl
 
    import ldap.modlist
 
except ImportError:
 
@@ -253,13 +256,13 @@ class LDAPPermissions(object):
 
            return False
 
        else:
 
            self.connection.modify_s(database[0], modify_list)
 
            return True
 

	
 

	
 
def main():
 
def run_module():
 
    """
 
    Runs the module.
 
    """
 

	
 
    # Construct the module helper for parsing the arguments.
 
    module = AnsibleModule(
 
@@ -295,8 +298,12 @@ def main():
 
    except DatabaseFilteringError as e:
 
        module.fail_json(msg="Module error: %s" % str(e))
 

	
 
    module.exit_json(changed=changed)
 

	
 

	
 
# Import module snippets.
 
def main():
 
    run_module()
 

	
 

	
 
if __name__ == '__main__':
 
    main()
0 comments (0 inline, 0 general)