collection 교체

This commit is contained in:
정훈 변
2024-02-23 16:37:40 +09:00
parent b494779b5b
commit 3fd554eee9
38862 changed files with 220204 additions and 6600073 deletions

View File

@@ -1,11 +1,12 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2019, Guillaume Martinez (lunik@tiwabbit.fr)
# Copyright: (c) 2018, Marcus Watkins <marwatk@marcuswatkins.net>
# Copyright (c) 2019, Guillaume Martinez (lunik@tiwabbit.fr)
# Copyright (c) 2018, Marcus Watkins <marwatk@marcuswatkins.net>
# Based on code:
# Copyright: (c) 2013, Phillip Gentry <phillip@cx.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Copyright (c) 2013, Phillip Gentry <phillip@cx.com>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import absolute_import, division, print_function
__metaclass__ = type
@@ -13,18 +14,24 @@ __metaclass__ = type
DOCUMENTATION = '''
---
module: gitlab_hook
short_description: Manages GitLab project hooks.
short_description: Manages GitLab project hooks
description:
- Adds, updates and removes project hook
author:
- Marcus Watkins (@marwatk)
- Guillaume Martinez (@Lunik)
requirements:
- python >= 2.7
- python-gitlab python module
extends_documentation_fragment:
- community.general.auth_basic
- community.general.gitlab
- community.general.attributes
attributes:
check_mode:
support: full
diff_mode:
support: none
options:
project:
@@ -39,8 +46,8 @@ options:
type: str
state:
description:
- When C(present) the hook will be updated to match the input or created if it doesn't exist.
- When C(absent) hook will be deleted if it exists.
- When V(present) the hook will be updated to match the input or created if it doesn't exist.
- When V(absent) hook will be deleted if it exists.
default: present
type: str
choices: [ "present", "absent" ]
@@ -48,52 +55,53 @@ options:
description:
- Trigger hook on push events.
type: bool
default: yes
default: true
push_events_branch_filter:
description:
- Branch name of wildcard to trigger hook on push events
type: str
version_added: '0.2.0'
default: ''
issues_events:
description:
- Trigger hook on issues events.
type: bool
default: no
default: false
merge_requests_events:
description:
- Trigger hook on merge requests events.
type: bool
default: no
default: false
tag_push_events:
description:
- Trigger hook on tag push events.
type: bool
default: no
default: false
note_events:
description:
- Trigger hook on note events or when someone adds a comment.
type: bool
default: no
default: false
job_events:
description:
- Trigger hook on job events.
type: bool
default: no
default: false
pipeline_events:
description:
- Trigger hook on pipeline events.
type: bool
default: no
default: false
wiki_page_events:
description:
- Trigger hook on wiki events.
type: bool
default: no
default: false
hook_validate_certs:
description:
- Whether GitLab will do SSL verification when triggering the hook.
type: bool
default: no
default: false
aliases: [ enable_ssl_verification ]
token:
description:
@@ -112,9 +120,8 @@ EXAMPLES = '''
project: "my_group/my_project"
hook_url: "https://my-ci-server.example.com/gitlab-hook"
state: present
push_events: yes
tag_push_events: yes
hook_validate_certs: no
push_events: true
tag_push_events: true
token: "my-super-secret-token-that-my-ci-server-will-check"
- name: "Delete the previous hook"
@@ -158,22 +165,12 @@ hook:
type: dict
'''
import re
import traceback
GITLAB_IMP_ERR = None
try:
import gitlab
HAS_GITLAB_PACKAGE = True
except Exception:
GITLAB_IMP_ERR = traceback.format_exc()
HAS_GITLAB_PACKAGE = False
from ansible.module_utils.api import basic_auth_argument_spec
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.common.text.converters import to_native
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils.gitlab import auth_argument_spec, find_project, gitlab_authentication
from ansible_collections.community.general.plugins.module_utils.gitlab import (
auth_argument_spec, find_project, gitlab_authentication
)
class GitLabHook(object):
@@ -232,9 +229,8 @@ class GitLabHook(object):
hook.save()
except Exception as e:
self._module.fail_json(msg="Failed to update hook: %s " % e)
return True
else:
return False
return changed
'''
@param project Project Object
@@ -256,9 +252,9 @@ class GitLabHook(object):
changed = False
for arg_key, arg_value in arguments.items():
if arguments[arg_key] is not None:
if getattr(hook, arg_key) != arguments[arg_key]:
setattr(hook, arg_key, arguments[arg_key])
if arg_value is not None:
if getattr(hook, arg_key, None) != arg_value:
setattr(hook, arg_key, arg_value)
changed = True
return (changed, hook)
@@ -286,10 +282,8 @@ class GitLabHook(object):
return False
def delete_hook(self):
if self._module.check_mode:
return True
return self.hook_object.delete()
if not self._module.check_mode:
self.hook_object.delete()
def main():
@@ -330,6 +324,9 @@ def main():
supports_check_mode=True,
)
# check prerequisites and connect to gitlab server
gitlab_instance = gitlab_authentication(module)
state = module.params['state']
project_identifier = module.params['project']
hook_url = module.params['hook_url']
@@ -345,11 +342,6 @@ def main():
enable_ssl_verification = module.params['hook_validate_certs']
hook_token = module.params['token']
if not HAS_GITLAB_PACKAGE:
module.fail_json(msg=missing_required_lib("python-gitlab"), exception=GITLAB_IMP_ERR)
gitlab_instance = gitlab_authentication(module)
gitlab_hook = GitLabHook(module, gitlab_instance)
project = find_project(gitlab_instance, project_identifier)