traefik-deploy/ansible/rollback-traefik.yml
2025-10-08 16:03:46 -04:00

43 lines
No EOL
1.2 KiB
YAML

---
- name: Rollback Traefik
hosts: traefik_servers
become: yes
vars:
current_color_file: "/tmp/traefik_current_color"
tasks:
- name: Read current color
slurp:
src: "{{ current_color_file }}"
register: current_color_raw
ignore_errors: yes
- name: Set rollback color
set_fact:
current_color: "{{ current_color_raw.content | b64decode | trim if current_color_raw.content is defined else 'blue' }}"
rollback_color: "{{ 'green' if (current_color_raw.content | b64decode | trim if current_color_raw.content is defined else 'blue') == 'blue' else 'blue' }}"
- name: Stop current
systemd:
name: "traefik-{{ current_color }}"
state: stopped
- name: Start previous
systemd:
name: "traefik-{{ rollback_color }}"
state: started
enabled: yes
- name: Update marker
copy:
content: "{{ rollback_color }}"
dest: "{{ current_color_file }}"
- name: Wait for health
uri:
url: "http://localhost:8080/ping"
status_code: 200
register: result
until: result.status == 200
retries: 10
delay: 2