You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Ansible将WAR文件部署至IBM WebSphere?

Ansible 部署WAR文件到IBM WebSphere的Playbook示例

前提准备

  • 确保Ansible控制节点能SSH访问目标WebSphere服务器
  • 若使用官方模块,需提前安装ibm.websphere集合:ansible-galaxy collection install ibm.websphere
  • 拥有WebSphere管理员账号(具备应用部署、服务器启停权限)

方式一:使用官方ibm.websphere.was_app模块(推荐)

该模块是IBM官方维护的WebSphere管理模块,操作更规范可靠:

---
- name: 自动化部署WAR文件到WebSphere
  hosts: websphere_servers
  gather_facts: false
  tasks:
    - name: 将本地WAR文件传输至目标服务器临时目录
      copy:
        src: ./local/path/your_app.war
        dest: /tmp/your_app.war
        mode: '0644'

    - name: 部署/更新WebSphere应用
      ibm.websphere.was_app:
        state: present
        name: YourWebAppName
        source: /tmp/your_app.war
        target: "WebSphere:cell=YourCellName,node=YourNodeName,server=YourServerName"
        was_home: /opt/IBM/WebSphere/AppServer
        profile_name: AppSrv01
        username: websphere_admin
        password: admin_password

参数说明

  • state: present:表示部署新应用或更新已有应用;若需卸载可改为absent
  • name:WebSphere中显示的应用名称
  • target:WebSphere目标服务器的JNDI路径,需替换为实际的cell、node、server名称
  • was_home:WebSphere的安装根目录
  • profile_name:WebSphere使用的配置文件名称

方式二:使用wsadmin命令行(无官方模块时备选)

如果无法安装官方集合,可直接调用WebSphere自带的wsadmin工具执行部署:

---
- name: 用wsadmin部署WAR到WebSphere
  hosts: websphere_servers
  gather_facts: false
  tasks:
    - name: 将WAR文件传输至WebSphere可安装目录
      copy:
        src: ./local/path/your_app.war
        dest: /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/installableApps/your_app.war
        mode: '0644'

    - name: 执行wsadmin部署应用
      command: >
        /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/wsadmin.sh
        -username websphere_admin
        -password admin_password
        -lang jython
        -c "AdminApp.install('/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/installableApps/your_app.war', 
        '[ -appname YourWebAppName -server YourServerName ]')"
      register: deploy_output
      changed_when: "'ADMA5018I' in deploy_output.stdout"

    - name: 停止WebSphere服务器
      command: >
        /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/stopServer.sh YourServerName
        -username websphere_admin
        -password admin_password
      register: stop_result
      until: stop_result.rc == 0
      retries: 5
      delay: 10

    - name: 启动WebSphere服务器(加载新应用)
      command: >
        /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/startServer.sh YourServerName
      register: start_result
      until: start_result.rc == 0
      retries: 5
      delay: 10

关键说明

  • changed_when:通过WebSphere的成功日志标识ADMA5018I判断部署是否产生变更
  • until/retries/delay:确保服务器启停操作执行成功,避免因状态未同步导致的失败

注意事项

  • 所有占位符(如websphere_servers、YourCellName、管理员账号密码等)需替换为实际环境信息
  • 若WebSphere启用了SSL,需在wsadmin命令中添加SSL相关参数
  • 生产环境建议使用Ansible Vault加密敏感信息(如管理员密码)

内容的提问来源于stack exchange,提问作者Supriyo Sarkar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 13:53:15