---
 - name: transfer sql to remonte host
   template: 
    src: /tmp/envoyinstack/include/replmgr/deploy/ansible/mysql/template/config_multi_source_replication.sql
    dest: /tmp/config_mutli_source_replication.sql

 - name: register mysql_root_password
   shell: /usr/bin/cat /tmp/envoyinstack/include/replmgr/config.yaml |grep ^mysql_root_password|awk -F ' ' '{print $2}'
   register: mysql_root_password 

 - name: restart slave mysqld
   service: name=mysqld state=restarted
   with_nested:
    - "{{ ansible_all_ipv4_addresses }}"
    - "{{ slave_ip }}"
   when: item[0] == item[1]

 - name: create multi source replication user on master / start slave on slave
   when:
   shell: source /etc/profile;mysql -hlocalhost -uroot -p{{ mysql_root_password.stdout }} -S /tmp/mysql.sock  < /tmp/config_mutli_source_replication.sql

 - name: restart mysqld
   service: name=mysqld state=restarted

 - name: clear temp file /tmp/config_mutli_source_replication.sql
   file:
    dest: /tmp/config_mutli_source_replication.sql
    state: absent
