ansible结合playbook批量部署war包项目上线

批量部署jenkins.war包实现上线

用于测试war包上线

[root~localhost]~#vim /etc/ansible/test.yml

- hosts: test

  vars:     tomcat: /usr/local/tomcat8   

remote_user: root  

tasks:    - name: "创建备份目录backup"     

file: dest={{ tomcat }}/backup owner=root group=root state=directory mode=0755     

ignore_errors: True   

- name: "创建新war包所在的目录newwar"     

file:          

dest={{ tomcat }}/newwar owner=root group=root state=directory mode=0755     

ignore_errors: True   

#- name: "备份旧的 war"     

#shell: cp -r {{ tomcat }}/webapps/test.war  {{ tomcat }}/backup/test-`date '+%F'`.war   

- name: "拷贝新的war包到远程服务器,把war包位置放在创建的新目录下"     

copy:       

src=/tmp/jenkins.war       

dest={{ tomcat }}/newwar   

- name: "停止tomcat服务"     

shell: ps -ef | grep tomcat | grep {{ tomcat }} | grep -v grep | awk '{print $2}' | xargs kill -9     

tags: stop     

ignore_errors: True   

#- name: "删除webapps下旧war包"     

#file: dest={{ tomcat }}/webapps/test.war state=absent   

- name: "拷贝新的war包到webapps"     

shell: mv {{ tomcat }}/newwar/jenkins.war {{ tomcat }}/webapps

#  - name: "删除临时文件"     

#shell: rm -rf {{ tomcat }}/temp/*  

#- name: "删除项目缓存"     

#shell: rm -rf {{ tomcat }}/work/Catalina/localhost/test

   - name: "启动tomcat服务"     

shell: nohup {{ tomcat }}/bin/startup.sh &

[root~localhost]#~ ansible-playbook /etc/ansible/test.yml

每台机器才执行一下启动,脚本启动shell模块不支持

[root~localhost]#~/usr/local/tomcat8/bin/startup.sh

访问http://192.168.30.21:8080/jenkins

 

posted @ 2019-06-18 16:30  #赵程#  阅读(1142)  评论(0编辑  收藏  举报