@@ -159,9 +159,10 @@ def start_slave(cursor):
159159 return started
160160
161161
162- def changemaster (cursor , chm ):
163- SQLPARAM = "," .join (chm )
164- cursor .execute ("CHANGE MASTER TO " + SQLPARAM )
162+ def changemaster (cursor , chm , chm_params ):
163+ sql_param = "," .join (chm )
164+ query = 'CHANGE MASTER TO %s' % sql_param
165+ cursor .execute (query , chm_params )
165166
166167
167168def strip_quotes (s ):
@@ -318,37 +319,52 @@ def main():
318319 elif mode in "changemaster" :
319320 print "Change master"
320321 chm = []
322+ chm_params = {}
321323 if master_host :
322- chm .append ("MASTER_HOST='" + master_host + "'" )
324+ chm .append ("MASTER_HOST=%(master_host)s" )
325+ chm_params ['master_host' ] = master_host
323326 if master_user :
324- chm .append ("MASTER_USER='" + master_user + "'" )
327+ chm .append ("MASTER_USER=%(master_user)s" )
328+ chm_params ['master_user' ] = master_user
325329 if master_password :
326- chm .append ("MASTER_PASSWORD='" + master_password + "'" )
330+ chm .append ("MASTER_PASSWORD=%(master_password)s" )
331+ chm_params ['master_password' ] = master_password
327332 if master_port :
328- chm .append ("MASTER_PORT=" + master_port )
333+ chm .append ("MASTER_PORT=%(master_port)s" )
334+ chm_params ['master_port' ] = master_port
329335 if master_connect_retry :
330- chm .append ("MASTER_CONNECT_RETRY='" + master_connect_retry + "'" )
336+ chm .append ("MASTER_CONNECT_RETRY=%(master_connect_retry)s" )
337+ chm_params ['master_connect_retry' ] = master_connect_retry
331338 if master_log_file :
332- chm .append ("MASTER_LOG_FILE='" + master_log_file + "'" )
339+ chm .append ("MASTER_LOG_FILE=%(master_log_file)s" )
340+ chm_params ['master_log_file' ] = master_log_file
333341 if master_log_pos :
334- chm .append ("MASTER_LOG_POS=" + master_log_pos )
342+ chm .append ("MASTER_LOG_POS=%(master_log_pos)s" )
343+ chm_params ['master_log_pos' ] = master_log_pos
335344 if relay_log_file :
336- chm .append ("RELAY_LOG_FILE='" + relay_log_file + "'" )
345+ chm .append ("RELAY_LOG_FILE=%(relay_log_file)s" )
346+ chm_params ['relay_log_file' ] = relay_log_file
337347 if relay_log_pos :
338- chm .append ("RELAY_LOG_POS=" + relay_log_pos )
348+ chm .append ("RELAY_LOG_POS=%(relay_log_pos)s" )
349+ chm_params ['relay_log_pos' ] = relay_log_pos
339350 if master_ssl :
340351 chm .append ("MASTER_SSL=1" )
341352 if master_ssl_ca :
342- chm .append ("MASTER_SSL_CA='" + master_ssl_ca + "'" )
353+ chm .append ("MASTER_SSL_CA=%(master_ssl_ca)s" )
354+ chm_params ['master_ssl_ca' ] = master_ssl_ca
343355 if master_ssl_capath :
344- chm .append ("MASTER_SSL_CAPATH='" + master_ssl_capath + "'" )
356+ chm .append ("MASTER_SSL_CAPATH=%(master_ssl_capath)s" )
357+ chm_params ['master_ssl_capath' ] = master_ssl_capath
345358 if master_ssl_cert :
346- chm .append ("MASTER_SSL_CERT='" + master_ssl_cert + "'" )
359+ chm .append ("MASTER_SSL_CERT=%(master_ssl_cert)s" )
360+ chm_params ['master_ssl_cert' ] = master_ssl_cert
347361 if master_ssl_key :
348- chm .append ("MASTER_SSL_KEY='" + master_ssl_key + "'" )
362+ chm .append ("MASTER_SSL_KEY=%(master_ssl_key)s" )
363+ chm_params ['master_ssl_key' ] = master_ssl_key
349364 if master_ssl_cipher :
350- chm .append ("MASTER_SSL_CIPHER='" + master_ssl_cipher + "'" )
351- changemaster (cursor ,chm )
365+ chm .append ("MASTER_SSL_CIPHER=%(master_ssl_cipher)s" )
366+ chm_params ['master_ssl_cipher' ] = master_ssl_cipher
367+ changemaster (cursor , chm , chm_params )
352368 module .exit_json (changed = True )
353369 elif mode in "startslave" :
354370 started = start_slave (cursor )
@@ -366,4 +382,4 @@ def main():
366382# import module snippets
367383from ansible .module_utils .basic import *
368384main ()
369- warnings .simplefilter ("ignore" )
385+ warnings .simplefilter ("ignore" )
0 commit comments