From 69b58bf00298153e6abeaa2cf7940470acc60770 Mon Sep 17 00:00:00 2001 From: Intellium Date: Thu, 15 Jun 2023 20:51:21 +0200 Subject: [PATCH 1/9] Make most options optional as they should be --- plugins/modules/gitlab_group.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/modules/gitlab_group.py b/plugins/modules/gitlab_group.py index 624028f298c..2a78712f663 100644 --- a/plugins/modules/gitlab_group.py +++ b/plugins/modules/gitlab_group.py @@ -205,11 +205,15 @@ def create_or_update_group(self, name, parent, options): 'name': name, 'path': options['path'], 'parent_id': parent_id, - 'visibility': options['visibility'], - 'project_creation_level': options['project_creation_level'], - 'auto_devops_enabled': options['auto_devops_enabled'], - 'subgroup_creation_level': options['subgroup_creation_level'], } + if options.get('auto_devops_enabled'): + payload['auto_devops_enabled'] = options['auto_devops_enabled'] + if options.get('visibility'): + payload['visibility'] = options['visibility'] + if options.get('project_creation_level'): + payload['project_creation_level'] = options['project_creation_level'] + if options.get('subgroup_creation_level'): + payload['subgroup_creation_level'] = options['subgroup_creation_level'] if options.get('description'): payload['description'] = options['description'] if options.get('require_two_factor_authentication'): From e29136445dbcdb1c70f65fa2fb90ff88e7d3d0c2 Mon Sep 17 00:00:00 2001 From: Intellium Date: Thu, 15 Jun 2023 22:22:55 +0200 Subject: [PATCH 2/9] Add filter to create_group instead --- plugins/modules/gitlab_group.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/modules/gitlab_group.py b/plugins/modules/gitlab_group.py index 2a78712f663..869877ad845 100644 --- a/plugins/modules/gitlab_group.py +++ b/plugins/modules/gitlab_group.py @@ -205,15 +205,11 @@ def create_or_update_group(self, name, parent, options): 'name': name, 'path': options['path'], 'parent_id': parent_id, + 'visibility': options['visibility'], + 'project_creation_level': options['project_creation_level'], + 'auto_devops_enabled': options['auto_devops_enabled'], + 'subgroup_creation_level': options['subgroup_creation_level'], } - if options.get('auto_devops_enabled'): - payload['auto_devops_enabled'] = options['auto_devops_enabled'] - if options.get('visibility'): - payload['visibility'] = options['visibility'] - if options.get('project_creation_level'): - payload['project_creation_level'] = options['project_creation_level'] - if options.get('subgroup_creation_level'): - payload['subgroup_creation_level'] = options['subgroup_creation_level'] if options.get('description'): payload['description'] = options['description'] if options.get('require_two_factor_authentication'): @@ -259,6 +255,11 @@ def create_group(self, arguments): return True try: + # Filter out None values + filtered = {arg_key: arg_value for arg_key, arg_value in arguments.items() if arg_value is not None} + arguments.clear() + arguments.update(filtered) + group = self._gitlab.groups.create(arguments) except (gitlab.exceptions.GitlabCreateError) as e: self._module.fail_json(msg="Failed to create group: %s " % to_native(e)) From 3173e1424efe546c900d471ff3a403daa7eb5d26 Mon Sep 17 00:00:00 2001 From: Intellium Date: Thu, 15 Jun 2023 22:39:48 +0200 Subject: [PATCH 3/9] Remove whitespace --- plugins/modules/gitlab_group.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/gitlab_group.py b/plugins/modules/gitlab_group.py index 869877ad845..aa2ac5558f3 100644 --- a/plugins/modules/gitlab_group.py +++ b/plugins/modules/gitlab_group.py @@ -259,7 +259,7 @@ def create_group(self, arguments): filtered = {arg_key: arg_value for arg_key, arg_value in arguments.items() if arg_value is not None} arguments.clear() arguments.update(filtered) - + group = self._gitlab.groups.create(arguments) except (gitlab.exceptions.GitlabCreateError) as e: self._module.fail_json(msg="Failed to create group: %s " % to_native(e)) From 97e65657a934c862af5289ce1ad4de3b4c33524a Mon Sep 17 00:00:00 2001 From: Intellium Date: Thu, 15 Jun 2023 22:49:59 +0200 Subject: [PATCH 4/9] Add changelog fragment --- changelogs/fragments/6712 | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/6712 diff --git a/changelogs/fragments/6712 b/changelogs/fragments/6712 new file mode 100644 index 00000000000..d66f02eb7d5 --- /dev/null +++ b/changelogs/fragments/6712 @@ -0,0 +1,2 @@ +bugfixes: + - gitlab_group module passed parameters to the API call even when not set. create_group is now filtering out 'None' values to remediate this (https://github.com/ansible-collections/community.general/pull/6712). From 06b09235eba6f625c8392ccdb153f21eb775336a Mon Sep 17 00:00:00 2001 From: Intellium Date: Thu, 15 Jun 2023 22:59:50 +0200 Subject: [PATCH 5/9] Added description and extension to fragment --- .../{6712 => 6712-gitlab_group-filtered-for-none-values.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelogs/fragments/{6712 => 6712-gitlab_group-filtered-for-none-values.yml} (100%) diff --git a/changelogs/fragments/6712 b/changelogs/fragments/6712-gitlab_group-filtered-for-none-values.yml similarity index 100% rename from changelogs/fragments/6712 rename to changelogs/fragments/6712-gitlab_group-filtered-for-none-values.yml From 465408bcf592fdd646e3b65e2d326fb6e865acf0 Mon Sep 17 00:00:00 2001 From: Intellium Date: Fri, 16 Jun 2023 09:27:41 +0200 Subject: [PATCH 6/9] Update changelogs/fragments/6712-gitlab_group-filtered-for-none-values.yml Co-authored-by: Felix Fontein --- .../fragments/6712-gitlab_group-filtered-for-none-values.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/6712-gitlab_group-filtered-for-none-values.yml b/changelogs/fragments/6712-gitlab_group-filtered-for-none-values.yml index d66f02eb7d5..53c02d45887 100644 --- a/changelogs/fragments/6712-gitlab_group-filtered-for-none-values.yml +++ b/changelogs/fragments/6712-gitlab_group-filtered-for-none-values.yml @@ -1,2 +1,2 @@ bugfixes: - - gitlab_group module passed parameters to the API call even when not set. create_group is now filtering out 'None' values to remediate this (https://github.com/ansible-collections/community.general/pull/6712). + - gitlab_group - the module passed parameters to the API call even when not set. The module is now filtering out ``None`` values to remediate this (https://github.com/ansible-collections/community.general/pull/6712). From 6e1cc59c6a560dc685055b3f05fafa99510d8218 Mon Sep 17 00:00:00 2001 From: Intellium Date: Fri, 16 Jun 2023 09:27:56 +0200 Subject: [PATCH 7/9] Update plugins/modules/gitlab_group.py Co-authored-by: Felix Fontein --- plugins/modules/gitlab_group.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/modules/gitlab_group.py b/plugins/modules/gitlab_group.py index aa2ac5558f3..bdca78d928e 100644 --- a/plugins/modules/gitlab_group.py +++ b/plugins/modules/gitlab_group.py @@ -257,10 +257,8 @@ def create_group(self, arguments): try: # Filter out None values filtered = {arg_key: arg_value for arg_key, arg_value in arguments.items() if arg_value is not None} - arguments.clear() - arguments.update(filtered) - group = self._gitlab.groups.create(arguments) + group = self._gitlab.groups.create(filtered) except (gitlab.exceptions.GitlabCreateError) as e: self._module.fail_json(msg="Failed to create group: %s " % to_native(e)) From 2a3602f1c6aa83341d925c071bdf30f7d508d0a8 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 18 Jun 2023 20:42:20 +0200 Subject: [PATCH 8/9] Make Python 2.6 compatible. --- plugins/modules/gitlab_group.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/gitlab_group.py b/plugins/modules/gitlab_group.py index bdca78d928e..177994f7146 100644 --- a/plugins/modules/gitlab_group.py +++ b/plugins/modules/gitlab_group.py @@ -256,7 +256,7 @@ def create_group(self, arguments): try: # Filter out None values - filtered = {arg_key: arg_value for arg_key, arg_value in arguments.items() if arg_value is not None} + filtered = dict(arg_key=arg_value for arg_key, arg_value in arguments.items() if arg_value is not None) group = self._gitlab.groups.create(filtered) except (gitlab.exceptions.GitlabCreateError) as e: From 31105f13fc70883655346b4ec13476ad7440c774 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sun, 18 Jun 2023 20:46:45 +0200 Subject: [PATCH 9/9] Another shot at compatibility. --- plugins/modules/gitlab_group.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/gitlab_group.py b/plugins/modules/gitlab_group.py index 177994f7146..4de1ffc5f0a 100644 --- a/plugins/modules/gitlab_group.py +++ b/plugins/modules/gitlab_group.py @@ -256,7 +256,7 @@ def create_group(self, arguments): try: # Filter out None values - filtered = dict(arg_key=arg_value for arg_key, arg_value in arguments.items() if arg_value is not None) + filtered = dict((arg_key, arg_value) for arg_key, arg_value in arguments.items() if arg_value is not None) group = self._gitlab.groups.create(filtered) except (gitlab.exceptions.GitlabCreateError) as e: