v3 #1
@@ -1,4 +1,5 @@
|
||||
temp_dir: "C:\\deploy\\vpress\\temp"
|
||||
iis_site_name: "demo.kinhtedothi.vn"
|
||||
iis_site_name_1: "demo.kinhtedothi.vn"
|
||||
iis_site_name_2: "hnt.kinhtedothi.vn"
|
||||
blue_path: "C:\\deploy\\vpress\\portal\\fe\\blue"
|
||||
green_path: "C:\\deploy\\vpress\\portal\\fe\\green"
|
||||
@@ -1,4 +1,5 @@
|
||||
temp_dir: "C:\\deploy\\vpress\\temp"
|
||||
iis_site_name: "uat-portal.vpress.vn"
|
||||
iis_site_name_1: "uat-portal.vpress.vn"
|
||||
iis_site_name_2: "uat-portal2"
|
||||
blue_path: "C:\\deploy\\vpress\\portal\\fe\\blue"
|
||||
green_path: "C:\\deploy\\vpress\\portal\\fe\\green"
|
||||
@@ -0,0 +1,4 @@
|
||||
- name: Deploy Frontend for Project Acp, Portal
|
||||
hosts: "{{ deploy_env }}-{{project_name}}-frontend"
|
||||
roles:
|
||||
- deploy-fe-portal
|
||||
@@ -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,45 @@
|
||||
# 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
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
- name: Setup environment
|
||||
import_tasks: setup.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,51 @@
|
||||
#Debug
|
||||
- name: Debug iis_site_name_1
|
||||
debug:
|
||||
var: iis_site_name_1
|
||||
|
||||
- name: Debug iis_site_name_2
|
||||
debug:
|
||||
var: iis_site_name_2
|
||||
|
||||
- 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_1 }}"
|
||||
$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
|
||||
@@ -0,0 +1,15 @@
|
||||
- name: Update site 1 IIS web application
|
||||
win_iis_website:
|
||||
name: "{{ iis_site_name_1 }}"
|
||||
physical_path: "{{ target_path }}"
|
||||
|
||||
- name: Update site 2 IIS web application
|
||||
win_iis_website:
|
||||
name: "{{ iis_site_name_2 }}"
|
||||
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