---
- name: Time Machine Directories
  file:
    path: "{{ timemachine_data_directory }}"
    state: directory

- name: Time Machine Docker Container
  docker_container:
    name: timemachine
    image: awlnx/samba-timemachine:latest
    pull: true
    ports:
      - "{{ timemachine_port }}:445"
    env:
      TMSIZE: "{{ timemachine_volume_size_limit }}"
      PASS: "{{ timemachine_password }}"
      SHARENAME: "{{ timemachine_share_name }}"
    volumes:
      - "{{ timemachine_data_directory }}/data:/backups"
    ulimits:
      - "nofile:1048576:1048576"
    network_mode: bridge
    restart_policy: unless-stopped
    memory: 1g

- name: Install avahi
  apt:
    name: "avahi-daemon"
    state: present
  register: result
  until: result is succeeded

- name: Setup timemachine service for avahi
  template:
    src: timemachine/timemachine.service
    dest: "/etc/avahi/services/timemachine.service"

- name: Reload avahi configuration
  service:
    name: avahi-daemon
    state: reloaded