Coder Social home page Coder Social logo

Using microsoft.ad.group to set members of a group does not work when both groups are in different OUs about microsoft.ad HOT 2 CLOSED

ansible-collections avatar ansible-collections commented on September 3, 2024
Using microsoft.ad.group to set members of a group does not work when both groups are in different OUs

from microsoft.ad.

Comments (2)

jborean93 avatar jborean93 commented on September 3, 2024

Looks like the problem isn't the OU but the length of the group name. The lookup code has a check to see if the input value is between 1-20 characters and if so search by sAMAccountName

elseif ($Identity -match '^(?:[^:*?""<>|\/\\]+\\)?(?<username>[^;:""<>|?,=\*\+\\\(\)]{1,20})$') {
$getParams.LDAPFilter = "(sAMAccountName=$($Matches.username))"
}

As TEST-MS-SQL-Server-abc-Administratoren exceeds 20 characters it's just going to try and find it by DistinguishedName which won't work. The following is a quick reproducer:

- hosts: ...
  gather_facts: false

  tasks:
  - block:
    - name: create OU1
      microsoft.ad.ou:
        name: OU1
        state: present
      register: ou1

    - name: create OU2
      microsoft.ad.ou:
        name: OU2
        state: present
      register: ou2

    - name: create Group1
      microsoft.ad.group:
        name: Group1
        path: '{{ ou1.distinguished_name }}'
        scope: domainlocal
      register: group1

    - name: create Group2
      microsoft.ad.group:
        name: Group2-ReallyLongGroupNameHere
        path: '{{ ou2.distinguished_name }}'
        scope: domainlocal

    - name: add Group2 to Group1
      microsoft.ad.group:
        identity: Group1
        members:
          set:
          - Group2-ReallyLongGroupNameHere

    - name: get group membership
      microsoft.ad.object_info:
        identity: '{{ group1.object_guid }}'
        properties: member

    always:
    - name: remove example OUs
      microsoft.ad.ou:
        name: '{{ item }}'
        state: absent
      loop:
      - OU1
      - OU2

When I change the regex from {1,20} to just + then the example above works. This is interesting because the docs for the sAMAccountName attribute states the maximum length is 20 characters but either that's out of date or just wrong. I'll have a play around and see what the next steps forward should be.

As a workaround you can use the distinguishedName, securityIdentifier, objectGuid, or userPrincipalName of the group in the yaml definition.

from microsoft.ad.

jborean93 avatar jborean93 commented on September 3, 2024

This has been fixed with #95

from microsoft.ad.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.