Pastebin
Retrouvez, créez et partagez vos snippets en temps réel.
Rechercher un Pastebin
Aucun paste trouvé.
Créer un paste
Pastebin
Blog
eezrrrrrrrrrr
--- - name: Deploy FO Frontend to IIS hosts: fo_web gather_facts: yes vars: # Source and destination paths source_path: "/mnt/d/r-CD/packages/FO-frontend/dist" dest_path: "C:\\inetpub\\frontend-frontoffice-r" backup_base_path: "C:\\inetpub\\backups" # IIS Configuration site_name: "FrontendFrontofficeSGAIA" app_pool_name: "FrontendFrontofficeSGAIA" # Backup settings backup_timestamp: "{{ ansible_date_time.iso8601_basic_short }}" backup_path: "{{ backup_base_path }}\\{{ site_name }}_{{ backup_timestamp }}" max_backups_to_keep: 5 tasks: - name: Display deployment information debug: msg: - "Deploying to: {{ inventory_hostname }}" - "Source: {{ source_path }}" - "Destination: {{ dest_path }}" - "Backup will be created at: {{ backup_path }}" - name: Ensure backup directory exists win_file: path: "{{ backup_base_path }}" state: directory - name: Check if current deployment exists win_stat: path: "{{ dest_path }}" register: current_deployment - name: Stop IIS Application Pool win_iis_webapppool: name: "{{ app_pool_name }}" state: stopped when: current_deployment.stat.exists register: apppool_stopped - name: Wait for application pool to stop win_shell: | $pool = Get-IISAppPool -Name "{{ app_pool_name }}" $timeout = 30 $elapsed = 0 while ($pool.State -ne 'Stopped' -and $elapsed -lt $timeout) { Start-Sleep -Seconds 2 $elapsed += 2 $pool = Get-IISAppPool -Name "{{ app_pool_name }}" } Write-Output $pool.State when: apppool_stopped.changed register: pool_state - name: Stop IIS Website win_iis_website: name: "{{ site_name }}" state: stopped when: current_deployment.stat.exists ignore_errors: yes - name: Create backup of current deployment win_shell: | if (Test-Path "{{ dest_path }}") { Copy-Item -Path "{{ dest_path }}" -Destination "{{ backup_path }}" -Recurse -Force Write-Output "Backup created at {{ backup_path }}" } else { Write-Output "No existing deployment to backup" } when: current_deployment.stat.exists register: backup_result - name: Display backup result debug: msg: "{{ backup_result.stdout_lines }}" when: backup_result.stdout_lines is defined - name: Get list of existing backups win_find: paths: "{{ backup_base_path }}" patterns: "{{ site_name }}_*" file_type: directory register: existing_backups - name: Clean up old backups (keep last {{ max_backups_to_keep }}) win_file: path: "{{ item.path }}" state: absent with_items: "{{ (existing_backups.files | sort(attribute='lastwritetime') | reverse)[max_backups_to_keep:] }}" when: existing_backups.matched > max_backups_to_keep - name: Remove old deployment files win_shell: | if (Test-Path "{{ dest_path }}") { Get-ChildItem -Path "{{ dest_path }}" -Recurse | Remove-Item -Force -Recurse Write-Output "Old files removed from {{ dest_path }}" } when: current_deployment.stat.exists - name: Ensure destination directory exists win_file: path: "{{ dest_path }}" state: directory - name: Copy new frontend files to IIS server win_copy: src: "{{ source_path }}/" dest: "{{ dest_path }}" remote_src: no register: copy_result - name: Verify files were copied win_find: paths: "{{ dest_path }}" recurse: no register: deployed_files - name: Display deployed files count debug: msg: "Deployed {{ deployed_files.matched }} files/folders to {{ dest_path }}" - name: Ensure Application Pool exists with correct settings win_iis_webapppool: name: "{{ app_pool_name }}" state: started attributes: managedRuntimeVersion: "" # No Managed Code for static sites managedPipelineMode: Integrated processModel.idleTimeout: "00:20:00" recycling.periodicRestart.time: "1.05:00:00" - name: Ensure IIS Website exists with correct configuration win_iis_website: name: "{{ site_name }}" physical_path: "{{ dest_path }}" application_pool: "{{ app_pool_name }}" state: started port: 80 # ip: "*" # hostname: "frontoffice.yourdomain.com" # Uncomment and set if needed - name: Start IIS Application Pool win_iis_webapppool: name: "{{ app_pool_name }}" state: started - name: Start IIS Website win_iis_website: name: "{{ site_name }}" state: started - name: Wait for site to be responsive win_uri: url: "http://localhost" method: GET status_code: 200,301,302,404 # Accept various status codes timeout: 30 register: site_check retries: 3 delay: 5 ignore_errors: yes - name: Display site status debug: msg: "Site is {{ 'responding' if site_check.status_code is defined else 'not responding - check manually' }}" - name: Create deployment log entry win_shell: | $logPath = "{{ backup_base_path }}\\deployment_log.txt" $logEntry = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Deployed to {{ inventory_hostname }} - Backup: {{ backup_path }}" Add-Content -Path $logPath -Value $logEntry ignore_errors: yes - name: Display deployment summary debug: msg: - "=== Deployment Summary ===" - "Server: {{ inventory_hostname }}" - "Site: {{ site_name }}" - "Deployment Path: {{ dest_path }}" - "Backup Path: {{ backup_path }}" - "Files Deployed: {{ deployed_files.matched }}" - "Status: SUCCESS"
Créé il y a 1 mois.