Added deletion of containers to reset routine

This commit is contained in:
2025-08-15 20:05:05 +02:00
parent cb539b038c
commit e9a41bd40c
4 changed files with 22 additions and 6 deletions

View File

@@ -0,0 +1,20 @@
- name: Gather containers
community.docker.docker_host_info:
containers: true
register: docker_info
- name: Remove containers (stops running ones)
community.docker.docker_container:
name: "{{ (item.Names | default([item.Name]))[0] | regex_replace('^/','') }}"
state: absent
force_kill: true
remove_volumes: false # NEVER SET TO TRUE - PREVENTS DELETION OF VOLUMES
loop: "{{ docker_info.containers }}"
loop_control:
label: "{{ (item.Names | default([item.Name]))[0] }}"
when: docker_info.containers | length > 0
- name: Trigger Docker restart
ansible.builtin.debug:
msg: "MODE_RESET is enabled → restarting Docker"
notify: Restart Docker