locale
The locale.* family of state modules.
| Module | Summary |
|---|---|
locale.present | Ensure a locale is enabled in /etc/locale.gen and generated via locale-gen. |
All states also accept the full set of requisite parameters and Salt-parity state attributes — see Dependencies & Requisites.
locale.present
Ensure a locale is enabled in /etc/locale.gen and generated via locale-gen.
Source: pkg/state/modules/locale/locale_present.go
locale.present ensures a locale (name, defaulting to the state ID) is enabled and generated. It verifies two independent halves: that locale -a lists the locale, and — only on systems that have /etc/locale.gen (the Debian family) — that the locale's line in that file is present and uncommented. Both halves compare locale names case-insensitively with dashes stripped, so en_US.UTF-8 matches the locale -a spelling en_US.utf8.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | No | State ID | locale string to enable (e.g. en_US.UTF-8); defaults to the state ID |
Effects
Check
Runs locale -a and reports a change when the locale is absent from its output. When present, and only when /etc/locale.gen exists, it ALSO verifies the locale's line in that file is present and uncommented — a locale generated out-of-band (localedef, image bakery) or whose line was later commented out is reported as needing a change, so the next Apply re-enables it. On a system without /etc/locale.gen (non-Debian: glibc langpacks, musl), locale -a membership alone satisfies the state.
Apply
On systems with /etc/locale.gen: uncomments the locale's existing line, or appends a new <locale> UTF-8 line when none matches — the file itself is NEVER created if it does not already exist (a system without it is left without it). Then runs locale-gen to regenerate the locale database. Reports Changed with the locale in its details.
Revert
Undoes only what this run's Apply actually changed in /etc/locale.gen (re-commenting the line it uncommented or appended) and re-runs locale-gen. A fresh instance (a standalone revert) recorded nothing and is an explicit clean no-op — a locale.gen line enabled by the distro installer or an admin is never safe to comment out.
Examples
Enable a locale
The locale defaults to the state ID.
en_US.UTF-8:
locale.present:
- require:
- pkg.installed:localesEnable a second locale in order
require orders one locale.gen edit after another (here, de_DE.UTF-8) to avoid concurrent rewrites.
fr_FR.UTF-8:
locale.present:
- require:
- "locale.present:de_DE.UTF-8"Enable a locale ad hoc
The bare positional argument is the locale string.
zester '*' locale.present en_US.UTF-8