Debian, locales, and puppet

Having gotten sick and tired of receiving error messages like this:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
I decided to solve the problem once and for all. We use puppet to manage machines, so this should be - and is - straight forward. /etc/puppet/modules/locales/files/locales.gen:
#
# /etc/locales.gen
#
# managed by puppet
#
en_US ISO-8859-1
en_US.ISO-8859-15 ISO-8859-15
en_US.UTF-8 UTF-8
/etc/puppet/modules/locales/manifests/init.pp:
class locales {
package { "locales":
ensure => latest,
}
file { "/etc/locale.gen":
source => [
"puppet://$server/files/locales/host/locale.gen.$fqdn",
"puppet://$server/files/locales/host/locale.gen.$hostname",
"puppet://$server/files/locales/env/locale.gen.$environment",
"puppet://$server/files/locales/locale.gen",
"puppet://$server/locales/locale.gen",
],
owner => "root",
group => "root",
mode => 644,
require => Package[locales],
}
exec { "/usr/sbin/locale-gen":
subscribe => File["/etc/locale.gen"],
refreshonly => true,
require => Package[locales],
require => File["/etc/locale.gen"],
}
}
Note that the code above permits server-specific, or environment specific files to override the default file found in the module. As well, the locale.gen will not get downloaded until AFTER the locales package has been installed, and locale-gen will not attempt to run until after the locale.gen file has been installed. -jbn

Tags: