mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
gitlab_project_variable: Allow delete without value (#4150)
* value is not required when state is absent * fix integration test. missing value * fix condition * add changelog fragment * fail fast * try required_if on suboptions * revert * Update plugins/modules/source_control/gitlab/gitlab_project_variable.py Co-authored-by: Felix Fontein <felix@fontein.de> * fix naming in doc * typo in name Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
9322809b3a
commit
69551ac325
3 changed files with 61 additions and 6 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- gitlab_project_variable - ``value`` is not necessary when deleting variables (https://github.com/ansible-collections/community.general/pull/4150).
|
|
@ -74,8 +74,8 @@ options:
|
||||||
value:
|
value:
|
||||||
description:
|
description:
|
||||||
- The variable value.
|
- The variable value.
|
||||||
|
- Required when I(state=present).
|
||||||
type: str
|
type: str
|
||||||
required: true
|
|
||||||
masked:
|
masked:
|
||||||
description:
|
description:
|
||||||
- Wether variable value is masked or not.
|
- Wether variable value is masked or not.
|
||||||
|
@ -403,7 +403,7 @@ def main():
|
||||||
vars=dict(type='dict', required=False, default=dict(), no_log=True),
|
vars=dict(type='dict', required=False, default=dict(), no_log=True),
|
||||||
variables=dict(type='list', elements='dict', required=False, default=list(), options=dict(
|
variables=dict(type='list', elements='dict', required=False, default=list(), options=dict(
|
||||||
name=dict(type='str', required=True),
|
name=dict(type='str', required=True),
|
||||||
value=dict(type='str', required=True, no_log=True),
|
value=dict(type='str', no_log=True),
|
||||||
masked=dict(type='bool', default=False),
|
masked=dict(type='bool', default=False),
|
||||||
protected=dict(type='bool', default=False),
|
protected=dict(type='bool', default=False),
|
||||||
environment_scope=dict(type='str', default='*'),
|
environment_scope=dict(type='str', default='*'),
|
||||||
|
@ -431,18 +431,21 @@ def main():
|
||||||
supports_check_mode=True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not HAS_GITLAB_PACKAGE:
|
||||||
|
module.fail_json(msg=missing_required_lib("python-gitlab"), exception=GITLAB_IMP_ERR)
|
||||||
|
|
||||||
purge = module.params['purge']
|
purge = module.params['purge']
|
||||||
var_list = module.params['vars']
|
var_list = module.params['vars']
|
||||||
|
state = module.params['state']
|
||||||
|
|
||||||
if var_list:
|
if var_list:
|
||||||
variables = vars_to_variables(var_list, module)
|
variables = vars_to_variables(var_list, module)
|
||||||
else:
|
else:
|
||||||
variables = module.params['variables']
|
variables = module.params['variables']
|
||||||
|
|
||||||
state = module.params['state']
|
if state == 'present':
|
||||||
|
if any(x['value'] is None for x in variables):
|
||||||
if not HAS_GITLAB_PACKAGE:
|
module.fail_json(msg='value parameter is required in state present')
|
||||||
module.fail_json(msg=missing_required_lib("python-gitlab"), exception=GITLAB_IMP_ERR)
|
|
||||||
|
|
||||||
gitlab_instance = gitlab_authentication(module)
|
gitlab_instance = gitlab_authentication(module)
|
||||||
|
|
||||||
|
|
|
@ -227,6 +227,7 @@
|
||||||
vars:
|
vars:
|
||||||
ACCESS_KEY_ID:
|
ACCESS_KEY_ID:
|
||||||
environment_scope: testing
|
environment_scope: testing
|
||||||
|
value: checkmode
|
||||||
register: gitlab_project_variable_state
|
register: gitlab_project_variable_state
|
||||||
|
|
||||||
- name: state must be changed
|
- name: state must be changed
|
||||||
|
@ -242,6 +243,7 @@
|
||||||
vars:
|
vars:
|
||||||
ACCESS_KEY_ID:
|
ACCESS_KEY_ID:
|
||||||
environment_scope: testing
|
environment_scope: testing
|
||||||
|
value: checkmode
|
||||||
register: gitlab_project_variable_state
|
register: gitlab_project_variable_state
|
||||||
|
|
||||||
- name: state must not be changed
|
- name: state must not be changed
|
||||||
|
@ -644,3 +646,51 @@
|
||||||
- gitlab_project_variable_state.project_variable.untouched|length == 0
|
- gitlab_project_variable_state.project_variable.untouched|length == 0
|
||||||
- gitlab_project_variable_state.project_variable.removed|length == 0
|
- gitlab_project_variable_state.project_variable.removed|length == 0
|
||||||
- gitlab_project_variable_state.project_variable.updated|length == 0
|
- gitlab_project_variable_state.project_variable.updated|length == 0
|
||||||
|
|
||||||
|
- name: throw error when state is present but no value is given
|
||||||
|
gitlab_project_variable:
|
||||||
|
api_url: "{{ gitlab_host }}"
|
||||||
|
api_token: "{{ gitlab_login_token }}"
|
||||||
|
project: "{{ gitlab_project_name }}"
|
||||||
|
variables:
|
||||||
|
- name: delete_me
|
||||||
|
register: gitlab_project_variable_state
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: verify fail
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- gitlab_project_variable_state.failed
|
||||||
|
- gitlab_project_variable_state is not changed
|
||||||
|
|
||||||
|
- name: set a new variable to delete it later
|
||||||
|
gitlab_project_variable:
|
||||||
|
api_url: "{{ gitlab_host }}"
|
||||||
|
api_token: "{{ gitlab_login_token }}"
|
||||||
|
project: "{{ gitlab_project_name }}"
|
||||||
|
purge: True
|
||||||
|
variables:
|
||||||
|
- name: delete_me
|
||||||
|
value: ansible
|
||||||
|
register: gitlab_project_variable_state
|
||||||
|
|
||||||
|
- name: verify the change
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- gitlab_project_variable_state.changed
|
||||||
|
|
||||||
|
- name: delete variable without referencing its value
|
||||||
|
gitlab_project_variable:
|
||||||
|
api_url: "{{ gitlab_host }}"
|
||||||
|
api_token: "{{ gitlab_login_token }}"
|
||||||
|
project: "{{ gitlab_project_name }}"
|
||||||
|
state: absent
|
||||||
|
variables:
|
||||||
|
- name: delete_me
|
||||||
|
register: gitlab_project_variable_state
|
||||||
|
|
||||||
|
- name: verify deletion
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- gitlab_project_variable_state.changed
|
||||||
|
- gitlab_project_variable_state.project_variable.removed|length == 1
|
||||||
|
|
Loading…
Reference in a new issue