Return List of Users with LDAP Query

Hi All,

I’m trying to use Ansible to query my Domain Controller to return a list of users with a specific set of criteria and then modify those returned users to add them to a group.

How this looks in practice is that I want Ansible to return a list of users based on this query:

(&(objectClass=User)(extensionAttribute10=AttribPresent)(!(memberOf=CN=MyGroup,OU=MyOU2,OU=MyOU,DC=Domain)))

This returns a list of users that I want to loop over and add to a group in AD: DaveGroup.

So far I can’t seem to find a way to do this, other than with PowerShell maybe?

Any help would be amazing!

Thanks

Take a look at the ldapsearch lookup plugin:

https://docs.ansible.com/ansible/latest/collections/community/general/ldap_search_module.html