mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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 <felix@fontein.de> * Make group and username mutually exclusive Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
199ead85d0
commit
c7cf6f2eb7
2 changed files with 15 additions and 1 deletions
|
@ -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).
|
|
@ -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)
|
||||
|
@ -352,6 +360,9 @@ def main():
|
|||
module.fail_json(msg="Failed to create project: group %s doesn't exists" % group_identifier)
|
||||
|
||||
namespace_id = group.id
|
||||
else:
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue