首页 > 代码库 > 使用ansible-playbook实现自动打包上线
使用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=http://www.mamicode.com/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=http://www.mamicode.com/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实现自动打包上线