Add default database "mysql" to mysql_user (#266)

* Add default database "mysql" to mysql_user

Since permissions are stored in the "mysql" database anyway this should not change the behaviour of the module. But replication / binlog filters which rely on the current database will be able to filter the statements correctly afterwards. Prior to this change they were not executed in any database context and could not be filtered in any way by the existing methods in MySQL.

* Added changelog fragment

* Update changelogs/fragments/266-default-database-for-mysql-user

Thanks!

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update mysql_user.py

Make the change a configureable boolean

* Update 266-default-database-for-mysql-user

update changelog fragment

* Update 266-default-database-for-mysql-user

it´s not a bugfix anymore

* Update plugins/modules/mysql_user.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/mysql_user.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/mysql_user.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/mysql_user.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* renamed new option to force_context
enhanced description
added tests

* fixed changelog

* Update plugins/modules/mysql_user.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update plugins/modules/mysql_user.py

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* added more tests

* removed first test attempts again (from issue-28.yml)
created new tests for testing with and without replication

* added force_context: no testing

* forgot to add the new part to main.yml

* found a copy&paste issue

* fix include naming

* Made sure the tests work in local testing

* MariaDB handles online replication filters differently

* fix changelog

* Update changelogs/fragments/266-default-database-for-mysql-user.yml

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

* Update changelogs/fragments/266-default-database-for-mysql-user.yml

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>

Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
This commit is contained in:
Daniel Rupp 2022-01-10 16:03:25 +01:00 committed by GitHub
parent 9c575b4762
commit f5e8fbb3f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 358 additions and 0 deletions

View file

@ -74,6 +74,19 @@ options:
- Whether binary logging should be enabled or disabled for the connection.
type: bool
default: yes
force_context:
description:
- Sets the С(mysql) system database as context for the executed statements (it will be used
as a database to connect to). Useful if you use binlog / replication filters in MySQL as
per default the statements can not be caught by a binlog / replication filter, they require
a database to be set to work, otherwise the replication can break down.
- See U(https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#option_mysqld_binlog-ignore-db)
for a description on how binlog filters work (filtering on the primary).
- See U(https://dev.mysql.com/doc/refman/8.0/en/replication-options-replica.html#option_mysqld_replicate-ignore-db)
for a description on how replication filters work (filtering on the replica).
type: bool
default: no
version_added: '3.1.0'
state:
description:
- Whether the user should exist.
@ -341,6 +354,7 @@ def main():
plugin_hash_string=dict(default=None, type='str'),
plugin_auth_string=dict(default=None, type='str'),
resource_limits=dict(type='dict'),
force_context=dict(type='bool', default=False),
)
module = AnsibleModule(
argument_spec=argument_spec,
@ -366,6 +380,8 @@ def main():
ssl_ca = module.params["ca_cert"]
check_hostname = module.params["check_hostname"]
db = ''
if module.params["force_context"]:
db = 'mysql'
sql_log_bin = module.params["sql_log_bin"]
plugin = module.params["plugin"]
plugin_hash_string = module.params["plugin_hash_string"]