mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-27 18:50:21 -07:00
Create gitlab_group_variable.py (#786)
* Create gitlab_group_variable.py * Create gitlab_group_variable.py * Create gitlab_group_variable.py * Create gitlab_group_variable tests * Fix test error E127: continuation line over-indented for visual indent * Update plugins/modules/gitlab_group_variable.py Co-authored-by: Felix Fontein <felix@fontein.de> * Create symlink for module * Update plugins/modules/source_control/gitlab/gitlab_group_variable.py Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru> * Update plugins/modules/source_control/gitlab/gitlab_group_variable.py Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru> * Update plugins/modules/source_control/gitlab/gitlab_group_variable.py Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru> * Update plugins/modules/source_control/gitlab/gitlab_group_variable.py Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru> * Update plugins/modules/source_control/gitlab/gitlab_group_variable.py Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru> * Apply suggestions from code review Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru> Co-authored-by: Felix Fontein <felix@fontein.de> * Apply suggestions from code review Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru> * Update plugins/modules/source_control/gitlab/gitlab_group_variable.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/source_control/gitlab/gitlab_group_variable.py Co-authored-by: Felix Fontein <felix@fontein.de> * Validate all input before starting to do changes Validate all input before starting to do changes * Update gitlab_group_variable.py * Update gitlab_group_variable.py * Update plugins/modules/source_control/gitlab/gitlab_group_variable.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
This commit is contained in:
parent
09d89da0ab
commit
60c9da76e7
4 changed files with 807 additions and 0 deletions
1
tests/integration/targets/gitlab_group_variable/aliases
Normal file
1
tests/integration/targets/gitlab_group_variable/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
unsupported
|
508
tests/integration/targets/gitlab_group_variable/tasks/main.yml
Normal file
508
tests/integration/targets/gitlab_group_variable/tasks/main.yml
Normal file
|
@ -0,0 +1,508 @@
|
|||
---
|
||||
- name: Install required libs
|
||||
pip:
|
||||
name: python-gitlab
|
||||
state: present
|
||||
|
||||
- name: purge all variables for check_mode test
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
purge: True
|
||||
|
||||
- name: add a variable value in check_mode
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID: checkmode
|
||||
check_mode: yes
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: check_mode state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is changed
|
||||
|
||||
- name: apply add value from check_mode test
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID: checkmode
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is changed
|
||||
|
||||
- name: test new format
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID:
|
||||
value: checkmode
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: state must be not changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is not changed
|
||||
|
||||
- name: change protected attribute
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID:
|
||||
value: checkmode
|
||||
protected: True
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is changed
|
||||
|
||||
- name: revert protected attribute
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID:
|
||||
value: checkmode
|
||||
protected: False
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is changed
|
||||
|
||||
- name: change masked attribute
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID:
|
||||
value: checkmode
|
||||
masked: True
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is changed
|
||||
|
||||
- name: revert masked attribute by not mention it
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID:
|
||||
value: checkmode
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is changed
|
||||
|
||||
- name: revert again masked attribute by not mention it (idempotent)
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID:
|
||||
value: checkmode
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: state must be not changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is not changed
|
||||
|
||||
- name: set both (masked and protected) attribute
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID:
|
||||
value: checkmode
|
||||
masked: True
|
||||
protected: True
|
||||
variable_type: env_var
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is changed
|
||||
|
||||
- name: set again both (masked and protected) attribute (idempotent)
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID:
|
||||
value: checkmode
|
||||
masked: True
|
||||
protected: True
|
||||
variable_type: env_var
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: state must not be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is not changed
|
||||
|
||||
- name: revert both (masked and protected) attribute
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID:
|
||||
value: checkmode
|
||||
protected: False
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is changed
|
||||
|
||||
- name: change a variable value in check_mode again
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID: checkmode
|
||||
check_mode: yes
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: check_mode state must not be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is not changed
|
||||
|
||||
- name: apply again the value change from check_mode test
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID: checkmode
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: state must not be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is not changed
|
||||
|
||||
- name: purge all variables at the beginning
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
purge: True
|
||||
|
||||
- name: set two test variables
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID: abc123
|
||||
SECRET_ACCESS_KEY: 321cba
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: set two test variables state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is 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
|
||||
|
||||
- name: re-set two test variables
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID: abc123
|
||||
SECRET_ACCESS_KEY: 321cba
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: re-set two test variables state must not be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is not changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 0
|
||||
- gitlab_group_variable_state.group_variable.untouched|length == 2
|
||||
- gitlab_group_variable_state.group_variable.removed|length == 0
|
||||
- gitlab_group_variable_state.group_variable.updated|length == 0
|
||||
|
||||
- name: edit one variable
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID: changed
|
||||
purge: False
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: edit one variable state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state.changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 0
|
||||
- gitlab_group_variable_state.group_variable.untouched|length == 1
|
||||
- gitlab_group_variable_state.group_variable.removed|length == 0
|
||||
- gitlab_group_variable_state.group_variable.updated|length == 1
|
||||
- gitlab_group_variable_state.group_variable.updated[0] == "ACCESS_KEY_ID"
|
||||
|
||||
- name: append one variable
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
some: value
|
||||
purge: False
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: append one variable state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state.changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 1
|
||||
- gitlab_group_variable_state.group_variable.untouched|length == 2
|
||||
- gitlab_group_variable_state.group_variable.removed|length == 0
|
||||
- gitlab_group_variable_state.group_variable.updated|length == 0
|
||||
- gitlab_group_variable_state.group_variable.added[0] == "some"
|
||||
|
||||
- name: re-set all variables
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
ACCESS_KEY_ID: changed
|
||||
SECRET_ACCESS_KEY: 321cba
|
||||
some: value
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: re-set all variables state must not be changed
|
||||
assert:
|
||||
that:
|
||||
- not gitlab_group_variable_state.changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 0
|
||||
- gitlab_group_variable_state.group_variable.untouched|length == 3
|
||||
- gitlab_group_variable_state.group_variable.removed|length == 0
|
||||
- gitlab_group_variable_state.group_variable.updated|length == 0
|
||||
|
||||
- name: set one variables and purge all others
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
some: value
|
||||
purge: True
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: set one variables and purge all others state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state.changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 0
|
||||
- gitlab_group_variable_state.group_variable.untouched|length == 1
|
||||
- gitlab_group_variable_state.group_variable.removed|length == 2
|
||||
- gitlab_group_variable_state.group_variable.updated|length == 0
|
||||
|
||||
- name: only one variable is left
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
some: value
|
||||
purge: False
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: only one variable is left state must not be changed
|
||||
assert:
|
||||
that:
|
||||
- not gitlab_group_variable_state.changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 0
|
||||
- gitlab_group_variable_state.group_variable.untouched|length == 1
|
||||
- gitlab_group_variable_state.group_variable.removed|length == 0
|
||||
- gitlab_group_variable_state.group_variable.updated|length == 0
|
||||
- gitlab_group_variable_state.group_variable.untouched[0] == "some"
|
||||
|
||||
- name: test integer values
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
some: 42
|
||||
purge: False
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: only one variable is left state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state.changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 0
|
||||
- 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 == 1
|
||||
|
||||
- name: test float values
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
some: 42.23
|
||||
purge: False
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: only one variable is left state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state.changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 0
|
||||
- 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 == 1
|
||||
|
||||
- name: delete the last left variable
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
state: absent
|
||||
vars:
|
||||
some: value
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: no variable is left state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state.changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 0
|
||||
- gitlab_group_variable_state.group_variable.untouched|length == 0
|
||||
- gitlab_group_variable_state.group_variable.removed|length == 1
|
||||
- gitlab_group_variable_state.group_variable.updated|length == 0
|
||||
- gitlab_group_variable_state.group_variable.removed[0] == "some"
|
||||
|
||||
- name: add one variable with variable_type file
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
my_test_var:
|
||||
value: my_test_value
|
||||
variable_type: file
|
||||
purge: False
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: append one variable state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state.changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 1
|
||||
- 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
|
||||
- gitlab_group_variable_state.group_variable.added[0] == "my_test_var"
|
||||
|
||||
- name: change variable_type attribute
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
my_test_var:
|
||||
value: my_test_value
|
||||
variable_type: env_var
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is changed
|
||||
|
||||
- name: revert variable_type attribute
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
vars:
|
||||
my_test_var:
|
||||
value: my_test_value
|
||||
variable_type: file
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state is changed
|
||||
|
||||
- name: delete the variable_type file variable
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
state: absent
|
||||
vars:
|
||||
my_test_var: my_test_value
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: no variable is left state must be changed
|
||||
assert:
|
||||
that:
|
||||
- gitlab_group_variable_state.changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 0
|
||||
- gitlab_group_variable_state.group_variable.untouched|length == 0
|
||||
- gitlab_group_variable_state.group_variable.removed|length == 1
|
||||
- gitlab_group_variable_state.group_variable.updated|length == 0
|
||||
- gitlab_group_variable_state.group_variable.removed[0] == "my_test_var"
|
||||
|
||||
- name: check that no variables are left
|
||||
gitlab_group_variable:
|
||||
api_url: "{{ gitlab_host }}"
|
||||
api_token: "{{ gitlab_login_token }}"
|
||||
group: "{{ gitlab_group_name }}"
|
||||
purge: True
|
||||
register: gitlab_group_variable_state
|
||||
|
||||
- name: check that no variables are untoucheded state must be changed
|
||||
assert:
|
||||
that:
|
||||
- not gitlab_group_variable_state.changed
|
||||
- gitlab_group_variable_state.group_variable.added|length == 0
|
||||
- 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
|
Loading…
Add table
Add a link
Reference in a new issue