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,10 +1,11 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright: (c) 2021, Lennert Mertens (lennert@nubera.be)
# Copyright: (c) 2019, Guillaume Martinez (lunik@tiwabbit.fr)
# Copyright: (c) 2015, Werner Dijkerman (ikben@werner-dijkerman.nl)
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Copyright (c) 2021, Lennert Mertens (lennert@nubera.be)
# Copyright (c) 2019, Guillaume Martinez (lunik@tiwabbit.fr)
# Copyright (c) 2015, Werner Dijkerman (ikben@werner-dijkerman.nl)
# 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
@@ -26,18 +27,24 @@ author:
- Lennert Mertens (@LennertMertens)
- Stef Graces (@stgrace)
requirements:
- python >= 2.7
- python-gitlab python module
- administrator rights on the GitLab server
extends_documentation_fragment:
- community.general.auth_basic
- community.general.gitlab
- community.general.attributes
attributes:
check_mode:
support: full
diff_mode:
support: none
options:
name:
description:
- Name of the user you want to create.
- Required only if C(state) is set to C(present).
- Required only if O(state=present).
type: str
username:
description:
@@ -58,7 +65,7 @@ options:
email:
description:
- The email that belongs to the user.
- Required only if C(state) is set to C(present).
- Required only if O(state=present).
type: str
sshkey_name:
description:
@@ -101,21 +108,21 @@ options:
description:
- Require confirmation.
type: bool
default: yes
default: true
isadmin:
description:
- Grant admin privileges to the user.
type: bool
default: no
default: false
external:
description:
- Define external parameter for this user.
type: bool
default: no
default: false
identities:
description:
- List of identities to be added/updated for this user.
- To remove all other identities from this user, set I(overwrite_identities=true).
- To remove all other identities from this user, set O(overwrite_identities=true).
type: list
elements: dict
suboptions:
@@ -131,8 +138,8 @@ options:
overwrite_identities:
description:
- Overwrite identities with identities added in this module.
- This means that all identities that the user has and that are not listed in I(identities) are removed from the user.
- This is only done if a list is provided for I(identities). To remove all identities, provide an empty list.
- This means that all identities that the user has and that are not listed in O(identities) are removed from the user.
- This is only done if a list is provided for O(identities). To remove all identities, provide an empty list.
type: bool
default: false
version_added: 3.3.0
@@ -143,14 +150,13 @@ EXAMPLES = '''
community.general.gitlab_user:
api_url: https://gitlab.example.com/
api_token: "{{ access_token }}"
validate_certs: False
username: myusername
state: absent
- name: "Create GitLab User"
community.general.gitlab_user:
api_url: https://gitlab.example.com/
validate_certs: True
validate_certs: true
api_username: dj-wasabi
api_password: "MySecretPassword"
name: My Name
@@ -166,7 +172,7 @@ EXAMPLES = '''
- name: "Create GitLab User using external identity provider"
community.general.gitlab_user:
api_url: https://gitlab.example.com/
validate_certs: True
validate_certs: true
api_token: "{{ access_token }}"
name: My Name
username: myusername
@@ -183,7 +189,6 @@ EXAMPLES = '''
community.general.gitlab_user:
api_url: https://gitlab.example.com/
api_token: "{{ access_token }}"
validate_certs: False
username: myusername
state: blocked
@@ -191,7 +196,6 @@ EXAMPLES = '''
community.general.gitlab_user:
api_url: https://gitlab.example.com/
api_token: "{{ access_token }}"
validate_certs: False
username: myusername
state: unblocked
'''
@@ -220,21 +224,14 @@ user:
type: dict
'''
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.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
from ansible_collections.community.general.plugins.module_utils.gitlab import auth_argument_spec, find_group, gitlab_authentication
from ansible_collections.community.general.plugins.module_utils.gitlab import (
auth_argument_spec, find_group, gitlab_authentication, gitlab
)
class GitLabUser(object):
@@ -243,12 +240,12 @@ class GitLabUser(object):
self._gitlab = gitlab_instance
self.user_object = None
self.ACCESS_LEVEL = {
'guest': gitlab.GUEST_ACCESS,
'reporter': gitlab.REPORTER_ACCESS,
'developer': gitlab.DEVELOPER_ACCESS,
'master': gitlab.MAINTAINER_ACCESS,
'maintainer': gitlab.MAINTAINER_ACCESS,
'owner': gitlab.OWNER_ACCESS,
'guest': gitlab.const.GUEST_ACCESS,
'reporter': gitlab.const.REPORTER_ACCESS,
'developer': gitlab.const.DEVELOPER_ACCESS,
'master': gitlab.const.MAINTAINER_ACCESS,
'maintainer': gitlab.const.MAINTAINER_ACCESS,
'owner': gitlab.const.OWNER_ACCESS,
}
'''
@@ -305,7 +302,7 @@ class GitLabUser(object):
# note: as we unfortunately have some uncheckable parameters
# where it is not possible to determine if the update
# changed something or not, we must assume here that a
# changed happend and that an user object update is needed
# changed happened and that an user object update is needed
potentionally_changed = True
# Assign ssh keys
@@ -484,7 +481,7 @@ class GitLabUser(object):
'''
@param user User object
@param identites List of identities to be added/updated
@param identities List of identities to be added/updated
@param overwrite_identities Overwrite user identities with identities passed to this module
'''
def add_identities(self, user, identities, overwrite_identities=False):
@@ -503,7 +500,7 @@ class GitLabUser(object):
'''
@param user User object
@param identites List of identities to be added/updated
@param identities List of identities to be added/updated
'''
def delete_identities(self, user, identities):
changed = False
@@ -616,6 +613,9 @@ def main():
)
)
# check prerequisites and connect to gitlab server
gitlab_instance = gitlab_authentication(module)
user_name = module.params['name']
state = module.params['state']
user_username = module.params['username'].lower()
@@ -633,11 +633,6 @@ def main():
user_identities = module.params['identities']
overwrite_identities = module.params['overwrite_identities']
if not HAS_GITLAB_PACKAGE:
module.fail_json(msg=missing_required_lib("python-gitlab"), exception=GITLAB_IMP_ERR)
gitlab_instance = gitlab_authentication(module)
gitlab_user = GitLabUser(module, gitlab_instance)
user_exists = gitlab_user.exists_user(user_username)
if user_exists: