---
- name: Install Tarsnap
  pacman: name=tarsnap state=present

- name: Copy default Tarsnap config
  copy: src=/etc/tarsnap/tarsnap.conf.sample dest=/etc/tarsnap/tarsnap.conf

- name: Create Tarsnap cache dir
  file: path=/usr/local/tarsnap-cache state=directory

- name: Humanize Tarsnap numbers
  lineinfile: dest=/etc/tarsnap/tarsnap.conf
              state=present
              line=humanize-numbers

- name: Install Tarsnapper into virtual environment
  pip: name=tarsnapper
       virtualenv=/usr/local/env/tarsnapper
       virtualenv_command=virtualenv3

- name: Link Tarsnapper to bin
  file: src=/usr/local/env/tarsnapper/bin/tarsnapper
        dest=/usr/local/bin/tarsnapper
        state=link

- name: Create Tarsnapper config include dir
  file: path=/usr/local/etc/tarsnapper.d/ state=directory

- name: Push Tarsnapper config
  template: src=tarsnapper.conf.j2 dest=/usr/local/etc/tarsnapper.conf

- name: Push Tarsnapper service file
  template: src=tarsnapper.service.j2 dest=/etc/systemd/system/tarsnapper.service
  notify:
    - reload systemd config

- name: Push Tarsnapper timer file
  template: src=tarsnapper.timer.j2 dest=/etc/systemd/system/tarsnapper.timer
  notify:
    - reload systemd config
    - restart tarsnapper

- include_tasks: roles/nmtrust/tasks/unit.yml
  vars:
      unit: tarsnapper.timer
      run_on: "{{ tarsnapper.run_on }}"
