Remove stuck portainer_agent container before redeploying

If the container exists but is in a Restarting state (e.g. due to a
stale AGENT_HOST env var), remove it so the deploy task creates a
fresh container with the correct config.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
sam 2026-03-01 01:30:11 -07:00
parent 9fa819a10d
commit fd71d5b82c

View File

@ -107,6 +107,12 @@
changed_when: false changed_when: false
failed_when: false failed_when: false
- name: Remove portainer_agent container if stuck in restart loop
community.docker.docker_container:
name: portainer_agent
state: absent
when: "'Restarting' in (agent_status.stdout | default(''))"
- name: Pull Portainer Agent image - name: Pull Portainer Agent image
community.docker.docker_image: community.docker.docker_image:
name: portainer/agent name: portainer/agent