--- - name: make sure ntp_server and ntp_refclocks is not defined assert: that: - ntp_refclocks is not defined - ntp_server is not defined msg: "systemd-timesyncd can not be used as a NTP server or sync to local clocks" - name: install systemd-timesyncd when: (ansible_distribution == 'Debian' and (ansible_distribution_major_version | int) > 10) or (ansible_distribution == 'Ubuntu') apt: name: systemd-timesyncd state: present - name: set ntp servers when: - ntp_client is defined - "'servers' in ntp_client" lineinfile: path: /etc/systemd/timesyncd.conf regexp: '^#?NTP=' line: "NTP={{ ntp_client.servers | map(attribute='name') | join(' ') }}" notify: restart systemd-timesyncd - name: un-set ntp servers when: "ntp_client is not defined or 'servers' not in ntp_client" lineinfile: path: /etc/systemd/timesyncd.conf regexp: '^#?NTP=' line: "#NTP=" notify: restart systemd-timesyncd