--- - 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