- name: Omv Setup
  become: "{{ false if inventory_hostname == 'nas.home.lan' else true }}"
  block:
    - name: Include vault
      ansible.builtin.include_vars:
        file: jaydee.yml
        name: mysecrets
      when: inventory_hostname != 'nas.home.lan'
    - name: Delete content & directory
      ansible.builtin.file:
        state: absent
        path: "{{ dest_folder }}"
    - name: Pull repo
      tags:
        - git_pull
      ansible.builtin.git:
        repo: "https://{{ mysecrets['git_user'] | urlencode }}:{{ mysecrets['git_password_mqtt'] | urlencode }}@gitlab.sectorq.eu/jaydee/watcher.git"
        dest: "{{ dest_folder }}"
        update: true
        clone: true
        version: main
      when: inventory_hostname != 'nas.home.lan'
    - name: Print
      ansible.builtin.debug:
        msg: "{{ inventory_hostname }}"

    - name: Upload script
      ansible.builtin.copy:
        src: "{{ dest_folder }}/watcher.sh"
        dest: /usr/bin/watcher.sh
        remote_src: true
        mode: '0755'
        owner: root
        group: root

    - name: Upload service config
      ansible.builtin.copy:
        src: "{{ dest_folder }}/watcher.service"
        dest: /etc/systemd/system/watcher.service
        remote_src: true
        mode: '0755'
        owner: root
        group: root

    - name: Restart watcher service
      ansible.builtin.service:
        name: watcher
        state: restarted
        daemon_reload: true
        enabled: true
