---
- hosts: all
  pre_tasks:
      - name: APT install Python3, Tox, Cron, Unison
        apt:
            name:
                - python3
                - tox
                - cron-daemon
                - unison
            state: present
            update_cache: True
            cache_valid_time: 3600

      - name: Get authorized keys
        become: False
        slurp:
            src: ~/.ssh/authorized_keys
        register: authorized_keys
  roles:
      - name: gitreceive
        gitreceive_public_keys: "{{ (authorized_keys['content']|b64decode).splitlines() }}"
        gitreceive_receiver_script: |
            #!/bin/sh
            set -eu
            echo '----> Unpacking ...'
            mkdir -p ~/poquita
            cd ~/poquita
            tar -xf -
            if [ -f receiver ] && [ -x receiver ]
            then
                echo '----> Running receiver ...'
                ./receiver
            fi
            echo '----> OK.'
  post_tasks:
      - name: Create Podcasts directory
        file:
            path: /srv/library/nimrod/Podcasts
            state: directory
            owner: nimrod
            group: git
            mode: 0o0775
