This commit is contained in:
thienqb123456
2025-03-04 10:06:53 +07:00
parent c4d166d418
commit f94804e277
3 changed files with 24 additions and 26 deletions
+6 -5
View File
@@ -1,4 +1,4 @@
# Tải artifact từ Nexus # Tải artifact từ Nexus Repository
- name: Download artifact from Nexus - name: Download artifact from Nexus
win_get_url: win_get_url:
url: "{{ nexus_url }}/{{ artifact_name }}" url: "{{ nexus_url }}/{{ artifact_name }}"
@@ -18,9 +18,11 @@
debug: debug:
var: download_status var: download_status
- name: Check if the download was successful # Lỗi khi tải artifact từ nexus thất bại
debug: - name: Fail if download artifact from Nexus Repository fail
msg: "Download successful: {{ download_status.msg }}" 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 # 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 - name: Check if the artifact file exists
@@ -35,7 +37,6 @@
debug: debug:
var: file_status var: file_status
# Giải nén artifact vào thư mục target # Giải nén artifact vào thư mục target
- name: Deploy to target environment - name: Deploy to target environment
win_unzip: win_unzip:
+15 -20
View File
@@ -20,6 +20,7 @@
debug: debug:
var: artifact_name var: artifact_name
# Validate các biến var truyền vào
- name: Validate required variables - name: Validate required variables
assert: assert:
that: that:
@@ -30,32 +31,26 @@
- artifact_name is defined and artifact_name | length > 0 - artifact_name is defined and artifact_name | length > 0
fail_msg: "One or more required variables are missing or empty!" fail_msg: "One or more required variables are missing or empty!"
- name: Check if IIS site exists #Lấy đường dẫn vật lý của iis site/kiểm tra sự tồn tại của site
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
- name: Get the physical path of the current IIS site - name: Get the physical path of the current IIS site
win_shell: | win_shell: |
Import-Module WebAdministration Import-Module WebAdministration
$site = Get-Website -Name "{{ iis_site_name}}" $site = Get-Website -Name "{{ iis_site_name}}"
$site.PhysicalPath if ($site) {
Write-Output $site.PhysicalPath
} else {
Write-Output "NOT_FOUND"
}
register: active_path 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 # Chuẩn hóa giá trị của active_path
- name: Normalize active_path - name: Normalize active_path
+3 -1
View File
@@ -1,9 +1,11 @@
# Cập nhật PhysicalPath mới cho site IIS (green/blue)
- name: Update site IIS web application - name: Update site IIS web application
win_iis_website: win_iis_website:
name: "{{ iis_site_name }}" name: "{{ iis_site_name }}"
physical_path: "{{ target_path }}" 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: | win_shell: |
Import-Module WebAdministration Import-Module WebAdministration
Add-WebConfigurationProperty -pspath "MACHINE/WEBROOT/APPHOST/{{ iis_site_name }}" ` Add-WebConfigurationProperty -pspath "MACHINE/WEBROOT/APPHOST/{{ iis_site_name }}" `