Repository: ansible/ansible-modules-extras

Issue:
mysql_replication module:  warning from MySQLdb.Warning result in failed task
##### Issue Type:

Bug Report
##### Ansible Version:

ansible --version
ansible 1.9.2
  configured module search path = None
##### Ansible Configuration:

```
[defaults]
# smart - gather by default, but don't regather if already gathered
# implicit - gather by default, turn off with gather_facts: False
# explicit - do not gather by default, must say gather_facts: True
gathering = smart

# if set to a persistant type (not 'memory', for example 'redis') fact values
# from previous runs in Ansible will be stored.  This may be useful when
# wanting to use, for example, IP information from one group of servers
# without having to talk to them in the same playbook run to get their
# current IP information.
# fact_caching = memory

fact_caching = jsonfile
fact_caching_connection = /tmp/ansiblefacts

```
##### Environment:

Running from Debian 8
Managing Debian 8
##### Summary:

When running a playbook to setup MySQL replication with a task doing  mode=changemaster the task failed, after a warning from MySQLdb. The warning complains about "Sending passwords in plain text without SSL/TLS is extremely insecure"
##### Steps To Reproduce:

Create a playbook to setup mysql and replication with a task like this which should be run on slave MySQL to declare the master host : 

```
- name: Change the master in slave to start the replication
  mysql_replication: mode=changemaster master_host={{ mysql_repl_master }} master_log_file={{ repl_stat.File }} master_log_pos={{ repl_stat.Position }} master_user={{ mysql_replication_user }} master_password={{ mysql_replication_user_password }}
```
##### Expected Results:

```
TASK: [mysql | Change the master in slave to start the replication] *** 
changed: [mysql2.preprod]
```
##### Actual Results:

```
failed: [mysql2.preprod] => {"failed": true, "parsed": false}
Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-tmp-1437058776.53-24949336144903/mysql_replication", line 2001, in <module>
    main()
  File "/root/.ansible/tmp/ansible-tmp-1437058776.53-24949336144903/mysql_replication", line 379, in main
    changemaster(cursor, chm, chm_params)
  File "/root/.ansible/tmp/ansible-tmp-1437058776.53-24949336144903/mysql_replication", line 174, in changemaster
    cursor.execute(query, chm_params)
  File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 176, in execute
    if not self._defer_warnings: self._warning_check()
  File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 92, in _warning_check
    warn(w[-1], self.Warning, 3)
_mysql_exceptions.Warning: Sending passwords in plain text without SSL/TLS is extremely insecure.

```



Discussion:
@jimi-c Here is the new issue ;-)

This fix was necessary for me as well (@banyek!)

Hey, is this still ongoing?

No idea.

Still seeing this on Ansible 2.0.0.2

The warnings will remain. we have to have this patch to work with all mysql environments.

Issue still on Ansible 2.1.0.0


Resolving patch:
diff --git a/database/mysql/mysql_replication.py b/database/mysql/mysql_replication.py
--- a/database/mysql/mysql_replication.py
+++ b/database/mysql/mysql_replication.py
@@ -274,6 +274,7 @@ def main():
     elif mode in "changemaster":
         chm=[]
         chm_params = {}
+        result = {}
         if master_host:
             chm.append("MASTER_HOST=%(master_host)s")
             chm_params['master_host'] = master_host
@@ -322,9 +323,12 @@ def main():
             chm.append("MASTER_AUTO_POSITION = 1")
         try:
             changemaster(cursor, chm, chm_params)
+        except MySQLdb.Warning, e:
+                result['warning'] = str(e)
         except Exception, e:
             module.fail_json(msg='%s. Query == CHANGE MASTER TO %s' % (e, chm))
-        module.exit_json(changed=True)
+        result['changed']=True
+        module.exit_json(**result)
     elif mode in "startslave":
         started = start_slave(cursor)
         if started is True:


Test patch: