- name: Collect service facts
  ansible.builtin.service_facts:
  listen: docker_configured

- name: Restart Docker service
  become: true
  when: |
    'docker.service' in ansible_facts.services and ansible_facts.services['docker.service'].state == 'running'
  ansible.builtin.systemd_service:
    name: docker
    state: restarted
  listen: docker_configured