ansible远程执行
拷贝开发环境代码到测试环境中并执行相关服务。
前置条件
- 开发环境工具和配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$ yum install -y ansible dos2unix $ vi hosts [server] 1.1.1.108 [compute1] 2.2.2.21 [compute2] 3.3.3.13 [compute] 4.4.4.3 4.4.4.2 |
- 密钥授权
将开发环境机器中公钥中XXX.pub内容,拷贝到测试环境机器中
1 2 3 4 |
#开发环境机器 cat ~/.ssh/id_rsa.pub #测试环境机器 vi ~/.ssh/authorized_keys |
执行脚本
创建并执行以下脚本,确认文件路径正确
1 2 3 4 5 |
cd ${APPPATH}/bin dos2unix build.sh bash build.sh ansible -i /root/hosts compute -m copy -a "${APPPATH}/appname" ansible -i /root/hosts compute -m shell -a "systemctl restart app-name" |
微信赞赏
支付宝赞赏