change filter name to users_info

This commit is contained in:
Laurent Indermuehle 2023-10-13 15:00:21 +02:00
parent 070109e70d
commit e61777cffb
No known key found for this signature in database
GPG key ID: 93FA944C9F34DD09
7 changed files with 107 additions and 107 deletions

View file

@ -0,0 +1,5 @@
---
minor_changes:
- mysql_info - add filter ``users_info`` (https://github.com/ansible-collections/community.mysql/pull/572).

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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