roles_timesync/roles/timesync-enabled/tasks/timesync_timesyncd.yml
2020-12-03 14:48:53 +01:00

32 lines
714 B
YAML

---
- name: See if NTProtocol active
shell: 'timedatectl | grep "\(NTP service\|NTP enabled\|Network time on\):" | cut -d: -f 2 | grep -o "active\|inactive\|yes\|no\|n/a"'
ignore_errors: True
register: timedatectl
- name: 'Fail if "timedatectl" could not be executed"'
fail:
msg: 'Could not execute "timedatectl", give up....'
when: timedatectl is failed
- name: Template configuration
template:
src: etc/systemd/timesyncd.conf.j2
dest: /etc/systemd/timesyncd.conf
notify: Restart systemd-timesyncd
- name: Activate NTProtocol
command: timedatectl set-ntp true
when: timedatectl.stdout == "no"
- name: Enable service
service:
name: systemd-timesyncd
enabled: True