Home > Software design >  ansible extrct uid form ldap_search and use to make ldap filter
ansible extrct uid form ldap_search and use to make ldap filter

Time:10-30

hello i obtain this result after an ldpa_search

 {
    "msg": {
        "changed": false,
        "failed": false,
        "results": [
            {    
                "cn": "workagfa",
                "uniquemember": [
                    "uid=gp2513,ou=user,O=agfa,C=com",
                    "uid=as2179,ou=user,O=agfa,C=com",
                    "uid=mh1382,ou=user,O=agfa,C=com",
                     .......

ther is a way to extract only the uid

for example use a regex

uid=([-\d]*[^\;])

and a create a fact like this

((uid=gp2513),(uid=as2179),(uid=mh1382))

this is is used to add a filter to a ldap query

many thanks

CodePudding user response:

you could do something like this:

  tasks:
    - name: something
      : get the extract of ldap
      register: output

    - name: extract uids
      set_fact:
        uids: "{{ uids | default([])   [item.split(',')[0]] }}"
      loop: "{{ ouput.results.0.uniquemember.0 }}"

    - name: display uids
      debug:
        var: uids
  • Related