---
- name: Ensure docker required directories are present
  file:
    path: "{{ item }}"
    state: directory
  with_items:
    - "{{ docker_data_path }}"
    - "{{ docker_config_path }}"
  notify: Restart docker daemon

- name: Create docker daemon file
  template:
    src: "docker/{{ item }}"
    dest: "{{ docker_config_path }}/{{ item }}"
  with_items:
    - daemon.json
  notify: Restart docker daemon

- name: Create docker volume garbage collector script
  template:
    src: "docker/volume-garbage-collector.sh"
    dest: "{{ docker_volume_gb_script }}"
    owner: root
    group: root
    mode: 0755
    variable_start_string: "€#"
    variable_end_string: "#€"
    block_start_string: "€%"
    block_end_string: "%€"

- name: Setup docker volume garbage collector cron
  cron:
    name: "clean layerops unused docker volumes"
    job: "{{ docker_volume_gb_script }}"
    minute: "*/5"
