配置RUNDECK+ANSIBLE实现websphere application server实现应用系统的自动更新

参照前面一篇文档,已经配置好了websphere application server发布应用

从SVN服务器自动下载WAR包,SVN服务器也已经配置好

ANSIBLE剧本如下:

[root@V71 gfp_svn]# pwd
/home/ansible/playbooks/gfp_svn
[root@V71 gfp_svn]# cat appcs.yml 
---
- hosts: "{{ dsthosts }}"
  remote_user: root
  vars:
    # 等待RUNDECK传参
    dsthosts: 192.168.156.71   
    
    #发布项目的文件夹的名称,等待RUNDECK传参
    appname: "ears"   

    #部署路径,等待RUNDECK传参
    was_path: "/tmps"
    
    #日志存放路径,等待RUNDECK传参
    waslog_path: "/app/WebSphere/AppServer/profiles/AppSrv01/logs/server1"
    
    #日志文件名
    systemlogout: "SystemOut.log"
    
    #错误日志文件名
    errorlogout: "SystemErr.log"
    
    #存放所有程序备份的目录
    allbakdir: "{{ was_path }}/{{ appname }}_releases"
    
    #启动服务的路径
    startserverpath: "/app/WebSphere/AppServer/profiles/AppSrv01/bin"

    #启动命令,等待RUNDECK传参
    start_cmd: "source /etc/profile; nohup {{ startserverpath }}/startServer.sh server1 &"

    #停止命令,等待RUNDECK传参,注意用户名密码参数正确才能停止WAS服务
    stop_cmd: "nohup {{ startserverpath }}/stopServer.sh server1 -username wasuser -password waspwd &"
   
    #SVN路径,等待RUNDECK传参
    svnaddress: "svn"

    #svn用户帐号
    svnuser: "svnuser"

    #svn密码,等待RUNDECK传参
    svnpwd: "failpwd"
   
    #war包存放在ansible服务器的临时路径
    localtmpwar: "/tmp/app/{{ appname }}.war"

    #war包存放在app服务器上面的路径
    apptmpwar: "/tmp/{{ appname }}.war"

    #war包解压到APP服务器存入的临时路径,等服务停止以后再移动到应用发布的目录
    apptmpdir: "/tmp/{{ appname }}tmp"

    #是否属于增量0表示全量,1表示增量,等待RUNDECK传参
    increment: "0"
    
    #svn的默认版本号,等待RUNDECK传参
    version: "head" 


  tasks:
  - name: copy form svn | 从svn下载
    subversion: repo="{{ svnaddress }}" dest="{{ localtmpwar }}" username="{{ svnuser }}" password="{{ svnpwd }}" export=yes force=yes revision="{{ version }}"
    delegate_to: localhost

  - name: copy to appservers | 拷贝到应用服务器
    copy: 
      src: "{{ localtmpwar }}" 
      dest: "{{ apptmpwar }}"
  
  - name: del apptmpdir      | 删除解压缩临时文件夹
    file:
      path: "{{ apptmpdir }}"
      state: absent
    ignore_errors: yes

  - name: createapptmpdir  |创建解压缩的文件夹 
    file:
      path: "{{ apptmpdir }}"
      state: directory
      mode: 0755
  
  - name: unarchive files  |解压缩 
    unarchive:
      src: "{{ apptmpwar }}"
      dest: "{{ apptmpdir }}"
      remote_src: yes
  
  - name: createbakname      | 生成备份文件夹的名称
    set_fact:
      formatdate: "{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}" 
      
  - name: createallbakdir    | 新建存放所有程序备份的目录,如果没有就创建
    file:
      path: "{{ allbakdir }}"
      state: directory
      mode: 0755

  - name: createincrementdir | 新建增量发布的备份文件夹
    file:
      path: "{{ allbakdir }}/{{ formatdate }}"
      state: directory
      mode: 0755 
    when: increment == "1"  

  - name: incrementbak       | 增量更新前备份旧程序
    shell: "cp -r {{ was_path }}/{{ appname }}/* {{ allbakdir }}/{{ formatdate }}/"
    when: increment == "1"
    
  - name: stopservice        | 停止服务
    shell: "{{ stop_cmd }}" 
    register: stopinfo
    ignore_errors: yes
    
  - name: sleep 10           | 休眠10秒
    shell: "sleep 10"  
           
  - name: print secondarystop|打印停止的信息
    debug: var=stopinfo
    ignore_errors: yes
    
  - name: backup logs        |备份日志
    command: "mv {{ waslog_path }}/{{ systemlogout }} {{ waslog_path }}/{{ systemlogout }}.{{ formatdate }}"
    ignore_errors: yes
    
  - name: backup errlogs        |备份错误日志
    command: "mv {{ waslog_path }}/{{ errorlogout }} {{ waslog_path }}/{{ errorlogout }}.{{ formatdate }}"
    ignore_errors: yes
    
    
  - name: mvbakoldapp     | 备份旧程序
    command: "mv {{ was_path }}/{{ appname }} {{ allbakdir }}/{{ formatdate }}"
    when: not increment == "1"
  
  - name: updateapp     | 更新程序
    command: "mv {{ apptmpdir }} {{ was_path }}/{{ appname }}"
    when: not increment == "1"

  - name: incrementupdate     | 增量更新
    shell: "cp -r {{ apptmpdir }}/* {{ was_path }}/{{ appname }}"
    when: increment == "1"   

  - name: startservice     | 启动服务
    shell: "{{ start_cmd }}"
    register: startup_out
    
  - name: echo startup_out    | 打印启动信息
    debug: var=startup_out
      
  - name: delincrementupdatefile | 删除已经被拷贝的增量更新的临时文件夹
    file:
      path: "{{ apptmpdir }}"
      state: absent
    when: increment == "1"

  - name: deloldbakfile      | 删除早于最近8个的备份文件
    shell: "ls -td {{ allbakdir }}/* | grep 201  | tail -n +9 | xargs rm -rf" 

 

 

RUNDECK作业配置如下,导出的XML格式文件

<joblist>
  <job>
    <context>
      <options preserveOrder='true'>
        <option name='appname' required='true' value='war1_war.ear'>
          <description>发布项目的文件夹的名称</description>
        </option>
        <option name='dsthosts' values='192.168.156.61'>
          <description>应用服务器</description>
        </option>
        <option name='svnaddress' required='true'>
          <description>SVN路径必填</description>
        </option>
        <option name='increment' required='true' value='0' values='0,1'>
          <description>是否属于增量0表示全量,1表示增量</description>
        </option>
        <option name='version' required='true' value='head'>
          <description>svn的默认版本号</description>
        </option>
        <option name='startserverpath' required='true' value='/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/bin'>
          <description>启动停止服务的路径</description>
        </option>
        <option name='svnpwd' secure='true' storagePath='keys/svnpw/svnpw' valueExposed='true'>
          <description>svn密码</description>
        </option>
        <option name='was_path' required='true' value='/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/installedApps/v61Cell01'>
          <description>was_path的部署路径</description>
        </option>
        <option name='waslog_path' value='/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/logs/server1'>
          <description>日志的路径</description>
        </option>
      </options>
    </context>
    <defaultTab>summary</defaultTab>
    <description>APP应用更新</description>
    <executionEnabled>true</executionEnabled>
    <group>runjobs</group>
    <id>28fac9a5-194f-4a11-8539-13032f8ae7db</id>
    <loglevel>INFO</loglevel>
    <name>APP应用更新</name>
    <nodeFilterEditable>false</nodeFilterEditable>
    <scheduleEnabled>true</scheduleEnabled>
    <sequence keepgoing='false' strategy='node-first'>
      <command>
        <exec>ansible-playbook  /home/ansible/playbooks/gfp_svn/appcs.yml --extra-vars "dsthosts=${option.dsthosts} appname=${option.appname} was_path=${option.was_path} startserverpath=${option.startserverpath} waslog_path=${option.waslog_path} svnaddress=${option.svnaddress} increment=${option.increment} version=${option.version} svnpwd=$RD_OPTION_SVNPWD" </exec>
      </command>
    </sequence>
    <uuid>28fac9a5-194f-4a11-8539-13032f8ae7db</uuid>
  </job>
</joblist>

 

运行界面和效果大致如下:

 

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页