Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql_role: don't add members to a role when creating the role and "detach_members: true" is set #367

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/367-mysql_role-fix-deatch-members.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "mysql_role: don't add members to a role when creating the role and \"detach_members: true\" is set"
betanummeric marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions plugins/modules/mysql_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@

author:
- Andrew Klychkov (@Andersson007)
- Felix Hamme (@betanummeric)

extends_documentation_fragment:
- community.mysql.mysql
Expand Down Expand Up @@ -1067,6 +1068,8 @@ def main():
if not role.exists:
if subtract_privs:
priv = None # avoid granting unwanted privileges
if detach_members:
members = None # avoid adding unwanted members
changed = role.add(members, priv, module.check_mode, admin,
set_default_role_all)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ nonexistent: user3
role0: role0
role1: role1
role2: role2
role3: role3
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,32 @@
that:
- result is not changed

- name: '"detach" users when creating a new role'
<<: *task_params
mysql_role:
<<: *mysql_params
name: '{{ role3 }}'
state: present
detach_members: yes
members:
- '{{ user1 }}@localhost'

- name: Check the role was created
assert:
that:
- result is changed

- name: Check grants
<<: *task_params
mysql_query:
<<: *mysql_params
query: "SHOW GRANTS FOR {{ user1 }}@localhost"

- name: asssert detach_members did not add a user to the role
assert:
that:
- "'{{ role3 }}' not in result.query_result.0.0['Grants for {{ user1 }}@localhost']"

# ##########
# Test privs
# ##########
Expand Down Expand Up @@ -1561,3 +1587,4 @@
loop:
- '{{ role0 }}'
- test
- '{{ role3 }}'