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

2023-07-08 Thread Nick Holloway
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.



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

2023-06-28 Thread Noah Meyerhans
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



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

2020-04-04 Thread Nick Holloway
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 +. 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 () 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