From c7cf6f2eb7b3795d6e9401104b9f7b3cbd46359d Mon Sep 17 00:00:00 2001 From: Stef Graces Date: Sun, 27 Jun 2021 16:09:41 +0200 Subject: [PATCH] gitlab_project - Add ability to create project under a user (#2824) * Add ability to create project under a user * Add changelog * Add username option * Update changelogs/fragments/2824-gitlab_project-project-under-user.yml Co-authored-by: Felix Fontein * Make group and username mutually exclusive Co-authored-by: Felix Fontein --- .../2824-gitlab_project-project-under-user.yml | 3 +++ .../modules/source_control/gitlab/gitlab_project.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/2824-gitlab_project-project-under-user.yml diff --git a/changelogs/fragments/2824-gitlab_project-project-under-user.yml b/changelogs/fragments/2824-gitlab_project-project-under-user.yml new file mode 100644 index 0000000000..7fa18941a0 --- /dev/null +++ b/changelogs/fragments/2824-gitlab_project-project-under-user.yml @@ -0,0 +1,3 @@ +--- +minor_changes: + - gitlab_project - projects can be created under other user's namespaces with the new ``username`` option (https://github.com/ansible-collections/community.general/pull/2824). diff --git a/plugins/modules/source_control/gitlab/gitlab_project.py b/plugins/modules/source_control/gitlab/gitlab_project.py index 61d1ac0cb1..c916246b78 100644 --- a/plugins/modules/source_control/gitlab/gitlab_project.py +++ b/plugins/modules/source_control/gitlab/gitlab_project.py @@ -109,6 +109,11 @@ options: required: false default: false version_added: "2.0.0" + username: + description: + - Used to create a personal project under a user's name. + type: str + version_added: "3.3.0" ''' EXAMPLES = r''' @@ -302,6 +307,7 @@ def main(): import_url=dict(type='str'), state=dict(type='str', default="present", choices=["absent", "present"]), lfs_enabled=dict(default=False, type='bool'), + username=dict(type='str'), )) module = AnsibleModule( @@ -309,6 +315,7 @@ def main(): mutually_exclusive=[ ['api_username', 'api_token'], ['api_password', 'api_token'], + ['group', 'username'], ], required_together=[ ['api_username', 'api_password'], @@ -332,6 +339,7 @@ def main(): import_url = module.params['import_url'] state = module.params['state'] lfs_enabled = module.params['lfs_enabled'] + username = module.params['username'] if not HAS_GITLAB_PACKAGE: module.fail_json(msg=missing_required_lib("python-gitlab"), exception=GITLAB_IMP_ERR) @@ -353,7 +361,10 @@ def main(): namespace_id = group.id else: - namespace = gitlab_instance.namespaces.list(search=gitlab_instance.user.username)[0] + if username: + namespace = gitlab_instance.namespaces.list(search=username)[0] + else: + namespace = gitlab_instance.namespaces.list(search=gitlab_instance.user.username)[0] namespace_id = namespace.id if not namespace_id: