---
- name: fcron | Install fcron package
  community.general.apk:
    name: fcron
    state: present

- name: fcron | Deny all users to access crontabs
  copy:
    content: |
      all
    dest: /etc/fcron/fcron.deny
    owner: root
    group: fcron
    mode: '640'

- name: fcron | Allow access to crontabs for root and {{ username }}
  copy:
    content: |
      root
      {{ username }}
    dest: /etc/fcron/fcron.allow
    owner: root
    group: fcron
    mode: '640'

# The default PATH is /bin:/usr/bin
- name: fcron | Set PATH inside system crontab (systab)
  lineinfile:
    path: /var/spool/fcron/systab.orig
    line: "PATH=/bin:/usr/bin:/sbin:/usr/sbin"
    insertbefore: BOF
    mode: '640'
    owner: root
    group: root
    state: present
  notify: Recompile fcron systab

- name: fcron | Start fcron service on runlevel default
  service:
    name: fcron
    runlevel: default
    state: started
    enabled: true
