diff --git a/changelogs/fragments/3400-fix-gitLab-api-searches-always-return-first-found-match-3386.yml b/changelogs/fragments/3400-fix-gitLab-api-searches-always-return-first-found-match-3386.yml new file mode 100644 index 0000000000..ab13b4adba --- /dev/null +++ b/changelogs/fragments/3400-fix-gitLab-api-searches-always-return-first-found-match-3386.yml @@ -0,0 +1,2 @@ +bugfixes: + - gitlab_group_members - ``get_group_id`` return the group ID by matching ``full_path``, ``path`` or ``name`` (https://github.com/ansible-collections/community.general/pull/3400). diff --git a/plugins/modules/source_control/gitlab/gitlab_group_members.py b/plugins/modules/source_control/gitlab/gitlab_group_members.py index 50779e6445..0ac5e50041 100644 --- a/plugins/modules/source_control/gitlab/gitlab_group_members.py +++ b/plugins/modules/source_control/gitlab/gitlab_group_members.py @@ -102,9 +102,13 @@ class GitLabGroup(object): # get group id if group exists def get_group_id(self, gitlab_group): - group_exists = self._gitlab.groups.list(search=gitlab_group) - if group_exists: - return group_exists[0].id + groups = self._gitlab.groups.list(search=gitlab_group) + for group in groups: + if group.full_path == gitlab_group: + return group.id + for group in groups: + if group.path == gitlab_group or group.name == gitlab_group: + return group.id # get all members in a group def get_members_in_a_group(self, gitlab_group_id):