mysql_role: add argument "members_must_exist" (#369)

* mysql_role: add argument "members_must_exist" (boolean, default true)

The assertion that the users supplied in the "members" argument exist is only executed when the new argument "members_must_exist" is true, to allow opt-out.

* mysql_role: add integration tests for argument members_must_exist

* add changelog fragment

* mysql_role: fix behavior of members_must_exist argument

* Update plugins/modules/mysql_role.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update changelogs/fragments/369_mysql_role-add-members_must_exist.yml

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

Co-authored-by: Felix Hamme <felix.hamme@ionos.com>
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
This commit is contained in:
betanummeric 2022-05-27 12:11:17 +02:00 committed by GitHub
commit bf5086d19d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 87 additions and 1 deletions

View file

@ -1274,6 +1274,71 @@
that:
- "'{{ role3 }}' not in result.query_result.0.0['Grants for {{ user1 }}@localhost']"
# test members_must_exist
- name: try failing on not-existing user in check-mode
<<: *task_params
mysql_role:
<<: *mysql_params
name: '{{ role0 }}'
state: present
members_must_exist: yes
append_members: yes
members:
- 'not_existent@localhost'
ignore_errors: yes
check_mode: yes
- name: assert failure
assert:
that:
- result is failed
- name: try failing on not-existing user in check-mode
<<: *task_params
mysql_role:
<<: *mysql_params
name: '{{ role0 }}'
state: present
members_must_exist: no
append_members: yes
members:
- 'not_existent@localhost'
check_mode: yes
- name: Check for lack of change
assert:
that:
- result is not changed
- name: try failing on not-existing user
<<: *task_params
mysql_role:
<<: *mysql_params
name: '{{ role0 }}'
state: present
members_must_exist: yes
append_members: yes
members:
- 'not_existent@localhost'
ignore_errors: yes
- name: assert failure
assert:
that:
- result is failed
- name: try failing on not-existing user
<<: *task_params
mysql_role:
<<: *mysql_params
name: '{{ role0 }}'
state: present
members_must_exist: no
append_members: yes
members:
- 'not_existent@localhost'
- name: Check for lack of change
assert:
that:
- result is not changed
# ##########
# Test privs
# ##########