diff --git a/changelogs/fragments/2881-gitlab_project-fix_workspace_user.yaml b/changelogs/fragments/2881-gitlab_project-fix_workspace_user.yaml new file mode 100644 index 0000000000..0de8368b7f --- /dev/null +++ b/changelogs/fragments/2881-gitlab_project-fix_workspace_user.yaml @@ -0,0 +1,3 @@ +--- +bugfixes: + - gitlab_project - user projects are created using namespace ID now, instead of user ID (https://github.com/ansible-collections/community.general/pull/2881). diff --git a/plugins/modules/source_control/gitlab/gitlab_project.py b/plugins/modules/source_control/gitlab/gitlab_project.py index 73def710c3..61d1ac0cb1 100644 --- a/plugins/modules/source_control/gitlab/gitlab_project.py +++ b/plugins/modules/source_control/gitlab/gitlab_project.py @@ -345,22 +345,22 @@ def main(): gitlab_project = GitLabProject(module, gitlab_instance) namespace = None - user_group_id = None + namespace_id = None if group_identifier: group = findGroup(gitlab_instance, group_identifier) if group is None: module.fail_json(msg="Failed to create project: group %s doesn't exists" % group_identifier) - user_group_id = group.id + namespace_id = group.id else: - user = gitlab_instance.users.list(username=gitlab_instance.user.username)[0] - user_group_id = user.id + namespace = gitlab_instance.namespaces.list(search=gitlab_instance.user.username)[0] + namespace_id = namespace.id - if not user_group_id: - module.fail_json(msg="Failed to find the user/group id which required to find namespace") + if not namespace_id: + module.fail_json(msg="Failed to find the namespace or group ID which is required to look up the namespace") try: - namespace = gitlab_instance.namespaces.get(user_group_id) + namespace = gitlab_instance.namespaces.get(namespace_id) except gitlab.exceptions.GitlabGetError as e: module.fail_json(msg="Failed to find the namespace for the given user: %s" % to_native(e))