Thienvv - first commit - ansible

This commit is contained in:
thienqb123456
2024-12-12 11:53:34 +07:00
commit 1301d3f726
17 changed files with 185 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
# Xóa file tạm
- name: Clean up temporary files
win_file:
path: "{{ temp_dir }}\\{{ artifact_name }}"
state: absent
+25
View File
@@ -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
+28
View File
@@ -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
+16
View File
@@ -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
+43
View File
@@ -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
+10
View File
@@ -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