-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify MySQL queries for user deletion (#641)
* use rowcount to determine mysql results Signed-off-by: Martin Schurz <[email protected]> * use correct list level Signed-off-by: Martin Schurz <[email protected]> * remove json_query Signed-off-by: Martin Schurz <[email protected]> * remove intermediate vars Signed-off-by: Martin Schurz <[email protected]> * add check for count Signed-off-by: Martin Schurz <[email protected]> * drop condition, since one result must exist Signed-off-by: Martin Schurz <[email protected]> * move rowcount in condition Signed-off-by: Martin Schurz <[email protected]> * do loop in ansible to report each deleted user Signed-off-by: Martin Schurz <[email protected]> * add idempotency check Signed-off-by: Martin Schurz <[email protected]> * additional tests to verify user deletion Signed-off-by: Martin Schurz <[email protected]> * actually iterate the whole user list when deleting Signed-off-by: Martin Schurz <[email protected]> * fix tests for SuSE Signed-off-by: Martin Schurz <[email protected]> * adopt suggestions Signed-off-by: Martin Schurz <[email protected]> --------- Signed-off-by: Martin Schurz <[email protected]>
- Loading branch information
Showing
6 changed files
with
58 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,6 @@ scenario: | |
- create | ||
- prepare | ||
- converge | ||
# - idempotence # not idempotent | ||
- idempotence | ||
- verify | ||
- destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
- name: create users for test | ||
community.mysql.mysql_query: | ||
query: | ||
- "CREATE USER 'user'@'delete';" | ||
- "CREATE USER 'user'@'127.0.0.1';" | ||
- "CREATE USER 'user'@'::1';" | ||
- "CREATE USER 'user'@'%';" | ||
- "CREATE USER 'user'@'192.168.0.%';" | ||
- "CREATE USER 'user'@'192.168.0.1';" | ||
- "CREATE USER '%'@'192.168.0.1';" | ||
- "CREATE USER 'user'@'192.168.0.2' IDENTIFIED BY 'keep';" | ||
- "CREATE USER 'user'@'keep' IDENTIFIED BY 'keep';" | ||
- "CREATE USER 'user'@'192.168.%' IDENTIFIED BY 'keep';" | ||
login_unix_socket: "{{ login_unix_socket | default(omit) }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
- name: Get all users from MySQL server | ||
community.mysql.mysql_query: | ||
query: > | ||
SELECT CONCAT(USER, '@', HOST) AS users FROM mysql.user; | ||
login_unix_socket: "{{ login_unix_socket | default(omit) }}" | ||
register: mysql_users | ||
|
||
- name: create list of users from mysql query | ||
set_fact: | ||
mysql_users_list: "{{ mysql_users.query_result.0 | json_query('[*].users') | list }}" | ||
|
||
- name: assert that only accounts with password remain | ||
ansible.builtin.assert: | ||
that: | ||
- '"user@delete" not in mysql_users_list' | ||
- '"[email protected]" not in mysql_users_list' | ||
- '"user@::1" not in mysql_users_list' | ||
- '"user@%" not in mysql_users_list' | ||
- '"[email protected].%" not in mysql_users_list' | ||
- '"[email protected]" not in mysql_users_list' | ||
- '"%@192.168.0.1" not in mysql_users_list' | ||
- '"[email protected]" in mysql_users_list' | ||
- '"user@keep" in mysql_users_list' | ||
- '"[email protected].%" in mysql_users_list' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters