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