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:
Markus Bergholz 2022-02-05 21:02:04 +01:00 committed by GitHub
commit 69551ac325
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 6 deletions

View file

@ -227,6 +227,7 @@
vars:
ACCESS_KEY_ID:
environment_scope: testing
value: checkmode
register: gitlab_project_variable_state
- name: state must be changed
@ -242,6 +243,7 @@
vars:
ACCESS_KEY_ID:
environment_scope: testing
value: checkmode
register: gitlab_project_variable_state
- 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.removed|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