---

- block:
  - name: ensure directories exist
    file:
      path: "{{ item }}"
      state: directory
      owner: root
      group: root
      mode: "0755"
    with_items:
      - "{{ docker_compose_gc_root }}"
      - "{{ docker_gc_etc_root }}"

  - name: install docker-gc docker-compose.yml
    copy:
      src: docker-compose.yml
      dest: "{{ docker_compose_gc_root }}/docker-compose.yml"
      owner: root
      group: root
      mode: "0644"

  - name: configure images and containers to not gc
    template:
      src: "{{ item }}"
      dest: "{{ docker_gc_etc_root }}/{{ item }}"
      owner: root
      group: root
      mode: "0644"
    with_items:
      - docker-gc-exclude
      - docker-gc-exclude-containers

  - name: install wrapper script
    copy:
      src: bin/docker-gc
      dest: /usr/local/bin/docker-gc
      owner: root
      group: root
      mode: "0755"

  - name: install cron definition
    template:
      src: cron.d/docker-gc
      dest: /etc/cron.d/docker-gc
      owner: root
      group: root
      mode: "0644"
  become: yes
