当我们在 Windows 目标计算机上部署时,如何将 nupkg 文件转换为 zip 文件?

How can I convert nupkg file to zip file when we deploy on windows target machine?

提问人:jyothi T 提问时间:9/26/2023 最后编辑:Zeitounatorjyothi T 更新时间:9/26/2023 访问量:27

问:

我正在使用以下剧本

- name: service deployment
  hosts: "{{ APP_HOSTS }}"
  vars:
    backup_keep: 2
  gather_facts: yes
  tasks:
    - name : Ping Server
      win_ping:
      tags:
         - ping

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

    - name: Rename .nupkg to .zip
      ansible.windows.win_copy:
        src:  "{{ PKGFOLDER }}/IdocService.1.0.27.nupkg"
        dest: "{{ PKGFOLDER }}/IdocService.1.0.27.zip"
        remote_src: yes 

备份

- name: Backup files before stopping app pool
  block:
    - name: print backup folder path
      debug:
        msg: "D:/ansible_runner/backups/{{ APP_SLUG }}/{{ ansible_date_time.date }}"

    - name: Prepare backup folder
      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: Backup files
      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: stop service - {{ API_SERVICE }}
  ansible.windows.win_service:
    name: "{{ API_SERVICE }}"
    state: stopped

- name: Copy build 
  ansible.windows.win_copy:
    src:  "D:/ansible_runner/temp/{{ app }}.{{ version }}/publish/"
    dest: "{{ API_TGT_PATH }}"
    remote_src: yes

- name: start application pool - {{ API_SERVICE }}
  ansible.windows.win_service:
    name: "{{ API_SERVICE }}"
    state: started

清理旧备份

- name: Get Available backup files
  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: Backups that can be deleted 
  debug:
    var: backups_to_delete
    
- name: Delete backup files
  ansible.windows.win_file:
    state: absent
    path: "{{ item }}"
  loop: "{{ backups_to_delete }}"

清理 nexus 包

- name: Remove Nexus package
  ansible.windows.win_file:
    name: "{{PKGFOLDER}}/{{ app }}.{{ version }}.nupkg"
    state: absent  

我尝试使用复制模块

Linux Windows 、Ansible GitLab Ansible-Template

评论

0赞 Zeitounator 9/26/2023
嗨,欢迎来到 SO。请编辑上面的内容,使其成为一个最小的可重现示例。您必须删除与您的问题没有直接关系的任何内容,以仅保留处理根据需要转换文件的部分。您还必须添加运行清理代码的结果以及您获得的任何输出和错误。最后,你必须描述你的期望
0赞 U880D 9/27/2023
您可以直接与 一起使用。无需在下载过程中命名文件并在之后重命名。win_get_urldest: "{{ PKGFOLDER }}/IdocService.1.0.27.zip".nupkg

答: 暂无答案