mysql_db: Add support for sql_log_bin option (#723)
Some checks are pending
Plugins CI / Sanity (Ⓐdevel) (push) Waiting to run
Plugins CI / Sanity (Ⓐstable-2.17) (push) Waiting to run
Plugins CI / Sanity (Ⓐstable-2.18) (push) Waiting to run
Plugins CI / Sanity (Ⓐstable-2.19) (push) Waiting to run
Plugins CI / Integration (Ⓐdevel, DB: mariadb 11.4.5, connector: mysqlclient 2.0.1) (push) Waiting to run
Plugins CI / Integration (Ⓐdevel, DB: mariadb 11.4.5, connector: mysqlclient 2.0.3) (push) Waiting to run
Plugins CI / Integration (Ⓐdevel, DB: mariadb 11.4.5, connector: mysqlclient 2.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐdevel, DB: mysql 8.4.1, connector: mysqlclient 2.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐdevel, DB: mariadb 11.4.5, connector: pymysql 0.9.3) (push) Waiting to run
Plugins CI / Integration (Ⓐdevel, DB: mariadb 11.4.5, connector: pymysql 1.0.2) (push) Waiting to run
Plugins CI / Integration (Ⓐdevel, DB: mariadb 11.4.5, connector: pymysql 1.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐdevel, DB: mysql 8.4.1, connector: pymysql 1.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.16, DB: mariadb 10.11.8, connector: pymysql 0.10.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.17, DB: mariadb 11.4.5, connector: mysqlclient 2.0.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.17, DB: mariadb 11.4.5, connector: mysqlclient 2.0.3) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.17, DB: mariadb 11.4.5, connector: mysqlclient 2.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.17, DB: mysql 8.4.1, connector: mysqlclient 2.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.17, DB: mariadb 11.4.5, connector: pymysql 0.9.3) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.17, DB: mariadb 11.4.5, connector: pymysql 1.0.2) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.17, DB: mariadb 11.4.5, connector: pymysql 1.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.17, DB: mysql 8.4.1, connector: pymysql 1.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mariadb 11.4.5, connector: mysqlclient 2.0.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mysql 8.0.38, connector: mysqlclient 2.0.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mariadb 10.11.8, connector: mysqlclient 2.0.3) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mariadb 11.4.5, connector: mysqlclient 2.0.3) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mysql 8.0.38, connector: mysqlclient 2.0.3) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mariadb 10.11.8, connector: mysqlclient 2.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mariadb 11.4.5, connector: mysqlclient 2.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mysql 8.0.38, connector: mysqlclient 2.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mysql 8.4.1, connector: mysqlclient 2.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mariadb 11.4.5, connector: pymysql 0.9.3) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mysql 8.0.38, connector: pymysql 0.9.3) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mariadb 11.4.5, connector: pymysql 1.0.2) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mysql 8.0.38, connector: pymysql 1.0.2) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mariadb 11.4.5, connector: pymysql 1.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.18, DB: mysql 8.4.1, connector: pymysql 1.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mariadb 11.4.5, connector: mysqlclient 2.0.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mysql 8.0.38, connector: mysqlclient 2.0.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mariadb 10.11.8, connector: mysqlclient 2.0.3) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mariadb 11.4.5, connector: mysqlclient 2.0.3) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mysql 8.0.38, connector: mysqlclient 2.0.3) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mariadb 10.11.8, connector: mysqlclient 2.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mariadb 11.4.5, connector: mysqlclient 2.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mysql 8.0.38, connector: mysqlclient 2.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mysql 8.4.1, connector: mysqlclient 2.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mariadb 11.4.5, connector: pymysql 0.9.3) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mysql 8.0.38, connector: pymysql 0.9.3) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mariadb 11.4.5, connector: pymysql 1.0.2) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mysql 8.0.38, connector: pymysql 1.0.2) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mariadb 11.4.5, connector: pymysql 1.1.1) (push) Waiting to run
Plugins CI / Integration (Ⓐstable-2.19, DB: mysql 8.4.1, connector: pymysql 1.1.1) (push) Waiting to run
Plugins CI / Units (Ⓐdevel, Python3.10) (push) Waiting to run
Plugins CI / Units (Ⓐdevel, Python3.11) (push) Waiting to run
Plugins CI / Units (Ⓐstable-2.18, Python3.10) (push) Waiting to run
Plugins CI / Units (Ⓐstable-2.18, Python3.11) (push) Waiting to run
Plugins CI / Units (Ⓐstable-2.18, Python3.8) (push) Waiting to run
Plugins CI / Units (Ⓐstable-2.18, Python3.9) (push) Waiting to run
Plugins CI / Units (Ⓐstable-2.19, Python3.10) (push) Waiting to run
Plugins CI / Units (Ⓐstable-2.19, Python3.11) (push) Waiting to run
Plugins CI / Units (Ⓐstable-2.19, Python3.9) (push) Waiting to run

This commit is contained in:
Yves Heitz 2025-07-14 08:38:51 +02:00 committed by GitHub
parent 105f9fd1ce
commit 83ad0e81e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 109 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
minor_changes:
- mysql_db - Add support for ``sql_log_bin`` option (https://github.com/ansible-collections/community.mysql/issues/700).

View file

@ -165,6 +165,11 @@ options:
type: bool
default: false
version_added: '3.4.0'
sql_log_bin:
description:
- Whether binary logging should be enabled or disabled for the connection.
type: bool
default: true
seealso:
- module: community.mysql.mysql_info
@ -633,6 +638,7 @@ def main():
config_overrides_defaults=dict(type='bool', default=False),
chdir=dict(type='path'),
pipefail=dict(type='bool', default=False),
sql_log_bin=dict(type='bool', default=True),
)
module = AnsibleModule(
@ -683,6 +689,7 @@ def main():
config_overrides_defaults = module.params['config_overrides_defaults']
chdir = module.params['chdir']
pipefail = module.params['pipefail']
sql_log_bin = module.params["sql_log_bin"]
if chdir:
try:
@ -725,6 +732,9 @@ def main():
else:
module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, to_native(e)))
if state in ['absent', 'present'] and not sql_log_bin:
cursor.execute("SET SQL_LOG_BIN=0;")
server_implementation = get_server_implementation(cursor)
server_version = get_server_version(cursor)

View file

@ -310,3 +310,99 @@
assert:
that:
- db_user1 not in result.stdout
# ============================================================
- set_fact:
show_master_status: >-
{% if db_engine == 'mariadb' and db_version is version('10.5.2', '>=') %}
SHOW BINLOG STATUS
{% elif db_engine == 'mysql' and db_version is version('8.4', '>=') %}
SHOW BINARY LOG STATUS
{% else %}
SHOW MASTER STATUS
{% endif %}
- name: State Present Absent | Capture binlog position
command: "{{ mysql_command }} -e \"{{ show_master_status }}\\G\""
register: bin_log_position_1
- name: State Present Absent | Create database with sql_log_bin enabled
mysql_db:
login_user: '{{ mysql_user }}'
login_password: '{{ mysql_password }}'
login_host: '{{ mysql_host }}'
login_port: '{{ mysql_primary_port }}'
name: 'sql_bin_on_{{ db_name }}'
sql_log_bin: true
state: present
- name: State Present Absent | Capture binlog position
command: "{{ mysql_command }} -e \"{{ show_master_status }}\\G\""
register: bin_log_position_2
- name: State Present Absent | Assert binlog events were written
assert:
that:
- bin_log_position_1.stdout_lines[2] != bin_log_position_2.stdout_lines[2]
- name: State Present Absent | Remove database with sql_log_bin enabled
mysql_db:
login_user: '{{ mysql_user }}'
login_password: '{{ mysql_password }}'
login_host: '{{ mysql_host }}'
login_port: '{{ mysql_primary_port }}'
name: 'sql_bin_on_{{ db_name }}'
sql_log_bin: true
state: absent
- name: State Present Absent | Capture binlog position
command: "{{ mysql_command }} -e \"{{ show_master_status }}\\G\""
register: bin_log_position_3
- name: State Present Absent | Assert Binlog events were written
assert:
that:
- bin_log_position_2.stdout_lines[2] != bin_log_position_3.stdout_lines[2]
# ============================================================
- name: State Present Absent | Capture binlog position
command: "{{ mysql_command }} -e \"{{ show_master_status }}\\G\""
register: bin_log_position_4
- name: State Present Absent | Create database with sql_log_bin disabled
mysql_db:
login_user: '{{ mysql_user }}'
login_password: '{{ mysql_password }}'
login_host: '{{ mysql_host }}'
login_port: '{{ mysql_primary_port }}'
name: 'sql_bin_off_{{ db_name }}'
sql_log_bin: false
state: present
- name: State Present Absent | Capture binlog position
command: "{{ mysql_command }} -e \"{{ show_master_status }}\\G\""
register: bin_log_position_5
- name: State Present Absent | Assert binlog events were not written
assert:
that:
- bin_log_position_4.stdout_lines[2] == bin_log_position_5.stdout_lines[2]
- name: State Present Absent | Remove database with sql_log_bin disabled
mysql_db:
login_user: '{{ mysql_user }}'
login_password: '{{ mysql_password }}'
login_host: '{{ mysql_host }}'
login_port: '{{ mysql_primary_port }}'
name: 'sql_bin_off_{{ db_name }}'
sql_log_bin: false
state: absent
- name: State Present Absent | Capture binlog position
command: "{{ mysql_command }} -e \"{{ show_master_status }}\\G\""
register: bin_log_position_6
- name: State Present Absent | Assert Binlog events were not written
assert:
that:
- bin_log_position_5.stdout_lines[2] == bin_log_position_6.stdout_lines[2]