######################################################################
#### function: install ansible
####author:danial_chen
####create date:2019-11-07
####modify date:2019-11-07
######################################################################
#/bin/bash
pd=$PWD
#USER_INSTALL_DIR=`cat $pd/config |grep USER_INSTALL_DIR= |awk -F "=" '{print $2}'|sed 's/ //g'`
USER_INSTALL_DIR=$1

##安装ansible##
echo "Now installing ansible..."
echo "=============================================================="
if [ `ansible --version | awk -F' ' 'NR==1 {print $1}'` == ansible ];then
   echo "`ansible --version | awk -F' ' 'NR==1 {print}'`"
else
   rpm -Uvh $pd/kingdeetmp/ansible/*.rpm --nodeps --force
   if [ $? -eq 1 ];then
	  exit 1
   fi
fi
mkdir -p /etc/ansible
/bin/cp -R -f $pd/ansible/* /etc/ansible/

## update /etc/ansible/*.yaml ##
sed -i s#[$]USER_INSTALL_DIR[$]#$pd#g /etc/ansible/ansible.cfg

#sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/k8e.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/sys_parm.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/dependencies.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/mysql.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/jdk.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/zookeeper.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/rabbitmq.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/redis_cache.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/redis_session.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/redis_algo.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/nginx.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/appstatic.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/mdd.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/mservice.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/mservice-k8s.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/mc.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/mc-k8s.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/mservice-qing.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/mservice-qing-k8s.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/fileserver.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/fileserver-k8s.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/kafka.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/elasticsearch.yaml
sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/logstash.yaml
#sed -i s#[$]KINGDEETMP_DIR[$]#$pd#g /etc/ansible/roles/k8s13x/tasks/main.yaml

#sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/k8e.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/sys_parm.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/dependencies.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/mysql.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/jdk.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/zookeeper.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/rabbitmq.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/redis_cache.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/redis_session.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/redis_algo.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/nginx.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/appstatic.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/mdd.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/mservice.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/mservice-k8s.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/mc.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/mc-k8s.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/mservice-qing.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/mservice-qing-k8s.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/fileserver.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/fileserver-k8s.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/kafka.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/elasticsearch.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/logstash.yaml
sed -i s#[$]USER_INSTALL_DIR[$]#$USER_INSTALL_DIR#g /etc/ansible/roles/docker_kubeadm/tasks/main.yaml
