Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bug#955733: cloud-init does not set locale specified in user data

519 views
Skip to first unread message

Nick Holloway

unread,
Apr 4, 2020, 7:10:03 AM4/4/20
to
Package: cloud-init
Version: 18.3-6

I am launching a Buster 10.3 EC2 instance with the following user data
to initialise and set the default locale:

#cloud-config
hostname: argon
locale: en_GB.UTF-8
timezone: Europe/London

This fails to set the locale, and "systemctl status cloud-init" shows:

Apr 04 11:00:30 argon systemd[1]: Starting Apply the settings specified in cloud-config...
Apr 04 11:00:43 argon cloud-init[546]: Generating locales (this might take a while)...
Apr 04 11:00:43 argon cloud-init[546]: Generation complete.
Apr 04 11:00:43 argon cloud-init[546]: *** update-locale: Error: invalid locale settings: LANG=en_GB.UTF-8
Apr 04 11:00:43 argon cloud-init[546]: Cloud-init v. 18.3 running 'modules:config' at Sat, 04 Apr 2020 10:00:41 +0000. Up 21.77 seconds.
Apr 04 11:00:43 argon cloud-init[546]: 2020-04-04 10:00:43,604 - util.py[WARNING]: Running module locale (<module 'cloudinit.config.cc_locale' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_locale.py'>) failed
Apr 04 11:00:45 argon systemd[1]: cloud-config.service: Main process exited, code=exited, status=1/FAILURE
Apr 04 11:00:45 argon systemd[1]: cloud-config.service: Failed with result 'exit-code'.
Apr 04 11:00:45 argon systemd[1]: Failed to start Apply the settings specified in cloud-config.

The log file "cloud-init.log" shows the error is caused by failing to
generate the requested locale.

2020-04-04 10:00:43,005 - debian.py[DEBUG]: Generating locales for en_GB.UTF-8
2020-04-04 10:00:43,005 - util.py[DEBUG]: Running command ['locale-gen', 'en_GB.UTF-8'] with allowed return codes [0] (shell=False, capture=False)

The command "locale-gen" does not accept a locale as an argument, but
only generates the locales listed in "/etc/locale.gen". So the locale
requested does not get generated, and causes the subsequent failure when
setting locale.

2020-04-04 10:00:43,196 - util.py[DEBUG]: Running command ['update-locale', '--locale-file=/etc/default/locale', 'LANG=en_GB.UTF-8'] with allowed return codes [0] (shell=False, capture=False)

Nick

Laurent GUERBY

unread,
Mar 12, 2022, 8:00:03 AM3/12/22
to
Tested on bullseye genericcloud and same issue of locale not working

https://cloud.debian.org/images/cloud/bullseye/daily/20220310-944/debia
n-11-genericcloud-amd64-daily-20220310-944.qcow2

cloud-init 20.4.1-2+deb11u1

Noah Meyerhans

unread,
Jun 29, 2023, 12:30:05 AM6/29/23
to
On Sat, Apr 04, 2020 at 11:49:42AM +0100, Nick Holloway wrote:
> Package: cloud-init
> Version: 18.3-6

Confirmed that the behavior as described is still an issue in cloud-init
22.4.2-1 in bookworm.

> The command "locale-gen" does not accept a locale as an argument, but
> only generates the locales listed in "/etc/locale.gen". So the locale
> requested does not get generated, and causes the subsequent failure when
> setting locale.
>
> 2020-04-04 10:00:43,196 - util.py[DEBUG]: Running command ['update-locale', '--locale-file=/etc/default/locale', 'LANG=en_GB.UTF-8'] with allowed return codes [0] (shell=False, capture=False)
>

I think that each of the components is working correct if viewed in
isolation, but the end result is not what you expect. If we document
that you must first populate /etc/locale.gen with the desired list of
available locales, that may be sufficient. For example, the following
sets the desired locale:

admin@ip-10-0-3-7:~$ sudo cat /var/lib/cloud/instance/user-data.txt
#cloud-config
write_files:
- path: /etc/locale.gen
content: ZW5fR0IuVVRGLTggVVRGLTgK
encoding: base64
locale: en_GB.UTF-8
admin@ip-10-0-3-7:~$ echo "ZW5fR0IuVVRGLTggVVRGLTgK" | openssl base64 -d
en_GB.UTF-8 UTF-8

Do Ubuntu systems list all known locales in /etc/locale.gen? That would
make the locale module work without additional configuration, but seems
unnecessarily expensive.

noah

Nick Holloway

unread,
Jul 8, 2023, 9:20:05 AM7/8/23
to
On Wed, Jun 28, 2023 at 08:51:46PM -0700, Noah Meyerhans wrote:
> I think that each of the components is working correct if viewed in
> isolation, but the end result is not what you expect. If we document
> that you must first populate /etc/locale.gen with the desired list of
> available locales, that may be sufficient. For example, the following
> sets the desired locale:
>
> admin@ip-10-0-3-7:~$ sudo cat /var/lib/cloud/instance/user-data.txt
> #cloud-config
> write_files:
> - path: /etc/locale.gen
> content: ZW5fR0IuVVRGLTggVVRGLTgK
> encoding: base64
> locale: en_GB.UTF-8
> admin@ip-10-0-3-7:~$ echo "ZW5fR0IuVVRGLTggVVRGLTgK" | openssl base64 -d
> en_GB.UTF-8 UTF-8

This feels like a workaround for the failure of cloud-init setting the locale
on a Debian install.

The locale configuration in cloud-init is expecting locale-gen to configure the
generated locales with the specified locale.

https://git.launchpad.net/ubuntu/+source/cloud-init/tree/cloudinit/distros/debian.py#n401

Debian just ignores the locale passed as a parameter.

> Do Ubuntu systems list all known locales in /etc/locale.gen? That would
> make the locale module work without additional configuration, but seems
> unnecessarily expensive.

Ubuntu does not list all locales in /etc/locale.gen, but their version of
locale-gen will update /etc/locale.gen to add/uncomment the specified locale
before generating locales.

https://git.launchpad.net/ubuntu/+source/glibc/tree/debian/local/usr_sbin/locale-gen?h=ubuntu/jammy#n115

It seems cloud-init has expectation on what locale-gen will do (i.e. _update_
and generate), and that is not the case.

I don't know if cloud-init should take on the responsibility for updating
/etc/locale.gen, or if locale-gen should update /etc/locale.gen if passed a
parameter.
0 new messages