mysql_replication - accept empty string to the module's parameters (#63546)

pull/63957/head
Andrey Klychkov 5 years ago committed by Sam Doran
parent cdb7ab61a0
commit 88af9f6470

@ -0,0 +1,2 @@
bugfixes:
- mysql_replication - allow to pass empty values to parameters (https://github.com/ansible/ansible/issues/23976).

@ -147,6 +147,9 @@ options:
type: str type: str
version_added: '2.10' version_added: '2.10'
notes:
- If an empty value for the parameter of string type is needed, use an empty string.
extends_documentation_fragment: extends_documentation_fragment:
- mysql - mysql
@ -454,37 +457,37 @@ def main():
elif mode in "changemaster": elif mode in "changemaster":
chm = [] chm = []
result = {} result = {}
if master_host: if master_host is not None:
chm.append("MASTER_HOST='%s'" % master_host) chm.append("MASTER_HOST='%s'" % master_host)
if master_user: if master_user is not None:
chm.append("MASTER_USER='%s'" % master_user) chm.append("MASTER_USER='%s'" % master_user)
if master_password: if master_password is not None:
chm.append("MASTER_PASSWORD='%s'" % master_password) chm.append("MASTER_PASSWORD='%s'" % master_password)
if master_port is not None: if master_port is not None:
chm.append("MASTER_PORT=%s" % master_port) chm.append("MASTER_PORT=%s" % master_port)
if master_connect_retry is not None: if master_connect_retry is not None:
chm.append("MASTER_CONNECT_RETRY=%s" % master_connect_retry) 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) chm.append("MASTER_LOG_FILE='%s'" % master_log_file)
if master_log_pos is not None: if master_log_pos is not None:
chm.append("MASTER_LOG_POS=%s" % master_log_pos) chm.append("MASTER_LOG_POS=%s" % master_log_pos)
if master_delay is not None: if master_delay is not None:
chm.append("MASTER_DELAY=%s" % master_delay) 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) chm.append("RELAY_LOG_FILE='%s'" % relay_log_file)
if relay_log_pos is not None: if relay_log_pos is not None:
chm.append("RELAY_LOG_POS=%s" % relay_log_pos) chm.append("RELAY_LOG_POS=%s" % relay_log_pos)
if master_ssl: if master_ssl:
chm.append("MASTER_SSL=1") 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) 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) 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) 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) 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) chm.append("MASTER_SSL_CIPHER='%s'" % master_ssl_cipher)
if master_auto_position: if master_auto_position:
chm.append("MASTER_AUTO_POSITION=1") chm.append("MASTER_AUTO_POSITION=1")

@ -33,6 +33,8 @@
- master_status is not changed - master_status is not changed
# Test changemaster mode: # 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 - name: Run replication
mysql_replication: mysql_replication:
login_host: 127.0.0.1 login_host: 127.0.0.1
@ -44,12 +46,13 @@
master_password: "{{ replication_pass }}" master_password: "{{ replication_pass }}"
master_log_file: "{{ master_status.File }}" master_log_file: "{{ master_status.File }}"
master_log_pos: "{{ master_status.Position }}" master_log_pos: "{{ master_status.Position }}"
master_ssl_ca: ''
register: result register: result
- assert: - assert:
that: that:
- result is changed - 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: # Test startslave mode:
- name: Start slave - name: Start slave

Loading…
Cancel
Save