diff --git a/ansible.cfg b/ansible.cfg index c83c2ba..fae1afd 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,3 +1,4 @@ [defaults] inventory = ./inventory -roles_path = ./roles \ No newline at end of file +roles_path = ./roles +error_on_missing_hosts = True ;Ansible sẽ thoát với mã lỗi 1 nếu không tìm thấy hosts. \ No newline at end of file diff --git a/inventory/host_vars/prod_be_acp.yml b/inventory/host_vars/prod_be_acp.yml deleted file mode 100644 index c23432b..0000000 --- a/inventory/host_vars/prod_be_acp.yml +++ /dev/null @@ -1,4 +0,0 @@ -temp_dir: "C:\\deploy\\vpress\\temp" -iis_site_name: "api-acp.kinhtedothi.vn" -blue_path: "C:\\deploy\\vpress\\acp\\be\\blue" -green_path: "C:\\deploy\\vpress\\acp\\be\\green" \ No newline at end of file diff --git a/inventory/host_vars/prod_be_portal.yml b/inventory/host_vars/prod_be_portal.yml deleted file mode 100644 index 7cda80e..0000000 --- a/inventory/host_vars/prod_be_portal.yml +++ /dev/null @@ -1,4 +0,0 @@ -temp_dir: "C:\\deploy\\vpress\\temp" -iis_site_name: "api-portal.kinhtedothi.vn" -blue_path: "C:\\deploy\\vpress\\portal\\be\\blue" -green_path: "C:\\deploy\\vpress\\portal\\be\\green" \ No newline at end of file diff --git a/inventory/host_vars/prod_fe_acp.yml b/inventory/host_vars/prod_fe_acp.yml deleted file mode 100644 index b92092b..0000000 --- a/inventory/host_vars/prod_fe_acp.yml +++ /dev/null @@ -1,4 +0,0 @@ -temp_dir: "C:\\deploy\\vpress\\temp" -iis_site_name: "acp.kinhtedothi.vn" -blue_path: "C:\\deploy\\vpress\\acp\\fe\\blue" -green_path: "C:\\deploy\\vpress\\acp\\fe\\green" \ No newline at end of file diff --git a/inventory/host_vars/prod_fe_portal.yml b/inventory/host_vars/prod_fe_portal.yml deleted file mode 100644 index de15b84..0000000 --- a/inventory/host_vars/prod_fe_portal.yml +++ /dev/null @@ -1,4 +0,0 @@ -temp_dir: "C:\\deploy\\vpress\\temp" -iis_site_name: "demo.kinhtedothi.vn" -blue_path: "C:\\deploy\\vpress\\portal\\fe\\blue" -green_path: "C:\\deploy\\vpress\\portal\\fe\\green" \ No newline at end of file diff --git a/inventory/host_vars/uat_be_acp.yml b/inventory/host_vars/uat_be_acp.yml deleted file mode 100644 index 5b8e711..0000000 --- a/inventory/host_vars/uat_be_acp.yml +++ /dev/null @@ -1,4 +0,0 @@ -temp_dir: "C:\\deploy\\vpress\\temp" -iis_site_name: "api-acp-2025" -blue_path: "C:\\deploy\\vpress\\acp\\be\\blue" -green_path: "C:\\deploy\\vpress\\acp\\be\\green" \ No newline at end of file diff --git a/inventory/host_vars/uat_be_portal.yml b/inventory/host_vars/uat_be_portal.yml deleted file mode 100644 index 1046b2e..0000000 --- a/inventory/host_vars/uat_be_portal.yml +++ /dev/null @@ -1,4 +0,0 @@ -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 diff --git a/inventory/host_vars/uat_fe_acp.yml b/inventory/host_vars/uat_fe_acp.yml deleted file mode 100644 index 293a6c6..0000000 --- a/inventory/host_vars/uat_fe_acp.yml +++ /dev/null @@ -1,4 +0,0 @@ -temp_dir: "C:\\deploy\\vpress\\temp" -iis_site_name: "uat-acp.vpress.vn" -blue_path: "C:\\deploy\\vpress\\acp\\fe\\blue" -green_path: "C:\\deploy\\vpress\\acp\\fe\\green" \ No newline at end of file diff --git a/inventory/host_vars/uat_fe_portal.yml b/inventory/host_vars/uat_fe_portal.yml deleted file mode 100644 index e1a0f01..0000000 --- a/inventory/host_vars/uat_fe_portal.yml +++ /dev/null @@ -1,4 +0,0 @@ -temp_dir: "C:\\deploy\\vpress\\temp" -iis_site_name: "uat_be_acp_TEST" -blue_path: "C:\\deploy\\vpress\\portal\\fe\\blue" -green_path: "C:\\deploy\\vpress\\portal\\fe\\green" \ No newline at end of file diff --git a/inventory/prod.ini b/inventory/prod.ini deleted file mode 100644 index b7dfa3b..0000000 --- a/inventory/prod.ini +++ /dev/null @@ -1,11 +0,0 @@ -[prod_be_acp_webservers] -prod_be_acp ansible_host=123.30.186.68 ansible_user=jenkins_cicd_ktdt ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore - -[prod_be_portal_webservers] -prod_be_portal ansible_host=123.30.186.68 ansible_user=jenkins_cicd_ktdt ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore - -[prod_fe_acp_webservers] -prod_fe_acp ansible_host=123.30.186.68 ansible_user=jenkins_cicd_ktdt ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore - -[prod_be_portal_webservers] -prod_fe_portal ansible_host=123.30.186.68 ansible_user=jenkins_cicd_ktdt ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore diff --git a/inventory/production/group_vars/all.yml b/inventory/production/group_vars/all.yml new file mode 100644 index 0000000..e69de29 diff --git a/inventory/production/group_vars/hnt.yml b/inventory/production/group_vars/hnt.yml new file mode 100644 index 0000000..e69de29 diff --git a/inventory/production/group_vars/ktdt.yml b/inventory/production/group_vars/ktdt.yml new file mode 100644 index 0000000..e69de29 diff --git a/inventory/production/host_vars/acp-backend.yml b/inventory/production/host_vars/acp-backend.yml new file mode 100644 index 0000000..0b4c394 --- /dev/null +++ b/inventory/production/host_vars/acp-backend.yml @@ -0,0 +1,8 @@ +temp_dir: "E:\\deploy\\vpress\\temp" +iis_site_name: "acp-api.kinhtedothi.vn" +app_pool_name: "acp-api.kinhtedothi.vn" + +blue_path: "E:\\deploy\\acp\\be\\blue" +green_path: "E:\\deploy\\acp\\be\\green" + +aspnetcore_environment: "Ktdt_Production" \ No newline at end of file diff --git a/inventory/production/host_vars/acp-frontend.yml b/inventory/production/host_vars/acp-frontend.yml new file mode 100644 index 0000000..eaab606 --- /dev/null +++ b/inventory/production/host_vars/acp-frontend.yml @@ -0,0 +1,6 @@ +temp_dir: "E:\\deploy\\vpress\\temp" +iis_site_name: "tsht.kinhtedothi.vn" +app_pool_name: "tsht.kinhtedothi.vn" + +blue_path: "E:\\deploy\\acp\\fe\\blue" +green_path: "E:\\deploy\\acp\\fe\\green" \ No newline at end of file diff --git a/inventory/production/host_vars/hnt-portal-backend.yml b/inventory/production/host_vars/hnt-portal-backend.yml new file mode 100644 index 0000000..fc51b81 --- /dev/null +++ b/inventory/production/host_vars/hnt-portal-backend.yml @@ -0,0 +1,8 @@ +temp_dir: "E:\\deploy\\vpress\\temp" +iis_site_name: "portal-api.hanoitimes.vn" +app_pool_name: "portal-api.hanoitimes.vn" + +blue_path: "E:\\deploy\\portal\\be\\hnt\\blue" +green_path: "E:\\deploy\\portal\\be\\hnt\\green" + +aspnetcore_environment: "Hnt_Production" \ No newline at end of file diff --git a/inventory/production/host_vars/hnt-portal-frontend.yml b/inventory/production/host_vars/hnt-portal-frontend.yml new file mode 100644 index 0000000..79d6a16 --- /dev/null +++ b/inventory/production/host_vars/hnt-portal-frontend.yml @@ -0,0 +1,6 @@ +temp_dir: "E:\\deploy\\vpress\\temp" +iis_site_name: "hanoitimes.vn" +app_pool_name: "beta.hanoitimes.vn" + +blue_path: "E:\\deploy\\portal\\fe\\hnt\\blue" +green_path: "E:\\deploy\\portal\\fe\\hnt\\green" \ No newline at end of file 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..3bb484b --- /dev/null +++ b/inventory/production/host_vars/hnt-resource-backend.yml @@ -0,0 +1,6 @@ +# temp_dir: "C:\\deploy\\vpress\\temp" +# iis_site_name: "cdn-media.hanoitimes.vn" +# blue_path: "C:\\deploy\\resource\\hnt\\blue" +# green_path: "C:\\deploy\\resource\\hnt\\green" + +# aspnetcore_environment: "Hnt_Production" \ No newline at end of file diff --git a/inventory/production/host_vars/ktdt-portal-backend.yml b/inventory/production/host_vars/ktdt-portal-backend.yml new file mode 100644 index 0000000..f85b607 --- /dev/null +++ b/inventory/production/host_vars/ktdt-portal-backend.yml @@ -0,0 +1,8 @@ +temp_dir: "E:\\deploy\\vpress\\temp" +iis_site_name: "portal-api.kinhtedothi.vn" +app_pool_name: "portal-api.kinhtedothi.vn" + +blue_path: "E:\\deploy\\portal\\be\\ktdt\\blue" +green_path: "E:\\deploy\\portal\\be\\ktdt\\green" + +aspnetcore_environment: "Ktdt_Production" \ No newline at end of file diff --git a/inventory/production/host_vars/ktdt-portal-frontend.yml b/inventory/production/host_vars/ktdt-portal-frontend.yml new file mode 100644 index 0000000..829678f --- /dev/null +++ b/inventory/production/host_vars/ktdt-portal-frontend.yml @@ -0,0 +1,6 @@ +temp_dir: "E:\\deploy\\vpress\\temp" +iis_site_name: "beta.kinhtedothi.vn" +app_pool_name: "beta.kinhtedothi.vn" + +blue_path: "E:\\deploy\\portal\\fe\\ktdt\\blue" +green_path: "E:\\deploy\\portal\\fe\\ktdt\\green" \ No newline at end of file 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..e992de9 --- /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.kinhtedothi.vn" +# blue_path: "C:\\deploy\\resource\\ktdt\\blue" +# green_path: "C:\\deploy\\resource\\ktdt\\green" + +# aspnetcore_environment: "Ktdt_Production" \ No newline at end of file diff --git a/inventory/production/hosts.ini b/inventory/production/hosts.ini new file mode 100644 index 0000000..ab92acd --- /dev/null +++ b/inventory/production/hosts.ini @@ -0,0 +1,25 @@ +[ktdt_portal_backend] +ktdt-portal-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_portal_backend] +hnt-portal-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_portal_frontend] +ktdt-portal-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 + +[hnt_portal_frontend] +hnt-portal-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 + +[acp_backend] +acp-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 + +[acp_frontend] +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 + +[hnt_resource_backend] +hnt-resource-backend + + diff --git a/inventory/uat.ini b/inventory/uat.ini deleted file mode 100644 index 34be3de..0000000 --- a/inventory/uat.ini +++ /dev/null @@ -1,11 +0,0 @@ -[uat_be_acp_webservers] -uat_be_acp ansible_host=123.30.172.34 ansible_user=jenkins_cicd ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore - -[uat_be_portal_webservers] -uat_be_portal ansible_host=123.30.172.34 ansible_user=jenkins_cicd ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore - -[uat_fe_acp_webservers] -uat_fe_acp ansible_host=123.30.172.34 ansible_user=jenkins_cicd ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore - -[uat_be_portal_webservers] -uat_fe_portal ansible_host=123.30.172.34 ansible_user=jenkins_cicd ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore diff --git a/inventory/uat/group_vars/all.yml b/inventory/uat/group_vars/all.yml new file mode 100644 index 0000000..e69de29 diff --git a/inventory/uat/group_vars/hnt.yml b/inventory/uat/group_vars/hnt.yml new file mode 100644 index 0000000..e69de29 diff --git a/inventory/uat/group_vars/ktdt.yml b/inventory/uat/group_vars/ktdt.yml new file mode 100644 index 0000000..e69de29 diff --git a/inventory/uat/host_vars/acp-backend.yml b/inventory/uat/host_vars/acp-backend.yml new file mode 100644 index 0000000..1d56daa --- /dev/null +++ b/inventory/uat/host_vars/acp-backend.yml @@ -0,0 +1,7 @@ +temp_dir: "E:\\deploy\\vpress\\temp" +iis_site_name: "api-acp-2025" +app_pool_name: "api-acp-2025" +blue_path: "E:\\deploy\\vpress\\acp\\be\\blue" +green_path: "E:\\deploy\\vpress\\acp\\be\\green" + +aspnetcore_environment: "Uat" \ No newline at end of file diff --git a/inventory/uat/host_vars/acp-frontend.yml b/inventory/uat/host_vars/acp-frontend.yml new file mode 100644 index 0000000..88643ba --- /dev/null +++ b/inventory/uat/host_vars/acp-frontend.yml @@ -0,0 +1,5 @@ +temp_dir: "E:\\deploy\\vpress\\temp" +iis_site_name: "uat-acp.vpress.vn" +app_pool_name: "uat-acp.vpress.vn" +blue_path: "E:\\deploy\\vpress\\acp\\fe\\blue" +green_path: "E:\\deploy\\vpress\\acp\\fe\\green" \ No newline at end of file diff --git a/inventory/uat/host_vars/hnt-portal-backend.yml b/inventory/uat/host_vars/hnt-portal-backend.yml new file mode 100644 index 0000000..cd9579f --- /dev/null +++ b/inventory/uat/host_vars/hnt-portal-backend.yml @@ -0,0 +1,7 @@ +temp_dir: "E:\\deploy\\vpress\\temp" +iis_site_name: "api-portal2-2025.vpress.vn" +app_pool_name: "api-portal2-2025.vpress.vn" +blue_path: "E:\\deploy\\vpress\\portal\\be\\hnt\\blue" +green_path: "E:\\deploy\\vpress\\portal\\be\\hnt\\green" + +aspnetcore_environment: "Uat_Hnt" \ No newline at end of file diff --git a/inventory/uat/host_vars/hnt-portal-frontend.yml b/inventory/uat/host_vars/hnt-portal-frontend.yml new file mode 100644 index 0000000..09e39c3 --- /dev/null +++ b/inventory/uat/host_vars/hnt-portal-frontend.yml @@ -0,0 +1,6 @@ +temp_dir: "E:\\deploy\\vpress\\temp" +iis_site_name: "uat-portal2" +app_pool_name: "uat-portal2" + +blue_path: "E:\\deploy\\vpress\\portal\\fe\\hnt\\blue" +green_path: "E:\\deploy\\vpress\\portal\\fe\\hnt\\green" \ No newline at end of file diff --git a/inventory/uat/host_vars/hnt-resource-backend.yml b/inventory/uat/host_vars/hnt-resource-backend.yml new file mode 100644 index 0000000..c1fd45a --- /dev/null +++ b/inventory/uat/host_vars/hnt-resource-backend.yml @@ -0,0 +1,8 @@ +temp_dir: "E:\\deploy\\vpress\\temp" +iis_site_name: "resource.vpress.vn" +app_pool_name: "resource.vpress.vn" + +blue_path: "E:\\deploy\\vpress\\resource\\hnt\\blue" +green_path: "E:\\deploy\\vpress\\resource\\hnt\\green" + +aspnetcore_environment: "Uat" \ No newline at end of file diff --git a/inventory/uat/host_vars/ktdt-portal-backend.yml b/inventory/uat/host_vars/ktdt-portal-backend.yml new file mode 100644 index 0000000..8bb408e --- /dev/null +++ b/inventory/uat/host_vars/ktdt-portal-backend.yml @@ -0,0 +1,8 @@ +temp_dir: "E:\\deploy\\vpress\\temp" +iis_site_name: "api-portal-2025" +app_pool_name: "api-portal-2025" + +blue_path: "E:\\deploy\\vpress\\portal\\be\\ktdt\\blue" +green_path: "E:\\deploy\\vpress\\portal\\be\\ktdt\\green" + +aspnetcore_environment: "Uat_Ktdt" \ No newline at end of file diff --git a/inventory/uat/host_vars/ktdt-portal-frontend.yml b/inventory/uat/host_vars/ktdt-portal-frontend.yml new file mode 100644 index 0000000..755b8cb --- /dev/null +++ b/inventory/uat/host_vars/ktdt-portal-frontend.yml @@ -0,0 +1,6 @@ +temp_dir: "E:\\deploy\\vpress\\temp" +iis_site_name: "uat-portal.vpress.vn" +app_pool_name: "uat-portal.vpress.vn" + +blue_path: "E:\\deploy\\vpress\\portal\\fe\\ktdt\\blue" +green_path: "E:\\deploy\\vpress\\portal\\fe\\ktdt\\green" \ No newline at end of file diff --git a/inventory/uat/host_vars/ktdt-resource-backend.yml b/inventory/uat/host_vars/ktdt-resource-backend.yml new file mode 100644 index 0000000..036e083 --- /dev/null +++ b/inventory/uat/host_vars/ktdt-resource-backend.yml @@ -0,0 +1,8 @@ +temp_dir: "E:\\deploy\\vpress\\temp" +iis_site_name: "resource.vpress.vn" +app_pool_name: "resource.vpress.vn" + +blue_path: "E:\\deploy\\vpress\\resource\\ktdt\\blue" +green_path: "E:\\deploy\\vpress\\resource\\ktdt\\green" + +aspnetcore_environment: "Uat" \ No newline at end of file diff --git a/inventory/uat/hosts.ini b/inventory/uat/hosts.ini new file mode 100644 index 0000000..ebc855e --- /dev/null +++ b/inventory/uat/hosts.ini @@ -0,0 +1,28 @@ +[ktdt_portal_backend] +ktdt-portal-backend ansible_host=123.30.172.34 ansible_user=jenkins_cicd ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore + +[hnt_portal_backend] +hnt-portal-backend ansible_host=123.30.172.34 ansible_user=jenkins_cicd ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore + +[ktdt_portal_frontend] +ktdt-portal-frontend ansible_host=123.30.172.34 ansible_user=jenkins_cicd ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore + +[hnt_portal_frontend] +hnt-portal-frontend ansible_host=123.30.172.34 ansible_user=jenkins_cicd ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore + +[acp_backend] +acp-backend ansible_host=123.30.172.34 ansible_user=jenkins_cicd ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore + +[acp_frontend] +acp-frontend ansible_host=123.30.172.34 ansible_user=jenkins_cicd 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.172.34 ansible_user=jenkins_cicd ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore + +[hnt_resource_backend] +hnt-resource-backend ansible_host=123.30.172.34 ansible_user=jenkins_cicd ansible_password=Thienthien123@ ansible_connection=winrm ansible_port=5985 ansible_winrm_transport=ntlm ansible_winrm_server_cert_validation=ignore + + + + + 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 new file mode 100644 index 0000000..d9703ae --- /dev/null +++ b/playbooks/backend/deploy_hnt_portal_backend.yml @@ -0,0 +1,4 @@ +- name: Deploy Backend for Project Portal + hosts: hnt-portal-backend + roles: + - deploy-be-portal diff --git a/playbooks/backend/deploy_hnt_resource_backend.yml b/playbooks/backend/deploy_hnt_resource_backend.yml new file mode 100644 index 0000000..8cef158 --- /dev/null +++ b/playbooks/backend/deploy_hnt_resource_backend.yml @@ -0,0 +1,5 @@ +- name: Deploy Backend for Project Resource + hosts: hnt-resource-backend + roles: + - deploy-be-resource + \ No newline at end of file diff --git a/playbooks/backend/deploy_ktdt_portal_backend.yml b/playbooks/backend/deploy_ktdt_portal_backend.yml new file mode 100644 index 0000000..ed1af4b --- /dev/null +++ b/playbooks/backend/deploy_ktdt_portal_backend.yml @@ -0,0 +1,5 @@ +- name: Deploy Backend for Project Portal + hosts: ktdt-portal-backend + roles: + - deploy-be-portal + \ No newline at end of file diff --git a/playbooks/backend/deploy_ktdt_resource_backend.yml b/playbooks/backend/deploy_ktdt_resource_backend.yml new file mode 100644 index 0000000..46d041f --- /dev/null +++ b/playbooks/backend/deploy_ktdt_resource_backend.yml @@ -0,0 +1,5 @@ +- name: Deploy Backend for Project Resource + hosts: ktdt-resource-backend + roles: + - deploy-be-resource + \ No newline at end of file diff --git a/playbooks/deploy_be.yml b/playbooks/deploy_be.yml deleted file mode 100644 index 65aff32..0000000 --- a/playbooks/deploy_be.yml +++ /dev/null @@ -1,5 +0,0 @@ -- name: Deploy Backend for Project Acp, Portal - hosts: "{{ target_host }}" - roles: - - deploy - \ No newline at end of file diff --git a/playbooks/deploy_fe.yml b/playbooks/deploy_fe.yml deleted file mode 100644 index aa608f4..0000000 --- a/playbooks/deploy_fe.yml +++ /dev/null @@ -1,4 +0,0 @@ -- name: Deploy Frontend for Project Acp, Portal - hosts: "{{ target_host }}" - roles: - - deploy 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..c670363 --- /dev/null +++ b/roles/deploy-be-acp/tasks/main.yml @@ -0,0 +1,37 @@ +- 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: start_iis_app_pool + import_role: + name: iis_utils + tasks_from: start_iis_app_pool.yml + +- name: set_site_aspnetcore_environment + import_role: + name: iis_utils + tasks_from: set_site_aspnetcore_environment.yml + + + diff --git a/roles/deploy-be-portal/tasks/main.yml b/roles/deploy-be-portal/tasks/main.yml new file mode 100644 index 0000000..c670363 --- /dev/null +++ b/roles/deploy-be-portal/tasks/main.yml @@ -0,0 +1,37 @@ +- 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: start_iis_app_pool + import_role: + name: iis_utils + tasks_from: start_iis_app_pool.yml + +- name: set_site_aspnetcore_environment + import_role: + name: iis_utils + tasks_from: set_site_aspnetcore_environment.yml + + + diff --git a/roles/deploy-be-resource/tasks/main.yml b/roles/deploy-be-resource/tasks/main.yml new file mode 100644 index 0000000..41dcf64 --- /dev/null +++ b/roles/deploy-be-resource/tasks/main.yml @@ -0,0 +1,39 @@ +- 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: start_iis_app_pool + import_role: + name: iis_utils + tasks_from: start_iis_app_pool.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..ad56107 --- /dev/null +++ b/roles/deploy-fe-acp/tasks/main.yml @@ -0,0 +1,33 @@ +- 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: start_iis_app_pool + import_role: + name: iis_utils + tasks_from: start_iis_app_pool.yml + + + + diff --git a/roles/deploy-fe-portal/tasks/main.yml b/roles/deploy-fe-portal/tasks/main.yml new file mode 100644 index 0000000..08104ed --- /dev/null +++ b/roles/deploy-fe-portal/tasks/main.yml @@ -0,0 +1,31 @@ +- 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: start_iis_app_pool + import_role: + name: iis_utils + tasks_from: start_iis_app_pool.yml + + 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 caeef62..0000000 --- a/roles/deploy/tasks/deploy.yml +++ /dev/null @@ -1,28 +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 }}" - -# Kiểm tra xem artifact đã được tải thành công chưa -- name: Verify artifact download - fail: - msg: "Failed to download artifact from Nexus." - when: download_status is failed - -# Giải nén artifact vào thư mục target -- name: Deploy Backend 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 25c7805..0000000 --- a/roles/deploy/tasks/setup.yml +++ /dev/null @@ -1,43 +0,0 @@ -- name: Debug iis_site_name - debug: - var: iis_site_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 - -# Chuẩn hóa giá trị của active_path -- name: Normalize active_path - set_fact: - active_path: "{{ active_path.stdout | trim }}" - -# Debug các biến quan trọng -- name: Debug active_path - debug: - var: active_path - -- name: Debug blue_path - debug: - var: blue_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 - -- name: Debug target_path - debug: - var: target_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 \ 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 - diff --git a/roles/iis_utils/tasks/artifact_deploy.yml b/roles/iis_utils/tasks/artifact_deploy.yml new file mode 100644 index 0000000..f4ebd20 --- /dev/null +++ b/roles/iis_utils/tasks/artifact_deploy.yml @@ -0,0 +1,14 @@ +- name: Validate variables + assert: + that: + - artifact_name is defined and artifact_name | length > 0 + - target_path is defined and target_path | length > 0 + - temp_dir is defined and temp_dir | length > 0 + fail_msg: "Thiếu hoặc rỗng biến cần thiết để deploy artifact!" + +# 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 \ No newline at end of file diff --git a/roles/iis_utils/tasks/artifact_download.yml b/roles/iis_utils/tasks/artifact_download.yml new file mode 100644 index 0000000..6f17af0 --- /dev/null +++ b/roles/iis_utils/tasks/artifact_download.yml @@ -0,0 +1,48 @@ +- name: Validate variables + assert: + that: + - nexus_url is defined and nexus_url | length > 0 + - temp_dir is defined and temp_dir | length > 0 + - artifact_name is defined and artifact_name | length > 0 + - nexus_username is defined and nexus_username | length > 0 + - nexus_password is defined and nexus_password | length > 0 + fail_msg: "Thiếu hoặc rỗng biến cần thiết để download artifact!" + +# 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 \ No newline at end of file diff --git a/roles/iis_utils/tasks/cleanup_temp_artifact.yml b/roles/iis_utils/tasks/cleanup_temp_artifact.yml new file mode 100644 index 0000000..ea33c6a --- /dev/null +++ b/roles/iis_utils/tasks/cleanup_temp_artifact.yml @@ -0,0 +1,12 @@ +- name: Validate variables + assert: + that: + - temp_dir is defined and temp_dir | length > 0 + - artifact_name is defined and artifact_name | length > 0 + fail_msg: "Thiếu hoặc rỗng biến cần thiết để cleanup_temp_artifact!" + +# 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/iis_utils/tasks/get_site_current_active_path.yml b/roles/iis_utils/tasks/get_site_current_active_path.yml new file mode 100644 index 0000000..66ba430 --- /dev/null +++ b/roles/iis_utils/tasks/get_site_current_active_path.yml @@ -0,0 +1,26 @@ +- name: Validate variables + assert: + that: + - iis_site_name is defined and iis_site_name | length > 0 + fail_msg: "Thiếu hoặc rỗng biến cần thiết để get_site_current_active_path!" + +#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" \ No newline at end of file diff --git a/roles/iis_utils/tasks/restart_iis_site.yml b/roles/iis_utils/tasks/restart_iis_site.yml new file mode 100644 index 0000000..23411fc --- /dev/null +++ b/roles/iis_utils/tasks/restart_iis_site.yml @@ -0,0 +1,11 @@ +- name: Validate variables + assert: + that: + - iis_site_name is defined and iis_site_name | length > 0 + fail_msg: "Thiếu hoặc rỗng biến cần thiết để restart_iis_site.yml!" + +# Restart IIS site +- name: Restart IIS site + win_iis_website: + name: "{{ iis_site_name }}" + state: restarted \ No newline at end of file diff --git a/roles/iis_utils/tasks/set_site_aspnetcore_environment.yml b/roles/iis_utils/tasks/set_site_aspnetcore_environment.yml new file mode 100644 index 0000000..1254888 --- /dev/null +++ b/roles/iis_utils/tasks/set_site_aspnetcore_environment.yml @@ -0,0 +1,15 @@ +- name: Validate variables + assert: + that: + - iis_site_name is defined and iis_site_name | length > 0 + - aspnetcore_environment is defined and aspnetcore_environment | length > 0 + fail_msg: "Thiếu hoặc rỗng biến cần thiết để set_site_aspnetcore_environment!" + +# 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 }}"} \ No newline at end of file diff --git a/roles/iis_utils/tasks/set_target_path.yml b/roles/iis_utils/tasks/set_target_path.yml new file mode 100644 index 0000000..53f8cbf --- /dev/null +++ b/roles/iis_utils/tasks/set_target_path.yml @@ -0,0 +1,16 @@ +- name: Validate variables + assert: + that: + - green_path is defined and green_path | length > 0 + - blue_path is defined and blue_path | length > 0 + - active_path is defined and active_path | length > 0 + fail_msg: "Thiếu hoặc rỗng biến cần thiết để set_target_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/iis_utils/tasks/start_iis_app_pool.yml b/roles/iis_utils/tasks/start_iis_app_pool.yml new file mode 100644 index 0000000..e1b9e08 --- /dev/null +++ b/roles/iis_utils/tasks/start_iis_app_pool.yml @@ -0,0 +1,11 @@ +- name: Validate variables + assert: + that: + - app_pool_name is defined and app_pool_name | length > 0 + fail_msg: "Thiếu hoặc rỗng biến cần thiết để start_iis_app_pool.yml!" + +# Start app pool +- name: Start IIS App Pool + win_iis_webapppool: + name: "{{ app_pool_name }}" + state: started \ No newline at end of file diff --git a/roles/iis_utils/tasks/update_iis_physical_path.yml b/roles/iis_utils/tasks/update_iis_physical_path.yml new file mode 100644 index 0000000..79bb8d5 --- /dev/null +++ b/roles/iis_utils/tasks/update_iis_physical_path.yml @@ -0,0 +1,12 @@ +- name: Validate variables + assert: + that: + - iis_site_name is defined and iis_site_name | length > 0 + - target_path is defined and target_path | length > 0 + fail_msg: "Thiếu hoặc rỗng biến cần thiết để set_target_path!" + +# 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 }}" \ No newline at end of file