- 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
  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