60 lines
1.7 KiB
YAML
60 lines
1.7 KiB
YAML
#Debug
|
|
- name: Debug iis_site_name
|
|
debug:
|
|
var: iis_site_name
|
|
|
|
- name: Debug aspnetcore_environment
|
|
debug:
|
|
var: aspnetcore_environment
|
|
|
|
- name: Debug blue_path
|
|
debug:
|
|
var: blue_path
|
|
|
|
# Kiểm tra các thông số Nexus
|
|
- name: Debug Nexus URL
|
|
debug:
|
|
var: nexus_url
|
|
|
|
- name: Debug artifact name
|
|
debug:
|
|
var: artifact_name
|
|
|
|
# Validate các biến var truyền vào
|
|
- name: Validate required variables
|
|
assert:
|
|
that:
|
|
- iis_site_name is defined and iis_site_name | length > 0
|
|
- aspnetcore_environment is defined and aspnetcore_environment | length > 0
|
|
- blue_path is defined and blue_path | length > 0
|
|
- nexus_url is defined and nexus_url | length > 0
|
|
- artifact_name is defined and artifact_name | length > 0
|
|
fail_msg: "One or more required variables are missing or empty!"
|
|
|
|
#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}}"
|
|
if ($site) {
|
|
Write-Output $site.PhysicalPath
|
|
} else {
|
|
Write-Output "NOT_FOUND"
|
|
}
|
|
register: site_path
|
|
|
|
- name: Set fact for site path
|
|
set_fact:
|
|
active_path: "{{ site_path.stdout_lines[0] }}"
|
|
|
|
- name: Fail if site does not exist
|
|
fail:
|
|
msg: "IIS site {{ iis_site_name }} not found!"
|
|
when: active_path == "NOT_FOUND"
|
|
|
|
# Chọn môi trường Blue hoặc Green để deploy
|
|
- name: Set target deployment environment
|
|
set_fact:
|
|
target_path: "{{ green_path if active_path == blue_path else blue_path }}" #lấy ra đường dẫn thư mục cần deploy
|
|
- debug:
|
|
var: target_path |