Pastebin
Retrouvez, créez et partagez vos snippets en temps réel.
Rechercher un Pastebin
Aucun paste trouvé.
Créer un paste
Pastebin
Blog
eezrrrrrrrrrrdddd
--- - name: Rollback FO Frontend Deployment hosts: fo_web gather_facts: yes vars: dest_path: "C:\\inetpub\\frontend-frontoffice-sgaia" backup_base_path: "C:\\inetpub\\backups" site_name: "FrontendFrontofficeSGAIA" app_pool_name: "FrontendFrontofficeSGAIA" # Specify backup to restore (leave empty to use latest) backup_to_restore: "" # Format: FrontendFrontofficeSGAIA_20250101T120000 tasks: - name: Get list of available backups win_find: paths: "{{ backup_base_path }}" patterns: "{{ site_name }}_*" file_type: directory register: available_backups - name: Fail if no backups available fail: msg: "No backups found in {{ backup_base_path }}" when: available_backups.matched == 0 - name: Display available backups debug: msg: "{{ available_backups.files | map(attribute='filename') | list }}" - name: Determine backup to restore set_fact: selected_backup: "{{ backup_to_restore if backup_to_restore else (available_backups.files | sort(attribute='lastwritetime', reverse=true) | first).path }}" - name: Display selected backup debug: msg: "Restoring from: {{ selected_backup }}" - name: Verify backup exists win_stat: path: "{{ selected_backup }}" register: backup_exists - name: Fail if backup doesn't exist fail: msg: "Backup not found: {{ selected_backup }}" when: not backup_exists.stat.exists - name: Stop IIS Application Pool win_iis_webapppool: name: "{{ app_pool_name }}" state: stopped - name: Stop IIS Website win_iis_website: name: "{{ site_name }}" state: stopped ignore_errors: yes - name: Create pre-rollback backup of current state win_shell: | $timestamp = Get-Date -Format "yyyyMMddTHHmmss" $preRollbackPath = "{{ backup_base_path }}\\{{ site_name }}_pre_rollback_$timestamp" if (Test-Path "{{ dest_path }}") { Copy-Item -Path "{{ dest_path }}" -Destination $preRollbackPath -Recurse -Force Write-Output "Pre-rollback backup created at $preRollbackPath" } register: pre_rollback_backup - name: Remove current deployment win_shell: | if (Test-Path "{{ dest_path }}") { Get-ChildItem -Path "{{ dest_path }}" -Recurse | Remove-Item -Force -Recurse Write-Output "Current deployment removed" } - name: Restore files from backup win_shell: | Copy-Item -Path "{{ selected_backup }}\\*" -Destination "{{ dest_path }}" -Recurse -Force Write-Output "Files restored from {{ selected_backup }}" register: restore_result - name: Verify restored files win_find: paths: "{{ dest_path }}" recurse: no register: restored_files - name: Display restored files count debug: msg: "Restored {{ restored_files.matched }} files/folders" - 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 timeout: 30 register: site_check retries: 3 delay: 5 ignore_errors: yes - name: Create rollback log entry win_shell: | $logPath = "{{ backup_base_path }}\\deployment_log.txt" $logEntry = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - ROLLBACK on {{ inventory_hostname }} - Restored: {{ selected_backup }}" Add-Content -Path $logPath -Value $logEntry ignore_errors: yes - name: Display rollback summary debug: msg: - "=== Rollback Summary ===" - "Server: {{ inventory_hostname }}" - "Restored from: {{ selected_backup }}" - "Files Restored: {{ restored_files.matched }}" - "Pre-rollback backup: {{ pre_rollback_backup.stdout_lines[0] if pre_rollback_backup.stdout_lines else 'N/A' }}" - "Status: SUCCESS"
Créé il y a 1 mois.