Skip to content

Instantly share code, notes, and snippets.

@JamesTheBard
Last active January 29, 2024 14:55
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesTheBard/9cd577c5ad3b8e21ad9dc82355cc5152 to your computer and use it in GitHub Desktop.
Save JamesTheBard/9cd577c5ad3b8e21ad9dc82355cc5152 to your computer and use it in GitHub Desktop.
Configure NTP Client for `timedatectl` via `systemd-timesyncd`
# vim:ts=2:sts=2:sw=2:et
#===========================================================
# NTP Configuration Playbook
#===========================================================
# This script will remove the 'ntp' daemon from each server
# and properly configure the 'systemd-timesyncd' daemon so
# that 'timedatectl' uses a specific NTP server. Remember
# to create a 'timesyncd.conf' file that holds your config
# in the same directory as this ansible playbook before
# running.
#-----------------------------------------------------------
# There are two categories managed: 'arch' and 'ubuntu'.
# When you create your hosts file, keep this in mind.
#===========================================================
---
- hosts: arch
remote_user: remoteuser
become: true
become_user: root
tasks:
- name: Uninstall 'ntp' package
pacman:
name: ntp
state: absent
- hosts: ubuntu
remote_user: remoteuser
become: true
become_user: root
tasks:
- name: Uninstall 'ntp' package
apt:
name: ntp
state: absent
- hosts: all
remote_user: remoteuser
become: true
become_user: root
tasks:
- name: Disabling "systemd-timesyncd"
systemd:
name: systemd-timesyncd
state: stopped
enabled: false
- name: Copying "timesyncd.conf" to "/etc/systemd".
copy:
src: timesyncd.conf
dest: /etc/systemd/timesyncd.conf
mode: 0644
owner: root
group: root
- name: Enabling "systemd-timesyncd"
systemd:
name: systemd-timesyncd
state: started
enabled: true
- name: Turning "set-ntp" on
command: /usr/bin/timedatectl set-ntp on
# This is where you put your NTP server configurations at.
# Since I run my own NTP server on the network, I've changed
# the default settings in the /etc/systemd/timesyncd.conf
# file.
#------------------------------------------------------------
[Time]
NTP=time.localdomain.local
FallbackNTP=time.localdomain.local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment