GuidesModules
locale.present
Ensures a locale is enabled in /etc/locale.gen and generated via locale-gen.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name | string | state ID | Locale string to enable (e.g. "en_US.UTF-8", "de_DE.UTF-8") |
Behavior
Check
Runs locale -a and checks whether the target locale appears in the output. Comparison is case-insensitive and ignores - characters (so en_US.UTF-8 matches en_US.utf8 in output).
Apply
- Reads
/etc/locale.gen. If the locale line is commented out, uncomments it. If the file does not contain the locale at all, appends it. Creates the file if it does not exist. - Runs
locale-gento regenerate the locale database.
Revert
- Re-comments the locale line in
/etc/locale.gen. - Runs
locale-gento regenerate without the locale.
Examples
# Enable US English UTF-8 locale
en_US.UTF-8:
locale.present:
- require:
- pkg.installed:locales
# Enable multiple locales
de_DE.UTF-8:
locale.present: []
fr_FR.UTF-8:
locale.present:
- require:
- locale.present:de_DE.UTF-8Notes
- This module is targeted at Debian/Ubuntu systems that use
/etc/locale.genandlocale-gen. - On Red Hat-based systems, locale management uses
localectl— usecmd.runwithlocalectl set-localeinstead. - The
localebinary andlocale-genmust be available on the target system (localespackage on Debian/Ubuntu). - Locale names in
/etc/locale.genmust include the encoding suffix (e.g.en_US.UTF-8 UTF-8). The module appendsUTF-8as a default encoding when adding a new line.