From eac7fa186088bbcb82c1914b124cfb93d9436202 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Thu, 14 Nov 2019 17:21:14 +0530 Subject: [PATCH] gitlab_user: Remove optional parameters while state is absent (#64832) While deleting gitlab user, several parameters such as email, name, password are not required. This fix removes this requirement from the module. Fixes: #61921 Signed-off-by: Abhijeet Kasurde --- changelogs/fragments/61921-gitlab_user.yml | 2 ++ .../rst/porting_guides/porting_guide_2.10.rst | 1 + .../source_control/gitlab/gitlab_user.py | 25 +++++++++++-------- 3 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 changelogs/fragments/61921-gitlab_user.yml diff --git a/changelogs/fragments/61921-gitlab_user.yml b/changelogs/fragments/61921-gitlab_user.yml new file mode 100644 index 00000000000..21b80963452 --- /dev/null +++ b/changelogs/fragments/61921-gitlab_user.yml @@ -0,0 +1,2 @@ +bugfixes: +- While deleting gitlab user, name, email and password is no longer required ini gitlab_user module (https://github.com/ansible/ansible/issues/61921). \ No newline at end of file diff --git a/docs/docsite/rst/porting_guides/porting_guide_2.10.rst b/docs/docsite/rst/porting_guides/porting_guide_2.10.rst index 23dbc176507..fc0bc9ec30b 100644 --- a/docs/docsite/rst/porting_guides/porting_guide_2.10.rst +++ b/docs/docsite/rst/porting_guides/porting_guide_2.10.rst @@ -80,6 +80,7 @@ Noteworthy module changes * The deprecated ``recurse`` option in :ref:`pacman ` module has been removed, you should use ``extra_args=--recursive`` instead. * :ref:`vmware_guest_custom_attributes ` module does not require VM name which was a required parameter for releases prior to Ansible 2.10. * :ref:`zabbix_action ` no longer requires ``esc_period`` and ``event_source`` arguments when ``state=absent``. +* :ref:`gitlab_user ` no longer requires ``name``, ``email`` and ``password`` arguments when ``state=absent``. Plugins ======= diff --git a/lib/ansible/modules/source_control/gitlab/gitlab_user.py b/lib/ansible/modules/source_control/gitlab/gitlab_user.py index f97e0f94a8f..beb13cecf04 100644 --- a/lib/ansible/modules/source_control/gitlab/gitlab_user.py +++ b/lib/ansible/modules/source_control/gitlab/gitlab_user.py @@ -20,6 +20,8 @@ description: - When the user does not exist in GitLab, it will be created. - When the user does exists and state=absent, the user will be deleted. - When changes are made to user, the user will be updated. +notes: + - From Ansible 2.10 and onwards, name, email and password are optional while deleting the user. version_added: "2.1" author: - Werner Dijkerman (@dj-wasabi) @@ -37,8 +39,8 @@ options: type: str name: description: - - Name of the user you want to create - required: true + - Name of the user you want to create. + - Required only if C(state) is set to C(present). type: str username: description: @@ -49,12 +51,12 @@ options: description: - The password of the user. - GitLab server enforces minimum password length to 8, set this value with 8 or more characters. - required: true + - Required only if C(state) is set to C(present). type: str email: description: - The email that belongs to the user. - required: true + - Required only if C(state) is set to C(present). type: str sshkey_name: description: @@ -66,7 +68,7 @@ options: type: str group: description: - - Id or Full path of parent group in the form of group/name + - Id or Full path of parent group in the form of group/name. - Add user as an member to this group. type: str access_level: @@ -96,13 +98,13 @@ options: version_added: "2.4" isadmin: description: - - Grant admin privileges to the user + - Grant admin privileges to the user. type: bool default: no version_added: "2.8" external: description: - - Define external parameter for this user + - Define external parameter for this user. type: bool default: no version_added: "2.8" @@ -397,11 +399,11 @@ def main(): argument_spec = basic_auth_argument_spec() argument_spec.update(dict( api_token=dict(type='str', no_log=True), - name=dict(type='str', required=True), + name=dict(type='str'), state=dict(type='str', default="present", choices=["absent", "present"]), username=dict(type='str', required=True), - password=dict(type='str', required=True, no_log=True), - email=dict(type='str', required=True), + password=dict(type='str', no_log=True), + email=dict(type='str'), sshkey_name=dict(type='str'), sshkey_file=dict(type='str'), group=dict(type='str'), @@ -424,6 +426,9 @@ def main(): ['api_username', 'api_token'] ], supports_check_mode=True, + required_if=( + ('state', 'present', ['name', 'email', 'password']), + ) ) gitlab_url = module.params['api_url']