Repository: ansible-collections/community.general

Issue:
Module gitlab_group_members does fail if more than 20 users are already in member of a group
### Summary

The current implementation fetches the list of members to check if the given user is already member. The call to group.members.list() is done without any arguments so that standard pagination is in order and cuts the returned list which results in wrong evaluation for some users. The resulting create fails due to the user already being in the group.

https://github.com/ansible-collections/community.general/blob/main/plugins/modules/source_control/gitlab/gitlab_group_members.py#L112

Reference GitLab API/Python modul:
https://docs.gitlab.com/ee/api/index.html#pagination
https://python-gitlab.readthedocs.io/en/stable/gl_objects/groups.html#group-members

Secondly to fetch the whole list every time (could be very long) does not perform to good. There is an API function to check if a user is member of a group. The implementation should be changed to this.

I'll do the fix.

### Issue Type

Bug Report

### Component Name

gitlab_group_members

### Ansible Version

any version as it's a bug in the module

### Configuration

not a configuration problem

### OS / Environment

independent

### Steps to Reproduce

- Have more then 20 users as members of a gitlab group
- call the module with each of those users

### Expected Results

The described function of the module

### Actual Results

```console (paste below)

```


### Code of Conduct

- [X] I agree to follow the Ansible Code of Conduct


Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
Same problem for gitlab_project_members
https://github.com/ansible-collections/community.general/blob/main/plugins/modules/source_control/gitlab/gitlab_project_members.py#L133
!component =plugins/modules/source_control/gitlab/gitlab_group_members.py
Files identified in the description:
* [`plugins/modules/source_control/gitlab/gitlab_group_members.py`](https://github.com/ansible-collections/community.general/blob/master/plugins/modules/source_control/gitlab/gitlab_group_members.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @Lunik @Shaps @dj-wasabi @marwatk @metanovii @scodeman @waheedi @zanssa
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/plugins/modules/source_control/gitlab/gitlab_group_members.py b/plugins/modules/source_control/gitlab/gitlab_group_members.py
--- a/plugins/modules/source_control/gitlab/gitlab_group_members.py
+++ b/plugins/modules/source_control/gitlab/gitlab_group_members.py
@@ -109,7 +109,7 @@ def get_group_id(self, gitlab_group):
     # get all members in a group
     def get_members_in_a_group(self, gitlab_group_id):
         group = self._gitlab.groups.get(gitlab_group_id)
-        return group.members.list()
+        return group.members.list(all=True)
 
     # check if the user is a member of the group
     def is_user_a_member(self, members, gitlab_user_id):
diff --git a/plugins/modules/source_control/gitlab/gitlab_project_members.py b/plugins/modules/source_control/gitlab/gitlab_project_members.py
--- a/plugins/modules/source_control/gitlab/gitlab_project_members.py
+++ b/plugins/modules/source_control/gitlab/gitlab_project_members.py
@@ -130,7 +130,7 @@ def get_user_id(self, gitlab_user):
     # get all members in a project
     def get_members_in_a_project(self, gitlab_project_id):
         project = self._gitlab.projects.get(gitlab_project_id)
-        return project.members.list()
+        return project.members.list(all=True)
 
     # check if the user is a member of the project
     def is_user_a_member(self, members, gitlab_user_id):


Test patch: