使用ansible-playbook实现自动打包上线
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用ansible-playbook实现自动打包上线相关的知识,希望对你有一定的参考价值。
- hosts: ceshi
remote_user: root
tasks:
- name: "192.168.55.14主机打包cms线上环境的war包"
script: /data/script/build_xianshang_cms.sh
- name: "从192.168.55.14拷贝war包到jenkins上"
fetch:
src=/buildwar/xianshang/cms/cms.war
dest=/var/www/html/deploy/packages/cms/
- hosts: xianshang_01:xianshang_02
remote_user: root
tasks:
- name: "从jenkins上传输到(xianshang_01),(xianshang_02)"
copy:
src=/var/www/html/deploy/packages/cms/192.168.55.14/buildwar/xianshang/cms/cms.war
dest=/data/cms/war/cms.war
- name: "得到cms进程号"
shell: APP_PID=$(ps -ef|grep cms|grep ‘java‘|awk ‘{print $2}‘)
- name: "杀掉cms进程"
shell: kill $APP_PID
- name: "进入cms的bak目录"
shell: cd /data/cms/bak
- name: "移动cms文件夹到/tmp目录下"
shell: mv cms /tmp/
- name: "进入cms的webapps目录"
shell: cd /data/cms/webapps/
- name: "移动cms文件夹到/data/cms/bak备份"
shell: mv cms /data/cms/bak/
- name: "移动cms.war包到/tmp目录下"
shell: mv cms.war /tmp/
- name: "进入/data/cms/war 线上包目录"
shell: cd /data/cms/war/
- name: "将cms.war包移动到/data/cms/wepapps"
shell: mv cms.war /data/cms/webapps/
- name: "进入/data/cms/bin"
shell: cd /data/cms/bin
- name: "启动cms工程"
shell: bash startup.sh
以上是关于使用ansible-playbook实现自动打包上线的主要内容,如果未能解决你的问题,请参考以下文章
ansible-playbook自动化安装Keepalived实现Nginx服务双机热备自动化配置