change filter name to user_accounts

This commit is contained in:
Laurent Indermuehle 2023-10-12 16:44:14 +02:00
parent 71abdd7567
commit db43c34f63
No known key found for this signature in database
GPG key ID: 93FA944C9F34DD09
5 changed files with 98 additions and 98 deletions

View file

@ -2,4 +2,4 @@
minor_changes:
- mysql_info - add filter ``users_privs`` (https://github.com/ansible-collections/community.mysql/pull/572).
- mysql_info - add filter ``user_accounts`` (https://github.com/ansible-collections/community.mysql/pull/572).

View file

@ -19,7 +19,7 @@ options:
description:
- Limit the collected information by comma separated string or YAML list.
- Allowable values are C(version), C(databases), C(settings), C(global_status),
C(users), C(users_privs), C(engines), C(master_status), C(slave_status), C(slave_hosts).
C(users), C(user_accounts), C(engines), C(master_status), C(slave_status), C(slave_hosts).
- By default, collects all subsets.
- You can use '!' before value (for example, C(!settings)) to exclude it from the information.
- If you pass including and excluding values to the filter, for example, I(filter=!settings,version),
@ -75,7 +75,7 @@ EXAMPLES = r'''
# ansible mysql-hosts -m mysql_info -a 'filter=databases,users'
# Display all users privileges:
# ansible mysql-hosts -m mysql_info -a 'filter=users_privs'
# ansible mysql-hosts -m mysql_info -a 'filter=user_accounts'
# Display only slave status:
# ansible standby -m mysql_info -a 'filter=slave_status'
@ -133,7 +133,7 @@ EXAMPLES = r'''
delegate_to: server_source
community.mysql.mysql_info:
filter:
- users_privs
- user_accounts
register: result
# Step 2
@ -150,7 +150,7 @@ EXAMPLES = r'''
resource_limits: "{{ item.resource_limits | default(omit) }}"
column_case_sensitive: true
state: present
loop: "{{ result.users_privs }}"
loop: "{{ result.user_accounts }}"
loop_control:
label: "{{ item.name }}@{{ item.host }}"
when:
@ -221,7 +221,7 @@ users:
type: dict
sample:
- { "localhost": { "root": { "Alter_priv": "Y", "Alter_routine_priv": "Y" } } }
users_privs:
user_accounts:
description:
- Information about users accounts.
- The output can be used as an input of the M(community.mysql.mysql_user) plugin.
@ -334,7 +334,7 @@ class MySQL_Info(object):
'global_status': {},
'engines': {},
'users': {},
'users_privs': {},
'user_accounts': {},
'master_status': {},
'slave_hosts': {},
'slave_status': {},
@ -403,8 +403,8 @@ class MySQL_Info(object):
if 'users' in wanted:
self.__get_users()
if 'users_privs' in wanted:
self.__get_users_privs()
if 'user_accounts' in wanted:
self.__get_user_accounts()
if 'master_status' in wanted:
self.__get_master_status()
@ -544,23 +544,23 @@ class MySQL_Info(object):
if vname not in ('Host', 'User'):
self.info['users'][host][user][vname] = self.__convert(val)
def __get_users_privs(self):
"""Get user privileges.
def __get_user_accounts(self):
"""Get user privileges, passwords, resources_limits, ...
Query the server to get all the users and return a string
of privileges that can be used by the mysql_user plugin.
For instance:
"users_privs": [
"user_accounts": [
{
"host": "users_privs.com",
"host": "user_accounts.com",
"priv": "*.*: ALL,GRANT",
"name": "users_privs_adm"
"name": "user_accounts_adm"
},
{
"host": "users_privs.com",
"priv": "`mysql`.*: SELECT/`users_privs_db`.*: SELECT",
"name": "users_privs_multi"
"host": "user_accounts.com",
"priv": "`mysql`.*: SELECT/`user_accounts_db`.*: SELECT",
"name": "user_accounts_multi"
}
]
"""
@ -622,7 +622,7 @@ class MySQL_Info(object):
output.append(output_dict)
self.info['users_privs'] = output
self.info['user_accounts'] = output
def __get_databases(self, exclude_fields, return_empty_dbs):
"""Get info about databases."""

View file

@ -1,7 +1,7 @@
DELIMITER //
DROP PROCEDURE IF EXISTS users_privs_db.get_all_items;
CREATE PROCEDURE users_privs_db.get_all_items()
DROP PROCEDURE IF EXISTS user_accounts_db.get_all_items;
CREATE PROCEDURE user_accounts_db.get_all_items()
BEGIN
SELECT * from users_privs_db.t1;
SELECT * from user_accounts_db.t1;
END //
DELIMITER ;

View file

@ -13,35 +13,35 @@
block:
# ================================ Prepare ==============================
- name: Mysql_info users_privs | Create databases
- name: Mysql_info user_accounts | Create databases
community.mysql.mysql_db:
name:
- users_privs_db
- users_privs_db2
- users_privs_db3
- user_accounts_db
- user_accounts_db2
- user_accounts_db3
state: present
- name: Mysql_info users_privs | Create tables
- name: Mysql_info user_accounts | Create tables
community.mysql.mysql_query:
query:
- >-
CREATE TABLE IF NOT EXISTS users_privs_db.t1
CREATE TABLE IF NOT EXISTS user_accounts_db.t1
(id int, name varchar(9))
- >-
CREATE TABLE IF NOT EXISTS users_privs_db.T_UPPER
CREATE TABLE IF NOT EXISTS user_accounts_db.T_UPPER
(id int, name1 varchar(9), NAME2 varchar(9), Name3 varchar(9))
# I failed to create a procedure using community.mysql.mysql_query.
# Maybe it's because we must changed the delimiter.
- name: Mysql_info users_privs | Create procedure SQL file
- name: Mysql_info user_accounts | Create procedure SQL file
ansible.builtin.template:
src: files/users_privs_create_procedure.sql
src: files/user_accounts_create_procedure.sql
dest: /root/create_procedure.sql
owner: root
group: root
mode: '0700'
- name: Mysql_info users_privs | Create a procedure
- name: Mysql_info user_accounts | Create a procedure
community.mysql.mysql_db:
name: all
state: import
@ -49,108 +49,108 @@
# Use a query instead of mysql_user, because we want to caches differences
# at the end and a bug in mysql_user would be invisible to this tests
- name: Mysql_info users_privs | Prepare common tests users
- name: Mysql_info user_accounts | Prepare common tests users
community.mysql.mysql_query:
query:
- >-
CREATE USER users_privs_adm@'users_privs.com' IDENTIFIED WITH
CREATE USER user_accounts_adm@'user_accounts.com' IDENTIFIED WITH
mysql_native_password AS '*6C387FC3893DBA1E3BA155E74754DA6682D04747'
- >
GRANT ALL ON *.* to users_privs_adm@'users_privs.com' WITH GRANT
GRANT ALL ON *.* to user_accounts_adm@'user_accounts.com' WITH GRANT
OPTION
- >-
CREATE USER users_privs_schema@'users_privs.com' IDENTIFIED WITH
CREATE USER user_accounts_schema@'user_accounts.com' IDENTIFIED WITH
mysql_native_password AS '*6C387FC3893DBA1E3BA155E74754DA6682D04747'
- >-
GRANT SELECT, INSERT, UPDATE, DELETE ON users_privs_db.* TO
users_privs_schema@'users_privs.com'
GRANT SELECT, INSERT, UPDATE, DELETE ON user_accounts_db.* TO
user_accounts_schema@'user_accounts.com'
- >-
CREATE USER users_privs_table@'users_privs.com' IDENTIFIED WITH
CREATE USER user_accounts_table@'user_accounts.com' IDENTIFIED WITH
mysql_native_password AS '*6C387FC3893DBA1E3BA155E74754DA6682D04747'
- >-
GRANT SELECT, INSERT, UPDATE ON users_privs_db.t1 TO
users_privs_table@'users_privs.com'
GRANT SELECT, INSERT, UPDATE ON user_accounts_db.t1 TO
user_accounts_table@'user_accounts.com'
- >-
CREATE USER users_privs_col@'users_privs.com' IDENTIFIED WITH
CREATE USER user_accounts_col@'user_accounts.com' IDENTIFIED WITH
mysql_native_password AS '*6C387FC3893DBA1E3BA155E74754DA6682D04747'
WITH MAX_USER_CONNECTIONS 100
- >-
GRANT SELECT (id) ON users_privs_db.t1 TO
users_privs_col@'users_privs.com'
GRANT SELECT (id) ON user_accounts_db.t1 TO
user_accounts_col@'user_accounts.com'
- >-
CREATE USER users_privs_proc@'users_privs.com' IDENTIFIED WITH
CREATE USER user_accounts_proc@'user_accounts.com' IDENTIFIED WITH
mysql_native_password AS '*6C387FC3893DBA1E3BA155E74754DA6682D04747'
WITH MAX_USER_CONNECTIONS 2 MAX_CONNECTIONS_PER_HOUR 60
- >-
GRANT EXECUTE ON PROCEDURE users_privs_db.get_all_items TO
users_privs_proc@'users_privs.com'
GRANT EXECUTE ON PROCEDURE user_accounts_db.get_all_items TO
user_accounts_proc@'user_accounts.com'
- >-
CREATE USER users_privs_multi@'users_privs.com' IDENTIFIED WITH
CREATE USER user_accounts_multi@'user_accounts.com' IDENTIFIED WITH
mysql_native_password AS '*6C387FC3893DBA1E3BA155E74754DA6682D04747'
- >-
GRANT SELECT ON mysql.* TO
users_privs_multi@'users_privs.com'
user_accounts_multi@'user_accounts.com'
- >-
GRANT ALL ON users_privs_db.* TO
users_privs_multi@'users_privs.com'
GRANT ALL ON user_accounts_db.* TO
user_accounts_multi@'user_accounts.com'
- >-
GRANT ALL ON users_privs_db2.* TO
users_privs_multi@'users_privs.com'
GRANT ALL ON user_accounts_db2.* TO
user_accounts_multi@'user_accounts.com'
- >-
GRANT ALL ON users_privs_db3.* TO
users_privs_multi@'users_privs.com'
GRANT ALL ON user_accounts_db3.* TO
user_accounts_multi@'user_accounts.com'
- >-
CREATE USER users_privs_usage_only@'users_privs.com' IDENTIFIED WITH
CREATE USER user_accounts_usage_only@'user_accounts.com' IDENTIFIED WITH
mysql_native_password AS '*6C387FC3893DBA1E3BA155E74754DA6682D04747'
- >-
GRANT USAGE ON *.* TO
users_privs_usage_only@'users_privs.com'
user_accounts_usage_only@'user_accounts.com'
- >-
CREATE USER users_privs_columns_uppercase@'users_privs.com'
CREATE USER user_accounts_columns_uppercase@'user_accounts.com'
IDENTIFIED WITH mysql_native_password AS
'*6C387FC3893DBA1E3BA155E74754DA6682D04747'
- >-
GRANT SELECT,UPDATE(name1,NAME2,Name3) ON users_privs_db.T_UPPER TO
users_privs_columns_uppercase@'users_privs.com'
GRANT SELECT,UPDATE(name1,NAME2,Name3) ON user_accounts_db.T_UPPER TO
user_accounts_columns_uppercase@'user_accounts.com'
- >-
CREATE USER users_privs_multi_hosts@'%'
CREATE USER user_accounts_multi_hosts@'%'
IDENTIFIED WITH mysql_native_password AS
'*6C387FC3893DBA1E3BA155E74754DA6682D04747'
- GRANT SELECT ON users_privs_db.* TO users_privs_multi_hosts@'%'
- GRANT SELECT ON user_accounts_db.* TO user_accounts_multi_hosts@'%'
- >-
CREATE USER users_privs_multi_hosts@'localhost'
CREATE USER user_accounts_multi_hosts@'localhost'
IDENTIFIED WITH mysql_native_password AS
'*6C387FC3893DBA1E3BA155E74754DA6682D04747'
- >-
GRANT SELECT ON users_privs_db.* TO
users_privs_multi_hosts@'localhost'
GRANT SELECT ON user_accounts_db.* TO
user_accounts_multi_hosts@'localhost'
- >-
CREATE USER users_privs_multi_hosts@'host1'
CREATE USER user_accounts_multi_hosts@'host1'
IDENTIFIED WITH mysql_native_password AS
'*6C387FC3893DBA1E3BA155E74754DA6682D04747'
- GRANT SELECT ON users_privs_db.* TO users_privs_multi_hosts@'host1'
- GRANT SELECT ON user_accounts_db.* TO user_accounts_multi_hosts@'host1'
# Different password than the others users_privs_multi_hosts
# Different password than the others user_accounts_multi_hosts
- >-
CREATE USER users_privs_multi_hosts@'host2'
CREATE USER user_accounts_multi_hosts@'host2'
IDENTIFIED WITH mysql_native_password AS
'*CB3326D5279DE7915FE5D743232165EE887883CA'
- GRANT SELECT ON users_privs_db.* TO users_privs_multi_hosts@'host2'
- GRANT SELECT ON user_accounts_db.* TO user_accounts_multi_hosts@'host2'
- name: Mysql_info users_privs | Prepare tests users for MariaDB
- name: Mysql_info user_accounts | Prepare tests users for MariaDB
community.mysql.mysql_user:
name: "{{ item.name }}"
host: "users_privs.com"
host: "user_accounts.com"
plugin: "{{ item.plugin | default(omit) }}"
plugin_auth_string: "{{ item.plugin_auth_string | default(omit) }}"
plugin_hash_string: "{{ item.plugin_hash_string | default(omit) }}"
@ -160,17 +160,17 @@
column_case_sensitive: true
state: present
loop:
- name: users_privs_socket # Only for MariaDB
- name: user_accounts_socket # Only for MariaDB
priv:
'*.*': 'ALL'
plugin: 'unix_socket'
when:
- db_engine == 'mariadb'
- name: Mysql_info users_privs | Prepare tests users for MySQL
- name: Mysql_info user_accounts | Prepare tests users for MySQL
community.mysql.mysql_user:
name: "{{ item.name }}"
host: "users_privs.com"
host: "user_accounts.com"
plugin: "{{ item.plugin | default(omit) }}"
plugin_auth_string: "{{ item.plugin_auth_string | default(omit) }}"
plugin_hash_string: "{{ item.plugin_hash_string | default(omit) }}"
@ -180,7 +180,7 @@
column_case_sensitive: true
state: present
loop:
- name: users_privs_sha256 # Only for MySQL
- name: user_accounts_sha256 # Only for MySQL
priv:
'*.*': 'ALL'
plugin_auth_string:
@ -189,10 +189,10 @@
when:
- db_engine == 'mysql'
- name: Mysql_info users_privs | Prepare tests users for MySQL 8+
- name: Mysql_info user_accounts | Prepare tests users for MySQL 8+
community.mysql.mysql_user:
name: "{{ item.name }}"
host: "users_privs.com"
host: "user_accounts.com"
plugin: "{{ item.plugin | default(omit) }}"
plugin_auth_string: "{{ item.plugin_auth_string | default(omit) }}"
plugin_hash_string: "{{ item.plugin_hash_string | default(omit) }}"
@ -202,7 +202,7 @@
column_case_sensitive: true
state: present
loop:
- name: users_privs_caching_sha2 # Only for MySQL 8+
- name: user_accounts_caching_sha2 # Only for MySQL 8+
priv:
'*.*': 'ALL'
plugin_auth_string:
@ -214,13 +214,13 @@
# ================================== Tests ==============================
- name: Mysql_info users_privs | Collect users_privs
- name: Mysql_info user_accounts | Collect user_accounts
community.mysql.mysql_info:
filter:
- users_privs
- user_accounts
register: result
- name: Recreate users from mysql_info users_privs result
- name: Recreate users from mysql_info user_accounts result
community.mysql.mysql_user:
name: "{{ item.name }}"
host: "{{ item.host }}"
@ -232,7 +232,7 @@
resource_limits: "{{ item.resource_limits | default(omit) }}"
column_case_sensitive: true
state: present
loop: "{{ result.users_privs }}"
loop: "{{ result.user_accounts }}"
loop_control:
label: "{{ item.name }}@{{ item.host }}"
register: recreate_users_result
@ -248,30 +248,30 @@
# ================================== Cleanup ============================
- name: Mysql_info users_privs | Cleanup users_privs
- name: Mysql_info user_accounts | Cleanup user_accounts
community.mysql.mysql_user:
name: "{{ item }}"
host: "users_privs.com"
host: "user_accounts.com"
column_case_sensitive: true
state: absent
loop:
- users_privs_adm
- users_privs_schema
- users_privs_table
- users_privs_col
- users_privs_proc
- users_privs_usage_only
- users_privs_columns_uppercase
- user_accounts_adm
- user_accounts_schema
- user_accounts_table
- user_accounts_col
- user_accounts_proc
- user_accounts_usage_only
- user_accounts_columns_uppercase
- name: Mysql_info users_privs | Cleanup databases
- name: Mysql_info user_accounts | Cleanup databases
community.mysql.mysql_db:
name:
- users_privs_db
- users_privs_db2
- users_privs_db3
- user_accounts_db
- user_accounts_db2
- user_accounts_db3
state: absent
- name: Mysql_info users_privs | Cleanup sql file for the procedure
- name: Mysql_info user_accounts | Cleanup sql file for the procedure
ansible.builtin.file:
path: /root/create_procedure.sql
state: absent

View file

@ -220,6 +220,6 @@
that:
- result.databases.allviews.size == 0
- name: Import tasks file to tests users_privs filter
- name: Import tasks file to tests user_accounts filter
ansible.builtin.import_tasks:
file: filter_users_privs.yml
file: filter_user_accounts.yml