def main(): module = AnsibleModule( argument_spec=gen_specs( dn=dict(type='str', required=True), scope=dict(type='str', default='base', choices=['base', 'onelevel', 'subordinate', 'children']), filter=dict(type='str', default='(objectClass=*)'), attrs=dict(type='list', elements='str'), schema=dict(type='bool', default=False), ), supports_check_mode=True, ) if not HAS_LDAP: module.fail_json(msg=missing_required_lib('python-ldap'), exception=LDAP_IMP_ERR) if not module.check_mode: try: LdapSearch(module).main() except Exception as exception: module.fail_json(msg="Attribute action failed.", details=to_native(exception)) module.exit_json(changed=False)
def main(): module = AnsibleModule( argument_spec=gen_specs( attributes=dict(default={}, type='dict'), objectClass=dict(type='raw'), params=dict(type='dict'), state=dict(default='present', choices=['present', 'absent']), ), supports_check_mode=True, ) if not HAS_LDAP: module.fail_json(msg=missing_required_lib('python-ldap'), exception=LDAP_IMP_ERR) state = module.params['state'] # Check if objectClass is present when needed if state == 'present' and module.params['objectClass'] is None: module.fail_json(msg="At least one objectClass must be provided.") # Check if objectClass is of the correct type if (module.params['objectClass'] is not None and not (isinstance(module.params['objectClass'], string_types) or isinstance(module.params['objectClass'], list))): module.fail_json(msg="objectClass must be either a string or a list.") # Update module parameters with user's parameters if defined if 'params' in module.params and isinstance(module.params['params'], dict): for key, val in module.params['params'].items(): if key in module.argument_spec: module.params[key] = val else: module.params['attributes'][key] = val # Remove the params module.params.pop('params', None) # Instantiate the LdapEntry object ldap = LdapEntry(module) # Get the action function if state == 'present': action = ldap.add() elif state == 'absent': action = ldap.delete() # Perform the action if action is not None and not module.check_mode: try: action() except Exception as e: module.fail_json(msg="Entry action failed.", details=to_native(e), exception=traceback.format_exc()) module.exit_json(changed=(action is not None))
def main(): module = AnsibleModule( argument_spec=gen_specs( attributes=dict(default={}, type='dict'), objectClass=dict(type='raw'), params=dict(type='dict'), state=dict(default='present', choices=['present', 'absent']), ), supports_check_mode=True, ) if not HAS_LDAP: module.fail_json(msg=missing_required_lib('python-ldap'), exception=LDAP_IMP_ERR) if module.params['params']: module.fail_json( msg= "The `params` option to ldap_attr was removed since it circumvents Ansible's option handling" ) state = module.params['state'] # Check if objectClass is present when needed if state == 'present' and module.params['objectClass'] is None: module.fail_json(msg="At least one objectClass must be provided.") # Check if objectClass is of the correct type if (module.params['objectClass'] is not None and not (isinstance(module.params['objectClass'], string_types) or isinstance(module.params['objectClass'], list))): module.fail_json(msg="objectClass must be either a string or a list.") # Instantiate the LdapEntry object ldap = LdapEntry(module) # Get the action function if state == 'present': action = ldap.add() elif state == 'absent': action = ldap.delete() # Perform the action if action is not None and not module.check_mode: try: action() except Exception as e: module.fail_json(msg="Entry action failed.", details=to_native(e), exception=traceback.format_exc()) module.exit_json(changed=(action is not None))
def main(): module = AnsibleModule( argument_spec=gen_specs( name=dict(type='str', required=True), params=dict(type='dict'), state=dict(type='str', default='present', choices=['absent', 'exact', 'present']), values=dict(type='raw', required=True), ), supports_check_mode=True, ) if not HAS_LDAP: module.fail_json(msg=missing_required_lib('python-ldap'), exception=LDAP_IMP_ERR) if module.params['params']: module.fail_json( msg= "The `params` option to ldap_attr was removed in since it circumvents Ansible's option handling" ) # Instantiate the LdapAttr object ldap = LdapAttr(module) state = module.params['state'] # Perform action if state == 'present': modlist = ldap.add() elif state == 'absent': modlist = ldap.delete() elif state == 'exact': modlist = ldap.exact() changed = False if len(modlist) > 0: changed = True if not module.check_mode: try: ldap.connection.modify_s(ldap.dn, modlist) except Exception as e: module.fail_json(msg="Attribute action failed.", details=to_native(e)) module.exit_json(changed=changed, modlist=modlist)
def main(): module = AnsibleModule( argument_spec=gen_specs( name=dict(type='str', required=True), params=dict(type='dict'), state=dict(type='str', default='present', choices=['absent', 'exact', 'present']), values=dict(type='raw', required=True), ), supports_check_mode=True, ) if not HAS_LDAP: module.fail_json(msg=missing_required_lib('python-ldap'), exception=LDAP_IMP_ERR) # Update module parameters with user's parameters if defined if 'params' in module.params and isinstance(module.params['params'], dict): module.params.update(module.params['params']) # Remove the params module.params.pop('params', None) # Instantiate the LdapAttr object ldap = LdapAttr(module) state = module.params['state'] # Perform action if state == 'present': modlist = ldap.add() elif state == 'absent': modlist = ldap.delete() elif state == 'exact': modlist = ldap.exact() changed = False if len(modlist) > 0: changed = True if not module.check_mode: try: ldap.connection.modify_s(ldap.dn, modlist) except Exception as e: module.fail_json(msg="Attribute action failed.", details=to_native(e)) module.exit_json(changed=changed, modlist=modlist)
def main(): module = AnsibleModule( argument_spec=gen_specs(passwd=dict(no_log=True)), supports_check_mode=True, ) if not HAS_LDAP: module.fail_json(msg=missing_required_lib('python-ldap'), exception=LDAP_IMP_ERR) ldap = LdapPasswd(module) if module.check_mode: module.exit_json(changed=ldap.passwd_check()) module.exit_json(changed=ldap.passwd_set())
def main(): module = AnsibleModule( argument_spec=gen_specs( attributes=dict(default={}, type='dict'), objectClass=dict(type='list', elements='str'), params=dict(type='dict'), state=dict(default='present', choices=['present', 'absent']), ), required_if=[('state', 'present', ['objectClass'])], supports_check_mode=True, ) if not HAS_LDAP: module.fail_json(msg=missing_required_lib('python-ldap'), exception=LDAP_IMP_ERR) if module.params['params']: module.fail_json( msg= "The `params` option to ldap_attr was removed since it circumvents Ansible's option handling" ) state = module.params['state'] # Instantiate the LdapEntry object ldap = LdapEntry(module) # Get the action function if state == 'present': action = ldap.add() elif state == 'absent': action = ldap.delete() # Perform the action if action is not None and not module.check_mode: try: action() except Exception as e: module.fail_json(msg="Entry action failed.", details=to_native(e), exception=traceback.format_exc()) module.exit_json(changed=(action is not None))
def main(): module = AnsibleModule( argument_spec=gen_specs( attributes=dict(type='dict', required=True), ordered=dict(type='bool', default=False, required=False), state=dict(type='str', default='present', choices=['absent', 'exact', 'present']), ), supports_check_mode=True, ) if not HAS_LDAP: module.fail_json(msg=missing_required_lib('python-ldap'), exception=LDAP_IMP_ERR) # Instantiate the LdapAttr object ldap = LdapAttrs(module) state = module.params['state'] # Perform action if state == 'present': modlist = ldap.add() elif state == 'absent': modlist = ldap.delete() elif state == 'exact': modlist = ldap.exact() changed = False if len(modlist) > 0: changed = True if not module.check_mode: try: ldap.connection.modify_s(ldap.dn, modlist) except Exception as e: module.fail_json(msg="Attribute action failed.", details=to_native(e)) module.exit_json(changed=changed, modlist=modlist)