2017-11-30 14:28:28 +00:00
|
|
|
---
|
|
|
|
- name: See if NTProtocol active
|
2020-12-03 13:48:53 +00:00
|
|
|
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
|
2017-11-30 14:28:28 +00:00
|
|
|
register: timedatectl
|
|
|
|
|
|
|
|
|
2020-12-03 13:48:53 +00:00
|
|
|
- name: 'Fail if "timedatectl" could not be executed"'
|
|
|
|
fail:
|
|
|
|
msg: 'Could not execute "timedatectl", give up....'
|
|
|
|
when: timedatectl is failed
|
|
|
|
|
|
|
|
|
2017-11-30 14:28:28 +00:00
|
|
|
- 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
|
|
|
|
|
|
|
|
|