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
+15 -20
View File
@@ -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