From da179bd1c370d8199a7fa3561e3e9d5aa3399787 Mon Sep 17 00:00:00 2001 From: thienqb123456 Date: Tue, 4 Mar 2025 18:17:07 +0700 Subject: [PATCH] quite-good --- inventory/host_vars/uat-resource-backend.yml | 4 -- roles/deploy-be-portal/tasks/cleanup.yml | 5 -- roles/deploy-be-portal/tasks/deploy.yml | 46 --------------- roles/deploy-be-portal/tasks/setup.yml | 60 -------------------- roles/deploy-be-portal/tasks/switch.yml | 20 ------- 5 files changed, 135 deletions(-) delete mode 100644 inventory/host_vars/uat-resource-backend.yml delete mode 100644 roles/deploy-be-portal/tasks/cleanup.yml delete mode 100644 roles/deploy-be-portal/tasks/deploy.yml delete mode 100644 roles/deploy-be-portal/tasks/setup.yml delete mode 100644 roles/deploy-be-portal/tasks/switch.yml diff --git a/inventory/host_vars/uat-resource-backend.yml b/inventory/host_vars/uat-resource-backend.yml deleted file mode 100644 index 2225d0f..0000000 --- a/inventory/host_vars/uat-resource-backend.yml +++ /dev/null @@ -1,4 +0,0 @@ -temp_dir: "C:\\deploy\\vpress\\temp" -iis_site_name: "resource.vpress.vn" -blue_path: "C:\\deploy\\vpress\\resource\\blue" -green_path: "C:\\deploy\\vpress\\resource\\green" \ No newline at end of file diff --git a/roles/deploy-be-portal/tasks/cleanup.yml b/roles/deploy-be-portal/tasks/cleanup.yml deleted file mode 100644 index 50350b2..0000000 --- a/roles/deploy-be-portal/tasks/cleanup.yml +++ /dev/null @@ -1,5 +0,0 @@ -# Xóa file tạm -- name: Clean up temporary files - win_file: - path: "{{ temp_dir }}\\{{ artifact_name }}" - state: absent \ No newline at end of file diff --git a/roles/deploy-be-portal/tasks/deploy.yml b/roles/deploy-be-portal/tasks/deploy.yml deleted file mode 100644 index 437213e..0000000 --- a/roles/deploy-be-portal/tasks/deploy.yml +++ /dev/null @@ -1,46 +0,0 @@ -# Tải artifact từ Nexus Repository -- name: Download artifact from Nexus - win_get_url: - url: "{{ nexus_url }}/{{ artifact_name }}" - dest: "{{ temp_dir }}\\{{ artifact_name }}" - validate_certs: no - url_username: "{{ nexus_username }}" - url_password: "{{ nexus_password }}" - register: download_status - vars: - nexus_url: "{{ nexus_url }}" - artifact_name: "{{ artifact_name }}" - nexus_username: "{{ nexus_username }}" - nexus_password: "{{ nexus_password }}" - -# Debug download_status -- name: Debug download_status - debug: - var: download_status - -# 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 - stat: - path: "{{ temp_dir }}/{{ artifact_name }}" - register: file_status - changed_when: false - failed_when: false - -# Debug file_status -- name: Debug file_status - debug: - var: file_status - -# Giải nén artifact vào thư mục target -- name: Deploy to target environment - win_unzip: - src: "{{ temp_dir }}\\{{ artifact_name }}" - dest: "{{ target_path }}" - overwrite: yes - diff --git a/roles/deploy-be-portal/tasks/setup.yml b/roles/deploy-be-portal/tasks/setup.yml deleted file mode 100644 index 08ea7b4..0000000 --- a/roles/deploy-be-portal/tasks/setup.yml +++ /dev/null @@ -1,60 +0,0 @@ -#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 \ No newline at end of file diff --git a/roles/deploy-be-portal/tasks/switch.yml b/roles/deploy-be-portal/tasks/switch.yml deleted file mode 100644 index 0dde19f..0000000 --- a/roles/deploy-be-portal/tasks/switch.yml +++ /dev/null @@ -1,20 +0,0 @@ -# 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 }}" - -# 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 }}" ` - -filter "system.webServer/aspNetCore/environmentVariables" ` - -name "." ` - -value @{name="ASPNETCORE_ENVIRONMENT"; value="{{ aspnetcore_environment }}"} - -# - name: Restart IIS site to apply changes -# win_iis_website: -# name: "{{ iis_site_name }}" -# state: restarted -