Rework of gitlab_project_variable over gitlab_group_variable (#4086) (#4226)

* Rework of gitlab_project_variable over gitlab_group_variable

* Linting and removed unused example

* Fix test 2

* Sync from review of gitlab_project_variable #4038

* Linting, default protected True, value optional

* Next version is 4.5.0

* Roll back protected default true, and value not required

* Apply suggestions from code review

Missing check_mode

Co-authored-by: Markus Bergholz <git@osuv.de>

* Fix one unit test, comment test that requires premium gitlab

* Add changelog

* Update plugins/modules/source_control/gitlab/gitlab_group_variable.py

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

* Update changelogs/fragments/4086-rework_of_gitlab_proyect_variable_over_gitlab_group_variable.yml

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

* Added conditional gitlab_premium_tests variable when required

* Allow delete without value

* Fix variable name

* Linting

* Value should not be required in doc

* Linting missing new-line

* Update changelogs/fragments/4086-rework_of_gitlab_proyect_variable_over_gitlab_group_variable.yml

Co-authored-by: Markus Bergholz <git@osuv.de>

Co-authored-by: Markus Bergholz <git@osuv.de>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 44f9bf545d)

Co-authored-by: Sebastian Guarino <sebastian.guarino@gmail.com>
This commit is contained in:
patchback[bot] 2022-02-18 20:52:36 +00:00 committed by GitHub
parent b3963fd3c7
commit ec7c39351d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 378 additions and 97 deletions

View file

@ -36,8 +36,9 @@
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
group: "{{ gitlab_group_name }}"
vars:
ACCESS_KEY_ID: checkmode
variables:
- name: ACCESS_KEY_ID
value: checkmode
register: gitlab_group_variable_state
- name: state must be changed
@ -219,6 +220,42 @@
that:
- gitlab_group_variable_state is not changed
- name: change environment scope
gitlab_group_variable:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
group: "{{ gitlab_group_name }}"
vars:
ACCESS_KEY_ID:
environment_scope: testing
value: checkmode
register: gitlab_group_variable_state
when: gitlab_premium_tests is defined
- name: state must be changed
assert:
that:
- gitlab_group_variable_state is changed
when: gitlab_premium_tests is defined
- name: apply again the environment scope change
gitlab_group_variable:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
group: "{{ gitlab_group_name }}"
vars:
ACCESS_KEY_ID:
environment_scope: testing
value: checkmode
register: gitlab_group_variable_state
when: gitlab_premium_tests is defined
- name: state must not be changed
assert:
that:
- gitlab_group_variable_state is not changed
when: gitlab_premium_tests is defined
- name: purge all variables at the beginning
gitlab_group_variable:
api_url: "{{ gitlab_host }}"
@ -426,8 +463,8 @@
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
group: "{{ gitlab_group_name }}"
vars:
my_test_var:
variables:
- name: my_test_var
value: my_test_value
variable_type: file
purge: False
@ -583,3 +620,84 @@
- gitlab_group_variable_state.group_variable.untouched|length == 0
- gitlab_group_variable_state.group_variable.removed|length == 40
- gitlab_group_variable_state.group_variable.updated|length == 0
- name: same vars, diff scope
gitlab_group_variable:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
group: "{{ gitlab_group_name }}"
purge: True
variables:
- name: SECRET_ACCESS_KEY
value: 3214cbad
masked: true
protected: true
variable_type: env_var
environment_scope: production
- name: SECRET_ACCESS_KEY
value: hello_world
masked: true
protected: true
variable_type: env_var
environment_scope: development
register: gitlab_group_variable_state
when: gitlab_premium_tests is defined
- name: verify two vars
assert:
that:
- gitlab_group_variable_state.changed
- gitlab_group_variable_state.group_variable.added|length == 2
- gitlab_group_variable_state.group_variable.untouched|length == 0
- gitlab_group_variable_state.group_variable.removed|length == 0
- gitlab_group_variable_state.group_variable.updated|length == 0
when: gitlab_premium_tests is defined
- name: throw error when state is present but no value is given
gitlab_group_variable:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
group: "{{ gitlab_group_name }}"
variables:
- name: delete_me
register: gitlab_group_variable_state
ignore_errors: yes
- name: verify fail
assert:
that:
- gitlab_group_variable_state.failed
- gitlab_group_variable_state is not changed
- name: set a new variable to delete it later
gitlab_group_variable:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
group: "{{ gitlab_group_name }}"
purge: True
variables:
- name: delete_me
value: ansible
register: gitlab_group_variable_state
- name: verify the change
assert:
that:
- gitlab_group_variable_state.changed
- name: delete variable without referencing its value
gitlab_group_variable:
api_url: "{{ gitlab_host }}"
api_token: "{{ gitlab_login_token }}"
group: "{{ gitlab_group_name }}"
state: absent
variables:
- name: delete_me
register: gitlab_group_variable_state
- name: verify deletion
assert:
that:
- gitlab_group_variable_state.changed
- gitlab_group_variable_state.group_variable.removed|length == 1