diff --git a/inventory/production/host_vars/beta-acp-backend.yml b/inventory/production/host_vars/acp-backend.yml similarity index 100% rename from inventory/production/host_vars/beta-acp-backend.yml rename to inventory/production/host_vars/acp-backend.yml diff --git a/inventory/production/host_vars/beta-acp-frontend.yml b/inventory/production/host_vars/acp-frontend.yml similarity index 100% rename from inventory/production/host_vars/beta-acp-frontend.yml rename to inventory/production/host_vars/acp-frontend.yml diff --git a/inventory/production/host_vars/beta-portal-backend.yml b/inventory/production/host_vars/beta-portal-backend.yml deleted file mode 100644 index f595c91..0000000 --- a/inventory/production/host_vars/beta-portal-backend.yml +++ /dev/null @@ -1,4 +0,0 @@ -temp_dir: "C:\\deploy\\vpress\\temp" -iis_site_name: "portal-api.kinhtedothi.vn" -blue_path: "C:\\deploy\\portal\\be\\blue" -green_path: "C:\\deploy\\portal\\be\\green" \ No newline at end of file diff --git a/inventory/production/host_vars/production-portal-hnt-backend.yml b/inventory/production/host_vars/hnt-portal-backend.yml similarity index 100% rename from inventory/production/host_vars/production-portal-hnt-backend.yml rename to inventory/production/host_vars/hnt-portal-backend.yml diff --git a/inventory/production/host_vars/beta-portal-hnt-frontend.yml b/inventory/production/host_vars/hnt-portal-frontend.yml similarity index 100% rename from inventory/production/host_vars/beta-portal-hnt-frontend.yml rename to inventory/production/host_vars/hnt-portal-frontend.yml diff --git a/inventory/production/host_vars/hnt-resource-backend.yml b/inventory/production/host_vars/hnt-resource-backend.yml new file mode 100644 index 0000000..8447c5b --- /dev/null +++ b/inventory/production/host_vars/hnt-resource-backend.yml @@ -0,0 +1,6 @@ +# temp_dir: "C:\\deploy\\vpress\\temp" +# iis_site_name: "resource.vpress.vn" +# blue_path: "C:\\deploy\\vpress\\resource\\hnt\\blue" +# green_path: "C:\\deploy\\vpress\\resource\\hnt\\green" + +# aspnetcore_environment: "Uat" \ No newline at end of file diff --git a/inventory/production/host_vars/beta-portal-ktdt-backend.yml b/inventory/production/host_vars/ktdt-portal-backend.yml similarity index 100% rename from inventory/production/host_vars/beta-portal-ktdt-backend.yml rename to inventory/production/host_vars/ktdt-portal-backend.yml diff --git a/inventory/production/host_vars/beta-portal-ktdt-frontend.yml b/inventory/production/host_vars/ktdt-portal-frontend.yml similarity index 100% rename from inventory/production/host_vars/beta-portal-ktdt-frontend.yml rename to inventory/production/host_vars/ktdt-portal-frontend.yml diff --git a/inventory/production/host_vars/ktdt-resource-backend.yml b/inventory/production/host_vars/ktdt-resource-backend.yml new file mode 100644 index 0000000..106db3b --- /dev/null +++ b/inventory/production/host_vars/ktdt-resource-backend.yml @@ -0,0 +1,6 @@ +# temp_dir: "C:\\deploy\\vpress\\temp" +# iis_site_name: "resource.vpress.vn" +# blue_path: "C:\\deploy\\vpress\\resource\\ktdt\\blue" +# green_path: "C:\\deploy\\vpress\\resource\\ktdt\\green" + +# aspnetcore_environment: "Ktdt_Beta" \ No newline at end of file diff --git a/inventory/production/hosts.ini b/inventory/production/hosts.ini index abbedce..ab92acd 100644 --- a/inventory/production/hosts.ini +++ b/inventory/production/hosts.ini @@ -17,9 +17,9 @@ acp-backend ansible_host=123.30.238.12 ansible_user=jenkins_cicd_beta ansible_pa acp-frontend ansible_host=123.30.238.12 ansible_user=jenkins_cicd_beta ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore [ktdt_resource_backend] -ktdt-resource-backend ansible_host=123.30.238.12 ansible_user=jenkins_cicd_beta ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore +ktdt-resource-backend [hnt_resource_backend] -hnt-resource-backend ansible_host=123.30.238.12 ansible_user=jenkins_cicd_beta ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore +hnt-resource-backend diff --git a/playbooks/backend/deploy_acp_backend.yml b/playbooks/backend/deploy_acp_backend.yml new file mode 100644 index 0000000..5724c47 --- /dev/null +++ b/playbooks/backend/deploy_acp_backend.yml @@ -0,0 +1,5 @@ +- name: Deploy Backend for Project ACP + hosts: acp-backend + roles: + - deploy-be-acp + \ No newline at end of file diff --git a/playbooks/backend/deploy_hnt_portal_backend.yml b/playbooks/backend/deploy_hnt_portal_backend.yml index ed1af4b..3070b07 100644 --- a/playbooks/backend/deploy_hnt_portal_backend.yml +++ b/playbooks/backend/deploy_hnt_portal_backend.yml @@ -2,4 +2,3 @@ hosts: ktdt-portal-backend roles: - deploy-be-portal - \ No newline at end of file diff --git a/playbooks/frontend/deploy_acp_frontend.yml b/playbooks/frontend/deploy_acp_frontend.yml new file mode 100644 index 0000000..1f9dcf8 --- /dev/null +++ b/playbooks/frontend/deploy_acp_frontend.yml @@ -0,0 +1,5 @@ +- name: Deploy FE for Project ACP + hosts: acp-frontend + roles: + - deploy-fe-acp + \ No newline at end of file diff --git a/playbooks/frontend/deploy_hnt_portal_frontend.yml b/playbooks/frontend/deploy_hnt_portal_frontend.yml new file mode 100644 index 0000000..c6132eb --- /dev/null +++ b/playbooks/frontend/deploy_hnt_portal_frontend.yml @@ -0,0 +1,5 @@ +- name: Deploy FE for Project Portal ktdt + hosts: hnt-portal-frontend + roles: + - deploy-fe-portal + \ No newline at end of file diff --git a/playbooks/frontend/deploy_ktdt_portal_frontend.yml b/playbooks/frontend/deploy_ktdt_portal_frontend.yml new file mode 100644 index 0000000..d74fea6 --- /dev/null +++ b/playbooks/frontend/deploy_ktdt_portal_frontend.yml @@ -0,0 +1,5 @@ +- name: Deploy FE for Project Portal ktdt + hosts: ktdt-portal-frontend + roles: + - deploy-fe-portal + \ No newline at end of file diff --git a/roles/deploy-be-acp/tasks/main.yml b/roles/deploy-be-acp/tasks/main.yml new file mode 100644 index 0000000..5eef374 --- /dev/null +++ b/roles/deploy-be-acp/tasks/main.yml @@ -0,0 +1,32 @@ +- name: get_site_current_active_path.yml + import_role: + name: iis_utils + tasks_from: get_site_current_active_path.yml + +- name: set_target_path + import_role: + name: iis_utils + tasks_from: set_target_path.yml + +- name: artifact_download + import_role: + name: iis_utils + tasks_from: artifact_download.yml + +- name: artifact_deploy + import_role: + name: iis_utils + tasks_from: artifact_deploy.yml + +- name: update_iis_physical_path + import_role: + name: iis_utils + tasks_from: update_iis_physical_path.yml + +- name: set_site_aspnetcore_environment + import_role: + name: iis_utils + tasks_from: set_site_aspnetcore_environment.yml + + + diff --git a/roles/deploy-fe-acp/tasks/main.yml b/roles/deploy-fe-acp/tasks/main.yml new file mode 100644 index 0000000..9fa9c57 --- /dev/null +++ b/roles/deploy-fe-acp/tasks/main.yml @@ -0,0 +1,28 @@ +- name: get_site_current_active_path.yml + import_role: + name: iis_utils + tasks_from: get_site_current_active_path.yml + +- name: set_target_path + import_role: + name: iis_utils + tasks_from: set_target_path.yml + +- name: artifact_download + import_role: + name: iis_utils + tasks_from: artifact_download.yml + +- name: artifact_deploy + import_role: + name: iis_utils + tasks_from: artifact_deploy.yml + +- name: update_iis_physical_path + import_role: + name: iis_utils + tasks_from: update_iis_physical_path.yml + + + + diff --git a/roles/deploy-fe-portal/tasks/cleanup.yml b/roles/deploy-fe-portal/tasks/cleanup.yml deleted file mode 100644 index 50350b2..0000000 --- a/roles/deploy-fe-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-fe-portal/tasks/deploy.yml b/roles/deploy-fe-portal/tasks/deploy.yml deleted file mode 100644 index c74b0cf..0000000 --- a/roles/deploy-fe-portal/tasks/deploy.yml +++ /dev/null @@ -1,45 +0,0 @@ -# Tải artifact từ Nexus -- 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 - -- name: Check if the download was successful - debug: - msg: "Download successful: {{ download_status.msg }}" - -# 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-fe-portal/tasks/main.yml b/roles/deploy-fe-portal/tasks/main.yml index 1570bf6..b024209 100644 --- a/roles/deploy-fe-portal/tasks/main.yml +++ b/roles/deploy-fe-portal/tasks/main.yml @@ -1,13 +1,26 @@ -- name: Setup environment - import_tasks: setup.yml - -- name: Deploy application - import_tasks: deploy.yml +- name: get_site_current_active_path.yml + import_role: + name: iis_utils + tasks_from: get_site_current_active_path.yml -- name: Clean up temporary files - import_tasks: cleanup.yml +- name: set_target_path + import_role: + name: iis_utils + tasks_from: set_target_path.yml -- name: Switch - import_tasks: switch.yml +- name: artifact_download + import_role: + name: iis_utils + tasks_from: artifact_download.yml + +- name: artifact_deploy + import_role: + name: iis_utils + tasks_from: artifact_deploy.yml + +- name: update_iis_physical_path + import_role: + name: iis_utils + tasks_from: update_iis_physical_path.yml diff --git a/roles/deploy-fe-portal/tasks/setup.yml b/roles/deploy-fe-portal/tasks/setup.yml deleted file mode 100644 index f827e00..0000000 --- a/roles/deploy-fe-portal/tasks/setup.yml +++ /dev/null @@ -1,47 +0,0 @@ -#Debug -- name: Debug iis_site_name - debug: - var: iis_site_name - -- 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 - -#Lấy đường dẫn vật lý của iis 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 - 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 == '' - - -# Chuẩn hóa giá trị của active_path -- name: Normalize active_path - set_fact: - active_path: "{{ active_path.stdout | trim }}" -- debug: - var: active_path - -# 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-fe-portal/tasks/switch.yml b/roles/deploy-fe-portal/tasks/switch.yml deleted file mode 100644 index b66d2b3..0000000 --- a/roles/deploy-fe-portal/tasks/switch.yml +++ /dev/null @@ -1,10 +0,0 @@ -- name: Update site IIS web application - win_iis_website: - name: "{{ iis_site_name }}" - physical_path: "{{ target_path }}" - -# - name: Restart IIS site to apply changes -# win_iis_website: -# name: "{{ iis_site_name }}" -# state: restarted - diff --git a/roles/deploy/tasks/cleanup.yml b/roles/deploy/tasks/cleanup.yml deleted file mode 100644 index 50350b2..0000000 --- a/roles/deploy/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/tasks/common.yml b/roles/deploy/tasks/common.yml deleted file mode 100644 index 93564aa..0000000 --- a/roles/deploy/tasks/common.yml +++ /dev/null @@ -1,25 +0,0 @@ -# Kiểm tra kết nối Nexus -- name: Check Nexus connectivity - uri: - url: "{{ nexus_url }}" - method: GET - return_content: yes - status_code: 200 - register: nexus_response - -- name: Verify Nexus response - fail: - msg: "Unable to connect to Nexus at {{ nexus_url }}" - when: nexus_response.status != 200 - -# Kiểm tra quyền ghi trên thư mục target -- name: Verify write access to target path - win_acl: - path: "{{ target_path }}" - state: query - register: acl_status - -- name: Ensure target path is writable - fail: - msg: "No write permissions for target path: {{ target_path }}" - when: acl_status.permissions | length == 0 diff --git a/roles/deploy/tasks/deploy.yml b/roles/deploy/tasks/deploy.yml deleted file mode 100644 index c74b0cf..0000000 --- a/roles/deploy/tasks/deploy.yml +++ /dev/null @@ -1,45 +0,0 @@ -# Tải artifact từ Nexus -- 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 - -- name: Check if the download was successful - debug: - msg: "Download successful: {{ download_status.msg }}" - -# 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/tasks/main.yml b/roles/deploy/tasks/main.yml deleted file mode 100644 index 98eac4d..0000000 --- a/roles/deploy/tasks/main.yml +++ /dev/null @@ -1,16 +0,0 @@ -- name: Setup environment - import_tasks: setup.yml - -# - name: Run common checks -# import_tasks: common.yml - -- name: Deploy application - import_tasks: deploy.yml - -- name: Clean up temporary files - import_tasks: cleanup.yml - -- name: Switch - import_tasks: switch.yml - - diff --git a/roles/deploy/tasks/setup.yml b/roles/deploy/tasks/setup.yml deleted file mode 100644 index 7895f6c..0000000 --- a/roles/deploy/tasks/setup.yml +++ /dev/null @@ -1,47 +0,0 @@ -#Debug -- name: Debug iis_site_name - debug: - var: iis_site_name - -- 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 - -#Lấy đường dẫn vật lý của iis 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 - 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 == '' - - -# Chuẩn hóa giá trị của active_path -- name: Normalize active_path - set_fact: - active_path: "{{ active_path.stdout | trim }}" -- debug: - var: active_path - -# 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/tasks/switch.yml b/roles/deploy/tasks/switch.yml deleted file mode 100644 index 8ef77b9..0000000 --- a/roles/deploy/tasks/switch.yml +++ /dev/null @@ -1,10 +0,0 @@ -- name: Update IIS web application path - win_iis_website: - name: "{{ iis_site_name }}" - physical_path: "{{ target_path }}" - -# - name: Restart IIS site to apply changes -# win_iis_website: -# name: "{{ iis_site_name }}" -# state: restarted -