---
# NOTE: chrony package comes with a default /etc/chrony/chrony.conf
# => No need to create a parent directory here
- name: chrony | Copy chrony.conf
  template:
    src: ntpd/chrony.conf.j2
    dest: /etc/chrony/chrony.conf
    owner: root
    group: root
    mode: '644'

# - Basically just run chronyd on foreground
# - https://wiki.archlinux.org/title/Chrony#For_intermittently_running_desktops
- name: chrony | Change default configuration for chronyd service
  lineinfile:
    path: /etc/conf.d/chronyd
    line: '{{ item }}'
    search_string: '{{ item | regex_replace("=.*$", "") }}'
    owner: root
    group: root
    mode: '644'
    state: present
  loop:
    - FAST_STARTUP=yes
    - ARGS="-s -r"

- name: chrony | Start chronyd service on runlevel 'default'
  service:
    name: chronyd
    enabled: true
    state: started
    runlevel: default
