mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
gitlab_project: Add a parameter to specify Git LFS (#1540)
* Update docs * Update example * Refactor code * Add a parameter ``lfs_enabled`` to specify Git Large file systems Fixes: #1506 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
c63f3f9956
commit
da2a629919
2 changed files with 63 additions and 40 deletions
2
changelogs/fragments/1506_gitlab_project.yml
Normal file
2
changelogs/fragments/1506_gitlab_project.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- gitlab_project - add parameter ``lfs_enabled`` to specify Git LFS (https://github.com/ansible-collections/community.general/issues/1506).
|
|
@ -14,7 +14,7 @@ module: gitlab_project
|
||||||
short_description: Creates/updates/deletes GitLab Projects
|
short_description: Creates/updates/deletes GitLab Projects
|
||||||
description:
|
description:
|
||||||
- When the project does not exist in GitLab, it will be created.
|
- When the project does not exist in GitLab, it will be created.
|
||||||
- When the project does exists and state=absent, the project will be deleted.
|
- When the project does exists and I(state=absent), the project will be deleted.
|
||||||
- When changes are made to the project, the project will be updated.
|
- When changes are made to the project, the project will be updated.
|
||||||
author:
|
author:
|
||||||
- Werner Dijkerman (@dj-wasabi)
|
- Werner Dijkerman (@dj-wasabi)
|
||||||
|
@ -32,11 +32,11 @@ options:
|
||||||
type: str
|
type: str
|
||||||
group:
|
group:
|
||||||
description:
|
description:
|
||||||
- Id or The full path of the group of which this projects belongs to.
|
- Id or the full path of the group of which this projects belongs to.
|
||||||
type: str
|
type: str
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- The name of the project
|
- The name of the project.
|
||||||
required: true
|
required: true
|
||||||
type: str
|
type: str
|
||||||
path:
|
path:
|
||||||
|
@ -63,20 +63,18 @@ options:
|
||||||
wiki_enabled:
|
wiki_enabled:
|
||||||
description:
|
description:
|
||||||
- If an wiki for this project should be available or not.
|
- If an wiki for this project should be available or not.
|
||||||
- Possible values are true and false.
|
|
||||||
type: bool
|
type: bool
|
||||||
default: yes
|
default: yes
|
||||||
snippets_enabled:
|
snippets_enabled:
|
||||||
description:
|
description:
|
||||||
- If creating snippets should be available or not.
|
- If creating snippets should be available or not.
|
||||||
- Possible values are true and false.
|
|
||||||
type: bool
|
type: bool
|
||||||
default: yes
|
default: yes
|
||||||
visibility:
|
visibility:
|
||||||
description:
|
description:
|
||||||
- Private. Project access must be granted explicitly for each user.
|
- C(private) Project access must be granted explicitly for each user.
|
||||||
- Internal. The project can be cloned by any logged in user.
|
- C(internal) The project can be cloned by any logged in user.
|
||||||
- Public. The project can be cloned without any authentication.
|
- C(public) The project can be cloned without any authentication.
|
||||||
default: private
|
default: private
|
||||||
type: str
|
type: str
|
||||||
choices: ["private", "internal", "public"]
|
choices: ["private", "internal", "public"]
|
||||||
|
@ -90,7 +88,7 @@ options:
|
||||||
type: str
|
type: str
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- create or delete project.
|
- Create or delete project.
|
||||||
- Possible values are present and absent.
|
- Possible values are present and absent.
|
||||||
default: present
|
default: present
|
||||||
type: str
|
type: str
|
||||||
|
@ -103,9 +101,24 @@ options:
|
||||||
choices: ["ff", "merge", "rebase_merge"]
|
choices: ["ff", "merge", "rebase_merge"]
|
||||||
default: merge
|
default: merge
|
||||||
version_added: "1.0.0"
|
version_added: "1.0.0"
|
||||||
|
lfs_enabled:
|
||||||
|
description:
|
||||||
|
- Enable Git large file systems to manages large files such
|
||||||
|
as audio, video, and graphics files.
|
||||||
|
type: bool
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
version_added: "2.0.0"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
|
- name: Create GitLab Project
|
||||||
|
community.general.gitlab_project:
|
||||||
|
api_url: https://gitlab.example.com/
|
||||||
|
api_token: "{{ api_token }}"
|
||||||
|
name: my_first_project
|
||||||
|
group: "10481470"
|
||||||
|
|
||||||
- name: Delete GitLab Project
|
- name: Delete GitLab Project
|
||||||
community.general.gitlab_project:
|
community.general.gitlab_project:
|
||||||
api_url: https://gitlab.example.com/
|
api_url: https://gitlab.example.com/
|
||||||
|
@ -186,31 +199,27 @@ class GitLabProject(object):
|
||||||
'''
|
'''
|
||||||
def createOrUpdateProject(self, project_name, namespace, options):
|
def createOrUpdateProject(self, project_name, namespace, options):
|
||||||
changed = False
|
changed = False
|
||||||
|
project_options = {
|
||||||
|
'name': project_name,
|
||||||
|
'description': options['description'],
|
||||||
|
'issues_enabled': options['issues_enabled'],
|
||||||
|
'merge_requests_enabled': options['merge_requests_enabled'],
|
||||||
|
'merge_method': options['merge_method'],
|
||||||
|
'wiki_enabled': options['wiki_enabled'],
|
||||||
|
'snippets_enabled': options['snippets_enabled'],
|
||||||
|
'visibility': options['visibility'],
|
||||||
|
'lfs_enabled': options['lfs_enabled'],
|
||||||
|
}
|
||||||
# Because we have already call userExists in main()
|
# Because we have already call userExists in main()
|
||||||
if self.projectObject is None:
|
if self.projectObject is None:
|
||||||
project = self.createProject(namespace, {
|
project_options.update({
|
||||||
'name': project_name,
|
|
||||||
'path': options['path'],
|
'path': options['path'],
|
||||||
'description': options['description'],
|
'import_url': options['import_url'],
|
||||||
'issues_enabled': options['issues_enabled'],
|
})
|
||||||
'merge_requests_enabled': options['merge_requests_enabled'],
|
project = self.createProject(namespace, project_options)
|
||||||
'merge_method': options['merge_method'],
|
|
||||||
'wiki_enabled': options['wiki_enabled'],
|
|
||||||
'snippets_enabled': options['snippets_enabled'],
|
|
||||||
'visibility': options['visibility'],
|
|
||||||
'import_url': options['import_url']})
|
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
changed, project = self.updateProject(self.projectObject, {
|
changed, project = self.updateProject(self.projectObject, project_options)
|
||||||
'name': project_name,
|
|
||||||
'description': options['description'],
|
|
||||||
'issues_enabled': options['issues_enabled'],
|
|
||||||
'merge_requests_enabled': options['merge_requests_enabled'],
|
|
||||||
'merge_method': options['merge_method'],
|
|
||||||
'wiki_enabled': options['wiki_enabled'],
|
|
||||||
'snippets_enabled': options['snippets_enabled'],
|
|
||||||
'visibility': options['visibility']})
|
|
||||||
|
|
||||||
self.projectObject = project
|
self.projectObject = project
|
||||||
if changed:
|
if changed:
|
||||||
|
@ -222,8 +231,7 @@ class GitLabProject(object):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._module.fail_json(msg="Failed update project: %s " % e)
|
self._module.fail_json(msg="Failed update project: %s " % e)
|
||||||
return True
|
return True
|
||||||
else:
|
return False
|
||||||
return False
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@param namespace Namespace Object (User or Group)
|
@param namespace Namespace Object (User or Group)
|
||||||
|
@ -293,6 +301,7 @@ def main():
|
||||||
visibility=dict(type='str', default="private", choices=["internal", "private", "public"], aliases=["visibility_level"]),
|
visibility=dict(type='str', default="private", choices=["internal", "private", "public"], aliases=["visibility_level"]),
|
||||||
import_url=dict(type='str'),
|
import_url=dict(type='str'),
|
||||||
state=dict(type='str', default="present", choices=["absent", "present"]),
|
state=dict(type='str', default="present", choices=["absent", "present"]),
|
||||||
|
lfs_enabled=dict(default=False, type='bool'),
|
||||||
))
|
))
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
@ -322,6 +331,7 @@ def main():
|
||||||
visibility = module.params['visibility']
|
visibility = module.params['visibility']
|
||||||
import_url = module.params['import_url']
|
import_url = module.params['import_url']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
|
lfs_enabled = module.params['lfs_enabled']
|
||||||
|
|
||||||
if not HAS_GITLAB_PACKAGE:
|
if not HAS_GITLAB_PACKAGE:
|
||||||
module.fail_json(msg=missing_required_lib("python-gitlab"), exception=GITLAB_IMP_ERR)
|
module.fail_json(msg=missing_required_lib("python-gitlab"), exception=GITLAB_IMP_ERR)
|
||||||
|
@ -334,24 +344,35 @@ def main():
|
||||||
|
|
||||||
gitlab_project = GitLabProject(module, gitlab_instance)
|
gitlab_project = GitLabProject(module, gitlab_instance)
|
||||||
|
|
||||||
|
namespace = None
|
||||||
|
user_group_id = None
|
||||||
if group_identifier:
|
if group_identifier:
|
||||||
group = findGroup(gitlab_instance, group_identifier)
|
group = findGroup(gitlab_instance, group_identifier)
|
||||||
if group is None:
|
if group is None:
|
||||||
module.fail_json(msg="Failed to create project: group %s doesn't exists" % group_identifier)
|
module.fail_json(msg="Failed to create project: group %s doesn't exists" % group_identifier)
|
||||||
|
|
||||||
namespace = gitlab_instance.namespaces.get(group.id)
|
user_group_id = group.id
|
||||||
project_exists = gitlab_project.existsProject(namespace, project_path)
|
|
||||||
else:
|
else:
|
||||||
user = gitlab_instance.users.list(username=gitlab_instance.user.username)[0]
|
user = gitlab_instance.users.list(username=gitlab_instance.user.username)[0]
|
||||||
namespace = gitlab_instance.namespaces.get(user.id)
|
user_group_id = user.id
|
||||||
project_exists = gitlab_project.existsProject(namespace, project_path)
|
|
||||||
|
if not user_group_id:
|
||||||
|
module.fail_json(msg="Failed to find the user/group id which required to find namespace")
|
||||||
|
|
||||||
|
try:
|
||||||
|
namespace = gitlab_instance.namespaces.get(user_group_id)
|
||||||
|
except gitlab.exceptions.GitlabGetError as e:
|
||||||
|
module.fail_json(msg="Failed to find the namespace for the given user: %s" % to_native(e))
|
||||||
|
|
||||||
|
if not namespace:
|
||||||
|
module.fail_json(msg="Failed to find the namespace for the project")
|
||||||
|
project_exists = gitlab_project.existsProject(namespace, project_path)
|
||||||
|
|
||||||
if state == 'absent':
|
if state == 'absent':
|
||||||
if project_exists:
|
if project_exists:
|
||||||
gitlab_project.deleteProject()
|
gitlab_project.deleteProject()
|
||||||
module.exit_json(changed=True, msg="Successfully deleted project %s" % project_name)
|
module.exit_json(changed=True, msg="Successfully deleted project %s" % project_name)
|
||||||
else:
|
module.exit_json(changed=False, msg="Project deleted or does not exists")
|
||||||
module.exit_json(changed=False, msg="Project deleted or does not exists")
|
|
||||||
|
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
if gitlab_project.createOrUpdateProject(project_name, namespace, {
|
if gitlab_project.createOrUpdateProject(project_name, namespace, {
|
||||||
|
@ -363,11 +384,11 @@ def main():
|
||||||
"wiki_enabled": wiki_enabled,
|
"wiki_enabled": wiki_enabled,
|
||||||
"snippets_enabled": snippets_enabled,
|
"snippets_enabled": snippets_enabled,
|
||||||
"visibility": visibility,
|
"visibility": visibility,
|
||||||
"import_url": import_url}):
|
"import_url": import_url,
|
||||||
|
"lfs_enabled": lfs_enabled}):
|
||||||
|
|
||||||
module.exit_json(changed=True, msg="Successfully created or updated the project %s" % project_name, project=gitlab_project.projectObject._attrs)
|
module.exit_json(changed=True, msg="Successfully created or updated the project %s" % project_name, project=gitlab_project.projectObject._attrs)
|
||||||
else:
|
module.exit_json(changed=False, msg="No need to update the project %s" % project_name, project=gitlab_project.projectObject._attrs)
|
||||||
module.exit_json(changed=False, msg="No need to update the project %s" % project_name, project=gitlab_project.projectObject._attrs)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue