Thienvv - first commit - ansible
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
[defaults]
|
||||||
|
inventory = ./inventory
|
||||||
|
roles_path = ./roles
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
temp_dir: "C:\\deploy\\vpress\\temp"
|
||||||
|
iis_site_name: "site_test"
|
||||||
|
blue_path: "C:\\deploy\\vpress\\acp\\be\\blue"
|
||||||
|
green_path: "C:\\deploy\\vpress\\acp\\be\\green"
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
temp_dir: "C:\\deploy\\vpress\\temp"
|
||||||
|
iis_site_name: "xx"
|
||||||
|
blue_path: "C:\\deploy\\vpress\\acp\\be\\blue"
|
||||||
|
green_path: "C:\\deploy\\vpress\\acp\\be\\green"
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
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"
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
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"
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
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"
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
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"
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[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_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_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_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_winrm_server_cert_validation=ignore
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[uat_be_acp_webservers]
|
||||||
|
uat_be_acp ansible_host=123.30.172.34 ansible_user=jenkins_cicd ansible_password=Thienthien123@ ansible_connection=winrm 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_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_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_winrm_server_cert_validation=ignore
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
- name: Deploy Backend for Project Acp, Portal
|
||||||
|
hosts: "{{ target_host }}"
|
||||||
|
roles:
|
||||||
|
- deploy
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
- name: Deploy Frontend for Project Acp, Portal
|
||||||
|
hosts: "{{ target_host }}"
|
||||||
|
roles:
|
||||||
|
- deploy
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Xóa file tạm
|
||||||
|
- name: Clean up temporary files
|
||||||
|
win_file:
|
||||||
|
path: "{{ temp_dir }}\\{{ artifact_name }}"
|
||||||
|
state: absent
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# 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
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
- 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
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
- 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
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
- 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
|
||||||
|
|
||||||
Reference in New Issue
Block a user