GuidesModules
timezone.system
Ensures the system timezone is set to a desired value. Uses timedatectl as the primary mechanism with a fallback to /etc/timezone + dpkg-reconfigure.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name | string | state ID | Timezone string (e.g. "America/New_York", "UTC") |
utc | bool | false | Set the hardware clock to UTC (timedatectl set-local-rtc 0) |
Behavior
Check
- Runs
timedatectl show --property=Timezone --valueand trims whitespace. - If
timedatectlfails (not available), falls back to reading/etc/timezone. - Compares to the desired timezone. Match →
NeedsChange: false; otherwiseNeedsChange: true.
Apply
- Reads current timezone before making changes (stored for Revert).
- Runs
timedatectl set-timezone <timezone>. - If
timedatectlfails, writes<timezone>to/etc/timezoneand runsdpkg-reconfigure -f noninteractive tzdata. - If
utc: true, additionally runstimedatectl set-local-rtc 0.
Revert
Restores the timezone that was active before Apply ran by calling timedatectl set-timezone <previousTZ>. If Apply was never called, Revert is a no-op (previous timezone is unknown).
Examples
# Set timezone to UTC
UTC:
timezone.system: []
# Set a regional timezone and sync hardware clock
America/Chicago:
timezone.system:
- utc: true
- require:
- pkg.installed:tzdata
# Use explicit name parameter
system-timezone:
timezone.system:
- name: Europe/BerlinNotes
- Timezone strings must match entries in the IANA Time Zone Database (e.g.
America/New_York, notEST). - On systems without
timedatectl(non-systemd), the fallback writes/etc/timezoneand invokesdpkg-reconfigure tzdata. Thedpkg-reconfigurebinary must be available. - The
utcparameter only affects the hardware clock setting, not the timezone string itself.