  - name: install proxysql
    shell: yum install -y /tmp/envoyinstack/src/proxysql/proxysql-2.0.10-1-centos7.x86_64.rpm 
    with_nested:
     - "{{ ansible_all_ipv4_addresses }}"
     - "{{ mysql_proxysql_hosts }}"
    when: item[0] == item[1]

  - name: create /data/proxysql/proxysql
    file:
     path: /data/proxysql/proxysql
     state: directory
     mode: '0755'
     owner: proxysql
     group: proxysql
     recurse: yes
    with_nested:
     - "{{ ansible_all_ipv4_addresses }}"
     - "{{ mysql_proxysql_hosts }}"
    when: item[0] == item[1]

  - name: config /etc/proxysql.cnf for proxysql
    template:
     src: ../template/proxysql/proxysql.cnf
     dest: /etc/proxysql.cnf
     owner: proxysql
     group: proxysql
     backup: yes
    with_nested:
     - "{{ ansible_all_ipv4_addresses }}"
     - "{{ mysql_proxysql_hosts }}"
    when: item[0] == item[1]
 
  - name: transfer sql statement to remonte
    template:
     src: /tmp/envoyinstack/include/replmgr/deploy/ansible/mysql/template/config_proxysql.sql
     dest: /tmp/config_proxysql.sql
    with_nested:
     - "{{ ansible_all_ipv4_addresses }}"
     - "{{ mysql_proxysql_hosts }}"
    when: item[0] == item[1]

  - name: start proxysql
    service: name=proxysql state=started
    with_nested:
     - "{{ ansible_all_ipv4_addresses }}"
     - "{{ mysql_proxysql_hosts }}"
    when: item[0] == item[1]

  - name: config mysql proxysql group replication
    shell: source /etc/profile;mysql -uadmin -p{{ mysql_admin_password }} -h 127.0.0.1 -P6032 --prompt='Admin>'  < /tmp/config_proxysql.sql
    with_nested:
     - "{{ ansible_all_ipv4_addresses }}"
     - "{{ mysql_proxysql_hosts }}"
    when: item[0] == item[1]

  - name: remove temp file /tmp/config_proxysql.sql
    file:
     dest: /tmp/config_proxysql.sql
     state: absent
