From f94804e277ffa5ad2e3bf4f7f6981e57a06e6b92 Mon Sep 17 00:00:00 2001 From: thienqb123456 Date: Tue, 4 Mar 2025 10:06:53 +0700 Subject: [PATCH] fix10 --- roles/deploy-be-portal/tasks/deploy.yml | 11 ++++---- roles/deploy-be-portal/tasks/setup.yml | 35 +++++++++++-------------- roles/deploy-be-portal/tasks/switch.yml | 4 ++- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/roles/deploy-be-portal/tasks/deploy.yml b/roles/deploy-be-portal/tasks/deploy.yml index c74b0cf..437213e 100644 --- a/roles/deploy-be-portal/tasks/deploy.yml +++ b/roles/deploy-be-portal/tasks/deploy.yml @@ -1,4 +1,4 @@ -# Tải artifact từ Nexus +# Tải artifact từ Nexus Repository - name: Download artifact from Nexus win_get_url: url: "{{ nexus_url }}/{{ artifact_name }}" @@ -18,9 +18,11 @@ debug: var: download_status -- name: Check if the download was successful - debug: - msg: "Download successful: {{ download_status.msg }}" +# Lỗi khi tải artifact từ nexus thất bại +- name: Fail if download artifact from Nexus Repository fail + fail: + msg: "Download artifact from nexus fail" + when: download_status.status_code != 200 # Kiểm tra ở trên server đã tồn tại file vùa tải xuống không - name: Check if the artifact file exists @@ -35,7 +37,6 @@ debug: var: file_status - # Giải nén artifact vào thư mục target - name: Deploy to target environment win_unzip: diff --git a/roles/deploy-be-portal/tasks/setup.yml b/roles/deploy-be-portal/tasks/setup.yml index 461cd66..e3e38cc 100644 --- a/roles/deploy-be-portal/tasks/setup.yml +++ b/roles/deploy-be-portal/tasks/setup.yml @@ -20,6 +20,7 @@ debug: var: artifact_name +# Validate các biến var truyền vào - name: Validate required variables assert: that: @@ -30,32 +31,26 @@ - artifact_name is defined and artifact_name | length > 0 fail_msg: "One or more required variables are missing or empty!" -- name: Check if IIS site exists - win_shell: | - Import-Module WebAdministration - if (Get-Website -Name "{{ iis_site_name }}") { "exists" } else { "not exists" } - register: site_check - failed_when: "'not exists' in site_check.stdout" - -- name: Debug site existence - debug: - msg: "IIS site {{ iis_site_name }} exists!" - -#Lấy đường dẫn vật lý của iis site +#Lấy đường dẫn vật lý của iis site/kiểm tra sự tồn tại của site - name: Get the physical path of the current IIS site win_shell: | Import-Module WebAdministration $site = Get-Website -Name "{{ iis_site_name}}" - $site.PhysicalPath + if ($site) { + Write-Output $site.PhysicalPath + } else { + Write-Output "NOT_FOUND" + } register: active_path -- debug: - var: active_path - -- name: Handle error if active_path is null - fail: - msg: "The IIS site active path could not be determined." - when: active_path.stdout is not defined or active_path.stdout == '' +- name: Debug output + debug: + msg: "Site path: {{ active_path.stdout }}" + +- name: Fail if site does not exist + fail: + msg: "IIS site {{ iis_site_name }} not found!" + when: active_path.stdout == "NOT_FOUND" # Chuẩn hóa giá trị của active_path - name: Normalize active_path diff --git a/roles/deploy-be-portal/tasks/switch.yml b/roles/deploy-be-portal/tasks/switch.yml index 573bdb7..0dde19f 100644 --- a/roles/deploy-be-portal/tasks/switch.yml +++ b/roles/deploy-be-portal/tasks/switch.yml @@ -1,9 +1,11 @@ +# Cập nhật PhysicalPath mới cho site IIS (green/blue) - name: Update site IIS web application win_iis_website: name: "{{ iis_site_name }}" physical_path: "{{ target_path }}" -- name: Set ASPNETCORE_ENVIRONMENT for IIS site +# Set ASPNETCORE_ENVIRONMENT cho site IIS +- name: Set ASPNETCORE_ENVIRONMENT for IIS site win_shell: | Import-Module WebAdministration Add-WebConfigurationProperty -pspath "MACHINE/WEBROOT/APPHOST/{{ iis_site_name }}" `