---
- name: Check if Docker daemon is running
  systemd:
    name: docker
    state: started
    enabled: yes
  become: yes
  register: docker_service

- name: Restart Docker if it was not running
  systemd:
    name: docker
    state: restarted
  become: yes
  when: docker_service.changed

- name: Wait for Docker to be ready
  command: docker info
  register: docker_info
  until: docker_info.rc == 0
  retries: 10
  delay: 3
  become: yes
  ignore_errors: yes

- name: Check Docker networks
  command: docker network ls
  register: docker_networks
  become: yes

- name: Ensure airflow_proxynet network exists
  docker_network:
    name: airflow_proxynet
    state: present
  become: yes
