#!/bin/bash
# Author:  EinicYeo <einicyeo AT gmail.com>
# BLOG:  https://www.infvie.com
#
# Notes: EnvoyinStack for CentOS/RedHat 6+

cat > /root/.ssh/config <<EOF
Host *
ControlPersist yes
ControlPersist 2h
ControlMaster auto
ControlPath ~/.ssh/%r@%h-%p
Compression yes
EOF

cat > /etc/ansible/ansible.cfg <<EOF
[defaults]
forks = 10
poll_interval = 15 
executable = /usr/bin/bash
hash_behaviour = replace
nocolor = 0
inventory=./inventory
pipelining=True
host_key_checking = False
command_warnings=False
use_tty = False
scp_if_ssh=False
gathering = smart
fact_caching_timeout = 86400
fact_caching = jsonfile
fact_caching_connection = /etc/ansible/ansible_fact_cache
EOF

/usr/bin/cat tools/iplist.txt|awk '{print $1}'|awk -F '.' '{print "mysql0"NR"-"$4,"hostname=mysql0"NR"-"$4,"ansible_host="$0}' >/etc/ansible/inventory && /usr/local/python/bin/ansible all -m hostname -a 'name={{ hostname }}'


Install_master_slaves() {
 pushd ${envoyinstack_dir}/include/replmgr/deploy/ansible/mysql/ >/dev/null
 ${python_install_dir}/bin/ansible-playbook install_master_slaves.yaml
 popd
}

Install_multi_source_replication() {
 pushd ${envoyinstack_dir}/include/replmgr/deploy/ansible/mysql/ >/dev/null
 ${python_install_dir}/bin/ansible-playbook install_multi_source_replication.yaml
 popd
} 

Install_ProxysqlMgr() { 
 pushd ${envoyinstack_dir}/include/replmgr/deploy/ansible/mysql/ >/dev/null
 ${python_install_dir}/bin/ansible-playbook install_group_replication.yaml
 popd
}

