From fc9cbbd564afb8b5951d9ef308242839be6a4b64 Mon Sep 17 00:00:00 2001 From: thienqb123456 Date: Mon, 3 Mar 2025 18:08:45 +0700 Subject: [PATCH] fix --- .../host_vars/beta-portal-hnt-backend.yml | 3 +- inventory/host_vars/uat-portal-backend.yml | 4 +- .../host_vars/uat-portal-hnt-backend.yml | 6 +++ .../host_vars/uat-portal-ktdt-backend.yml | 6 +++ roles/deploy-be-portal/tasks/setup.yml | 43 +++++++++++++------ 5 files changed, 45 insertions(+), 17 deletions(-) create mode 100644 inventory/host_vars/uat-portal-hnt-backend.yml create mode 100644 inventory/host_vars/uat-portal-ktdt-backend.yml diff --git a/inventory/host_vars/beta-portal-hnt-backend.yml b/inventory/host_vars/beta-portal-hnt-backend.yml index 22030ef..624313b 100644 --- a/inventory/host_vars/beta-portal-hnt-backend.yml +++ b/inventory/host_vars/beta-portal-hnt-backend.yml @@ -3,5 +3,4 @@ iis_site_name: "portal-api.hanoitimes.vn" blue_path: "C:\\deploy\\portal\\be\\hnt\\blue" green_path: "C:\\deploy\\portal\\be\\hnt\\green" -aspnetcore_environtment: "Hnt_Beta" -iis_app_pool: "portal-api.hanoitimes.vn" \ No newline at end of file +aspnetcore_environtment: "Hnt_Beta" \ No newline at end of file diff --git a/inventory/host_vars/uat-portal-backend.yml b/inventory/host_vars/uat-portal-backend.yml index 1046b2e..7c45e7f 100644 --- a/inventory/host_vars/uat-portal-backend.yml +++ b/inventory/host_vars/uat-portal-backend.yml @@ -1,4 +1,6 @@ temp_dir: "C:\\deploy\\vpress\\temp" iis_site_name: "api-portal-2025" blue_path: "C:\\deploy\\vpress\\portal\\be\\blue" -green_path: "C:\\deploy\\vpress\\portal\\be\\green" \ No newline at end of file +green_path: "C:\\deploy\\vpress\\portal\\be\\green" + +aspnetcore_environtment: "Uat" \ No newline at end of file diff --git a/inventory/host_vars/uat-portal-hnt-backend.yml b/inventory/host_vars/uat-portal-hnt-backend.yml new file mode 100644 index 0000000..7c45e7f --- /dev/null +++ b/inventory/host_vars/uat-portal-hnt-backend.yml @@ -0,0 +1,6 @@ +temp_dir: "C:\\deploy\\vpress\\temp" +iis_site_name: "api-portal-2025" +blue_path: "C:\\deploy\\vpress\\portal\\be\\blue" +green_path: "C:\\deploy\\vpress\\portal\\be\\green" + +aspnetcore_environtment: "Uat" \ No newline at end of file diff --git a/inventory/host_vars/uat-portal-ktdt-backend.yml b/inventory/host_vars/uat-portal-ktdt-backend.yml new file mode 100644 index 0000000..7c45e7f --- /dev/null +++ b/inventory/host_vars/uat-portal-ktdt-backend.yml @@ -0,0 +1,6 @@ +temp_dir: "C:\\deploy\\vpress\\temp" +iis_site_name: "api-portal-2025" +blue_path: "C:\\deploy\\vpress\\portal\\be\\blue" +green_path: "C:\\deploy\\vpress\\portal\\be\\green" + +aspnetcore_environtment: "Uat" \ No newline at end of file diff --git a/roles/deploy-be-portal/tasks/setup.yml b/roles/deploy-be-portal/tasks/setup.yml index 0df25a9..7efdbe1 100644 --- a/roles/deploy-be-portal/tasks/setup.yml +++ b/roles/deploy-be-portal/tasks/setup.yml @@ -3,10 +3,6 @@ debug: var: iis_site_name -- name: Debug iis_app_pool - debug: - var: iis_app_pool - - name: Debug aspnetcore_environtment debug: var: aspnetcore_environtment @@ -24,17 +20,36 @@ debug: var: artifact_name -- name: Set registry key for IIS App Pool environment variable - win_regedit: - path: "HKLM:\\SYSTEM\\CurrentControlSet\\Services\\W3SVC\\AppPools\\{{ iis_app_pool }}\\Environment" - name: "TEST_ENV" - type: string - data: "{{ aspnetcore_environtment }}" +- name: Validate required variables + assert: + that: + - iis_site_name is defined and iis_site_name | length > 0 + - aspnetcore_environtment is defined and aspnetcore_environtment | 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!" + +- name: Check if IIS site exists + win_iis_site: + name: "{{ iis_site_name }}" + state: absent + check_mode: yes + register: site_check + +- name: Fail if IIS site does not exist + fail: + msg: "IIS site '{{ iis_site_name }}' does not exist!" + when: site_check is changed + +- name: Set ASPNETCORE_ENVIRONMENT for site + win_shell: | + Import-Module WebAdministration + Add-WebConfigurationProperty -pspath "MACHINE/WEBROOT/APPHOST/{{ iis_site_name }}" ` + -filter "system.webServer/aspNetCore/environmentVariables" ` + -name "." ` + -value @{name="ASPNETCORE_ENVIRONMENT"; value="{{ aspnetcore_environtment }}"} -- name: Khởi động lại App Pool (hoặc IIS) để áp dụng - win_iis_webapppool: - name: "{{ iis_app_pool }}" - state: restarted #Lấy đường dẫn vật lý của iis site - name: Get the physical path of the current IIS site