diff --git a/changelogs/fragments/266-default-database-for-mysql-user b/changelogs/fragments/266-default-database-for-mysql-user index c1a30b5..bad8b8e 100644 --- a/changelogs/fragments/266-default-database-for-mysql-user +++ b/changelogs/fragments/266-default-database-for-mysql-user @@ -1,2 +1,2 @@ minor_change: -- mysql_user - added the context_db boolean option to set the default database context for the queries to be the ``mysql`` database. This way replication/binlog filters can catch the statements (https://github.com/ansible-collections/community.mysql/issues/265). +- mysql_user - added the force_context boolean option to set the default database context for the queries to be the ``mysql`` database. This way replication/binlog filters can catch the statements (https://github.com/ansible-collections/community.mysql/issues/265). diff --git a/plugins/modules/mysql_user.py b/plugins/modules/mysql_user.py index cadf99c..4b371df 100644 --- a/plugins/modules/mysql_user.py +++ b/plugins/modules/mysql_user.py @@ -74,10 +74,16 @@ options: - Whether binary logging should be enabled or disabled for the connection. type: bool default: yes - db_context: + 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. + - 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. + - 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' @@ -348,7 +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'), - db_context=dict(type='bool', default=False), + force_context=dict(type='bool', default=False), ) module = AnsibleModule( argument_spec=argument_spec, @@ -374,7 +380,7 @@ def main(): ssl_ca = module.params["ca_cert"] check_hostname = module.params["check_hostname"] db = '' - if module.params["db_context"]: + if module.params["force_context"]: db = 'mysql' sql_log_bin = module.params["sql_log_bin"] plugin = module.params["plugin"] diff --git a/tests/integration/targets/test_mysql_replication/tasks/issue-28.yml b/tests/integration/targets/test_mysql_replication/tasks/issue-28.yml index 11e457b..eb2c20e 100644 --- a/tests/integration/targets/test_mysql_replication/tasks/issue-28.yml +++ b/tests/integration/targets/test_mysql_replication/tasks/issue-28.yml @@ -30,6 +30,7 @@ <<: *mysql_params name: '{{ user_name_1 }}' state: absent + force_context: yes ignore_errors: yes - name: create user with ssl requirement @@ -38,6 +39,7 @@ name: "{{ user_name_1 }}" password: "{{ user_password_1 }}" priv: '*.*:ALL,GRANT' + force_context: yes tls_requires: SSL: @@ -84,3 +86,4 @@ name: '{{ user_name_1 }}' host: 127.0.0.1 state: absent + force_context: yes