[PR #5667/c3bc172b backport][stable-5] respect new variable property in gitlab_group_variable and gitlab_project_variable (#5678)

respect new variable property in gitlab_group_variable and gitlab_project_variable (#5667)

* draft

* add changelog fragment

* rework

* rework group variables

* add new line at end of file

* Update plugins/module_utils/gitlab.py

Co-authored-by: Nejc Habjan <hab.nejc@gmail.com>

* rename

* revert

* return a copy

* Update plugins/modules/gitlab_project_variable.py

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Nejc Habjan <hab.nejc@gmail.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit c3bc172bf6)

Co-authored-by: Markus Bergholz <git@osuv.de>
This commit is contained in:
patchback[bot] 2022-12-10 22:42:16 +01:00 committed by GitHub
parent 77aabcd8f5
commit 14f23fbebe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 22 deletions

View file

@ -189,7 +189,7 @@ except Exception:
HAS_GITLAB_PACKAGE = False
from ansible_collections.community.general.plugins.module_utils.gitlab import (
auth_argument_spec, gitlab_authentication, ensure_gitlab_package
auth_argument_spec, gitlab_authentication, ensure_gitlab_package, filter_returned_variables
)
@ -255,9 +255,11 @@ class GitlabProjectVariables(object):
return True
var = {
"key": var_obj.get('key'), "value": var_obj.get('value'),
"masked": var_obj.get('masked'), "protected": var_obj.get('protected'),
"variable_type": var_obj.get('variable_type')
"key": var_obj.get('key'),
"value": var_obj.get('value'),
"masked": var_obj.get('masked'),
"protected": var_obj.get('protected'),
"variable_type": var_obj.get('variable_type'),
}
if var_obj.get('environment_scope') is not None:
@ -319,12 +321,9 @@ def native_python_main(this_gitlab, purge, requested_variables, state, module):
before = [x.attributes for x in gitlab_keys]
gitlab_keys = this_gitlab.list_all_project_variables()
existing_variables = [x.attributes for x in gitlab_keys]
# preprocessing:filter out and enrich before compare
for item in existing_variables:
item.pop('project_id')
existing_variables = filter_returned_variables(gitlab_keys)
# filter out and enrich before compare
for item in requested_variables:
item['key'] = item.pop('name')
item['value'] = str(item.get('value'))
@ -354,9 +353,7 @@ def native_python_main(this_gitlab, purge, requested_variables, state, module):
if purge:
# refetch and filter
gitlab_keys = this_gitlab.list_all_project_variables()
existing_variables = [x.attributes for x in gitlab_keys]
for item in existing_variables:
item.pop('project_id')
existing_variables = filter_returned_variables(gitlab_keys)
remove = [x for x in existing_variables if x not in requested_variables]
for item in remove:
@ -409,7 +406,7 @@ def main():
masked=dict(type='bool', default=False),
protected=dict(type='bool', default=False),
environment_scope=dict(type='str', default='*'),
variable_type=dict(type='str', default='env_var', choices=["env_var", "file"])
variable_type=dict(type='str', default='env_var', choices=["env_var", "file"]),
)),
state=dict(type='str', default="present", choices=["absent", "present"]),
)