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

Windows目标机部署时如何将nupkg文件转换为zip文件?

在Windows目标机部署服务时,我需要将nupkg文件转换为zip文件,尝试通过Ansible的win_copy模块重命名文件来实现转换,以下是我的Playbook内容:

服务部署Playbook
- name: 服务部署
  hosts: "{{ APP_HOSTS }}"
  vars:
    backup_keep: 2
  gather_facts: yes
  tasks:
    - name : 测试服务器连通性
      win_ping:
      tags:
         - ping

    
    - name: 下载NuGet包
      ansible.windows.win_get_url:
        url: "{{ PKGURL }}/{{ app }}/{{ version }}"
        dest: "{{ PKGFOLDER }}/IdocService.1.0.27.nupkg"
        headers:  
          Authorization: "Basic {{NEXUS_AUTH}}"

    - name: 将.nupkg重命名为.zip
      ansible.windows.win_copy:
        src:  "{{ PKGFOLDER }}/IdocService.1.0.27.nupkg"
        dest: "{{ PKGFOLDER }}/IdocService.1.0.27.zip"
        remote_src: yes 
备份流程
- name: 停止应用池前备份文件
  block:
    - name: 打印备份文件夹路径
      debug:
        msg: "D:/ansible_runner/backups/{{ APP_SLUG }}/{{ ansible_date_time.date }}"

    - name: 创建备份文件夹
      ansible.windows.win_file:
        state: directory
        #path: "D:/ansible_runner/backups/{{ APP_SLUG }}/{{ ansible_date_time.iso8601_basic_short }}"
        path: "D:/ansible_runner/backups/{{ APP_SLUG }}/{{ ansible_date_time.date }}"

    - name: 执行文件备份
      ansible.windows.win_powershell:
        script: |
          Copy-Item -Path {{ API_TGT_PATH }}/* `
          -Destination D:/ansible_runner/backups/{{ APP_SLUG }}/{{ ansible_date_time.date }} `
          -Recurse `
          -Exclude Logs*,backup*,backups*,Backup*,Backups*
部署流程
- name: 停止服务 - {{ API_SERVICE }}
  ansible.windows.win_service:
    name: "{{ API_SERVICE }}"
    state: stopped

- name: 复制构建文件
  ansible.windows.win_copy:
    src:  "D:/ansible_runner/temp/{{ app }}.{{ version }}/publish/"
    dest: "{{ API_TGT_PATH }}"
    remote_src: yes

- name: 启动服务 - {{ API_SERVICE }}
  ansible.windows.win_service:
    name: "{{ API_SERVICE }}"
    state: started
清理旧备份
- name: 获取现有备份文件列表
  ansible.windows.win_find:
    paths: "D:/ansible_runner/backups/{{ APP_SLUG }}"
    file_type: "directory"
  register: avl_backups
  
- debug:
    var: avl_backups

- set_fact:
    backups_to_delete: "{{ (avl_backups.files | sort(attribute='lastwritetime', reverse=true) | map(attribute='path') | list)[backup_keep:] }}"

- name: 待删除的备份列表
  debug:
    var: backups_to_delete
    
- name: 删除旧备份文件
  ansible.windows.win_file:
    state: absent
    path: "{{ item }}"
  loop: "{{ backups_to_delete }}"
清理Nexus包
- name: 删除Nexus下载的包
  ansible.windows.win_file:
    name: "{{PKGFOLDER}}/{{ app }}.{{ version }}.nupkg"
    state: absent  

内容的提问来源于stack exchange,提问作者jyothi T

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 00:16:10