提问人:jyothi T 提问时间:9/26/2023 最后编辑:Zeitounatorjyothi T 更新时间:9/26/2023 访问量:27
当我们在 Windows 目标计算机上部署时,如何将 nupkg 文件转换为 zip 文件?
How can I convert nupkg file to zip file when we deploy on windows target machine?
问:
我正在使用以下剧本
- 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
我尝试使用复制模块
答: 暂无答案
评论
win_get_url
dest: "{{ PKGFOLDER }}/IdocService.1.0.27.zip"
.nupkg