-
Notifications
You must be signed in to change notification settings - Fork 704
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 <Martin.Schurz@t-systems.com> * use correct list level Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com> * remove json_query Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com> * remove intermediate vars Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com> * add check for count Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com> * drop condition, since one result must exist Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com> * move rowcount in condition Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com> * do loop in ansible to report each deleted user Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com> * add idempotency check Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com> * additional tests to verify user deletion Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com> * actually iterate the whole user list when deleting Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com> * fix tests for SuSE Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com> * adopt suggestions Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com> --------- Signed-off-by: Martin Schurz <Martin.Schurz@t-systems.com>
- 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' | ||
- '"user@127.0.0.1" not in mysql_users_list' | ||
- '"user@::1" not in mysql_users_list' | ||
- '"user@%" not in mysql_users_list' | ||
- '"user@192.168.0.%" not in mysql_users_list' | ||
- '"user@192.168.0.1" not in mysql_users_list' | ||
- '"%@192.168.0.1" not in mysql_users_list' | ||
- '"user@192.168.0.2" in mysql_users_list' | ||
- '"user@keep" in mysql_users_list' | ||
- '"user@192.168.%" 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