#####################################
### someone's ansible provisioner ###
#####################################
# Part of: https://git.somenet.org/root/pub/somesible.git
# 2017-2025 by someone <someone@somenet.org>
#
---
- name: install chrony
  apt:
    pkg:
    - chrony
    state: present
    policy_rc_d: 101
  tags: "online"
  ignore_errors: "{{ignore_online_errors | bool}}"


- name: copy config
  copy:
    src: "{{item}}"
    dest: "/etc/chrony/chrony.conf"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/chrony.conf"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/chrony.conf"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/chrony.conf"
    - "default/chrony.{{ntpd_type}}.conf"
  notify: restart chrony.service


- name: copy chrony.service to /etc/systemd/system/
  copy:
    src: "{{item}}"
    dest: "/etc/systemd/system/chrony.service"
    mode: 0644
    owner: "root"
    group: "root"
  with_first_found:
    - "{{lookup('env','PWD')}}/host_files/{{inventory_hostname}}/{{role_name}}/chrony.service"
    - "{{lookup('env','PWD')}}/group_files/{{group_files_group}}/{{role_name}}/chrony.service"
    - "{{lookup('env','PWD')}}/group_files/all/{{role_name}}/chrony.service"
    - "default/chrony.service"
  notify: restart chrony.service


- name: enable and start chrony.service
  include_role: name="base/systemd/enable-and-start"
  vars:
    service_name: chrony.service


- name: disable and mask systemd-timesyncd.service
  systemd:
    name: systemd-timesyncd.service
    daemon_reload: yes
    enabled: no
    masked: yes
  # may have been removed by ntp install. sometimes not.
  ignore_errors: yes
