---
# Run this whole role with `become: True`.
- name: copy resource-usage.sh to remote
  ansible.builtin.copy:
    src: ../scripts/resource-usage.sh
    dest: /home/safe/resource-usage.sh
    owner: safe
    group: safe
    mode: '0744'

- name: ensure the logging directory exists
  ansible.builtin.file:
    path: /home/safe/.local/share/safe/node
    state: directory
    owner: safe
    group: safe
    mode: '0755'

- name: create systemd service for resource-usage
  ansible.builtin.template:
    src: resource-usage.service.j2
    dest: /etc/systemd/system/resource-usage.service

- name: enable and start resource-usage service
  ansible.builtin.systemd_service:
    name: resource-usage
    state: started
    enabled: yes
    daemon_reload: yes
