zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    ubuntu下如何更改mysql数据存放路径
    collection_select
    发现星期六日的电视比较好看
    rails
    系统抢救10.04
    劫后重生,痛定思痛,ubuntu 10.04=>10.10
    随机查询N条记录
    which linux your like
    kindeditor的使用
    array
  • 原文地址:https://www.cnblogs.com/zc1741845455/p/11045937.html
Copyright © 2011-2022 走看看