mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-18 16:31:26 -07:00
gitlab modules: minor refactor (#6384)
* gitlab modules: minor refactor * add changelog frag * Update plugins/module_utils/gitlab.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/module_utils/gitlab.py Co-authored-by: Felix Fontein <felix@fontein.de> * update changelog frag * remove extraneous bracket --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
165182cdbf
commit
febe7a2fb4
4 changed files with 43 additions and 85 deletions
|
@ -166,52 +166,11 @@ group_variable:
|
|||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.api import basic_auth_argument_spec
|
||||
from ansible.module_utils.six import string_types
|
||||
from ansible.module_utils.six import integer_types
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.gitlab import (
|
||||
auth_argument_spec, gitlab_authentication, ensure_gitlab_package, filter_returned_variables
|
||||
auth_argument_spec, gitlab_authentication, ensure_gitlab_package, filter_returned_variables, vars_to_variables
|
||||
)
|
||||
|
||||
|
||||
def vars_to_variables(vars, module):
|
||||
# transform old vars to new variables structure
|
||||
variables = list()
|
||||
for item, value in vars.items():
|
||||
if (isinstance(value, string_types) or
|
||||
isinstance(value, (integer_types, float))):
|
||||
variables.append(
|
||||
{
|
||||
"name": item,
|
||||
"value": str(value),
|
||||
"masked": False,
|
||||
"protected": False,
|
||||
"variable_type": "env_var",
|
||||
}
|
||||
)
|
||||
|
||||
elif isinstance(value, dict):
|
||||
new_item = {"name": item, "value": value.get('value')}
|
||||
|
||||
new_item = {
|
||||
"name": item,
|
||||
"value": value.get('value'),
|
||||
"masked": value.get('masked'),
|
||||
"protected": value.get('protected'),
|
||||
"variable_type": value.get('variable_type'),
|
||||
}
|
||||
|
||||
if value.get('environment_scope'):
|
||||
new_item['environment_scope'] = value.get('environment_scope')
|
||||
|
||||
variables.append(new_item)
|
||||
|
||||
else:
|
||||
module.fail_json(msg="value must be of type string, integer, float or dict")
|
||||
|
||||
return variables
|
||||
|
||||
|
||||
class GitlabGroupVariables(object):
|
||||
|
||||
def __init__(self, module, gitlab_instance):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue