quinot / ansible-plugin-lookup_ldap

Ansible LDAP lookup plugin
50 stars 16 forks source link

Allow automatic expansion of list terms #17

Closed Petraea closed 6 years ago

Petraea commented 6 years ago

Hi there,

There's a mild oversight in this plugin. If you want to pass in a list of terms from e.g. a variable, then you'd do so like so:

vars: users:

However, without this PR the ldap function will simply flatten the users list into a string, and attempt to lookup like so:

LDAP search, expanded: {u'binddn': u'abind@mysite', 'context': {u'binddn': u'abind@mysite', u'key': u'cn', u'url': u'ldaps://myldap', u'value': u'mail', u'filter': u"(cn=[u'usera', u'userb'])", u'base': u'DC=my,DC=site', u'bindpw': u'apwd', 'context': {u'url': u'ldaps://myldap', u'binddn': u'abind@mysite', u'base': u'DC=my,DC=site', u'bindpw': u'apwd'}}, u'url': u'ldaps://myldap', u'value': u'mail', 'filter': u"(cn=[u'usera', u'userb'])", 'base': u'DC=my,DC=site', u'bindpw': u'apwd', 'wantlist': True, u'key': u'cn', 'scope': 'subtree'}

This PR pulls in any list terms into the main terms list, allowing full iteration.

quinot commented 6 years ago

Adding such flattenning would be an incompatible change. This is now supported instead using an explicit "terms:" parameter accepting a list of terms. In your example this would be:

with_ldap:
  - context: my_ctx
  - terms: "{{ users }}"