From 88af9f64709430695d4c5bf3f1445d7aafc74241 Mon Sep 17 00:00:00 2001 From: Andrey Klychkov Date: Fri, 25 Oct 2019 18:56:40 +0300 Subject: [PATCH] mysql_replication - accept empty string to the module's parameters (#63546) --- ...replication_allow_to_pass_empty_values.yml | 2 ++ .../database/mysql/mysql_replication.py | 23 +++++++++++-------- .../tasks/mysql_replication_initial.yml | 5 +++- 3 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 changelogs/fragments/63546-mysql_replication_allow_to_pass_empty_values.yml diff --git a/changelogs/fragments/63546-mysql_replication_allow_to_pass_empty_values.yml b/changelogs/fragments/63546-mysql_replication_allow_to_pass_empty_values.yml new file mode 100644 index 00000000000..801bda2f9e9 --- /dev/null +++ b/changelogs/fragments/63546-mysql_replication_allow_to_pass_empty_values.yml @@ -0,0 +1,2 @@ +bugfixes: +- mysql_replication - allow to pass empty values to parameters (https://github.com/ansible/ansible/issues/23976). diff --git a/lib/ansible/modules/database/mysql/mysql_replication.py b/lib/ansible/modules/database/mysql/mysql_replication.py index 9c261a43508..c5e1c099ecf 100644 --- a/lib/ansible/modules/database/mysql/mysql_replication.py +++ b/lib/ansible/modules/database/mysql/mysql_replication.py @@ -147,6 +147,9 @@ options: type: str version_added: '2.10' +notes: +- If an empty value for the parameter of string type is needed, use an empty string. + extends_documentation_fragment: - mysql @@ -454,37 +457,37 @@ def main(): elif mode in "changemaster": chm = [] result = {} - if master_host: + if master_host is not None: chm.append("MASTER_HOST='%s'" % master_host) - if master_user: + if master_user is not None: chm.append("MASTER_USER='%s'" % master_user) - if master_password: + if master_password is not None: chm.append("MASTER_PASSWORD='%s'" % master_password) if master_port is not None: chm.append("MASTER_PORT=%s" % master_port) if master_connect_retry is not None: chm.append("MASTER_CONNECT_RETRY=%s" % master_connect_retry) - if master_log_file: + if master_log_file is not None: chm.append("MASTER_LOG_FILE='%s'" % master_log_file) if master_log_pos is not None: chm.append("MASTER_LOG_POS=%s" % master_log_pos) if master_delay is not None: chm.append("MASTER_DELAY=%s" % master_delay) - if relay_log_file: + if relay_log_file is not None: chm.append("RELAY_LOG_FILE='%s'" % relay_log_file) if relay_log_pos is not None: chm.append("RELAY_LOG_POS=%s" % relay_log_pos) if master_ssl: chm.append("MASTER_SSL=1") - if master_ssl_ca: + if master_ssl_ca is not None: chm.append("MASTER_SSL_CA='%s'" % master_ssl_ca) - if master_ssl_capath: + if master_ssl_capath is not None: chm.append("MASTER_SSL_CAPATH='%s'" % master_ssl_capath) - if master_ssl_cert: + if master_ssl_cert is not None: chm.append("MASTER_SSL_CERT='%s'" % master_ssl_cert) - if master_ssl_key: + if master_ssl_key is not None: chm.append("MASTER_SSL_KEY='%s'" % master_ssl_key) - if master_ssl_cipher: + if master_ssl_cipher is not None: chm.append("MASTER_SSL_CIPHER='%s'" % master_ssl_cipher) if master_auto_position: chm.append("MASTER_AUTO_POSITION=1") diff --git a/test/integration/targets/mysql_replication/tasks/mysql_replication_initial.yml b/test/integration/targets/mysql_replication/tasks/mysql_replication_initial.yml index 59d03c08d75..ce7c260c1e4 100644 --- a/test/integration/targets/mysql_replication/tasks/mysql_replication_initial.yml +++ b/test/integration/targets/mysql_replication/tasks/mysql_replication_initial.yml @@ -33,6 +33,8 @@ - master_status is not changed # Test changemaster mode: +# master_ssl_ca will be set as '' to check the module's behaviour for #23976, +# must be converted to an empty string - name: Run replication mysql_replication: login_host: 127.0.0.1 @@ -44,12 +46,13 @@ master_password: "{{ replication_pass }}" master_log_file: "{{ master_status.File }}" master_log_pos: "{{ master_status.Position }}" + master_ssl_ca: '' register: result - assert: that: - result is changed - - result.queries == ["CHANGE MASTER TO MASTER_HOST='127.0.0.1',MASTER_USER='replication_user',MASTER_PASSWORD='********',MASTER_PORT=3306,MASTER_LOG_FILE='{{ master_status.File }}',MASTER_LOG_POS={{ master_status.Position }}"] + - result.queries == ["CHANGE MASTER TO MASTER_HOST='127.0.0.1',MASTER_USER='replication_user',MASTER_PASSWORD='********',MASTER_PORT=3306,MASTER_LOG_FILE='{{ master_status.File }}',MASTER_LOG_POS={{ master_status.Position }},MASTER_SSL_CA=''"] # Test startslave mode: - name: Start slave