canonical / canonical/cloud-init

Locale generation fails on debian

Open
#4,195 13 comments 3 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
3.8k
Forks
1.1k
Avg merge
2d 23h
Merged PRs (30d)
18

Description

# Bug report
We've seen some issues when using cloud-init to set locales on Debian Bookworm. It looks like when a locale is not present, cloud-init attempts to generate it by passing the locale to `locale-gen`, but locale-gen does not appear to support this. The locale-gen call silently appears to do nothing, but then the later `update-locale` call fails because the locale has not been generated.

I think instead /etc/locale.gen needs to be updated before running locale-gen - it looks like this is already what some other distro modules use, and a similar fix was made for gentoo on https://github.com/canonical/cloud-init/pull/1205.

Possibly this could also be simplified by using localectl?

## Steps to reproduce the problem
Use the following cloud-config to set a locale, on debian bookworm:
```
#cloud-config
locale: en_GB.UTF-8
```

## Environment details
- Cloud-init version: 22.4.2 from debian bookworm repositories
- Operating System Distribution: Debian Bookworm
- Cloud provider, platform or installer type: Mythic Beasts - we're using the debian cloud images from https://cloud.debian.org/images/cloud/ (the "genericcloud" images)

## cloud-init logs
```
2023-06-23 11:50:53,468 - modules.py[DEBUG]: Running module locale () with frequency once-per-instance
2023-06-23 11:50:53,469 - handlers.py[DEBUG]: start: modules-config/config-locale: running config-locale with frequency once-per-instance
2023-06-23 11:50:53,469 - util.py[DEBUG]: Writing to /var/lib/cloud/instances/vds:tdsbookworm/sem/config_locale - wb: [644] 24 bytes
2023-06-23 11:50:53,469 - helpers.py[DEBUG]: Running config-locale using lock ()
2023-06-23 11:50:53,469 - util.py[DEBUG]: Reading from /etc/default/locale (quiet=False)
2023-06-23 11:50:53,469 - util.py[DEBUG]: Read 13 bytes from /etc/default/locale
2023-06-23 11:50:53,469 - cc_locale.py[DEBUG]: Setting locale to en_GB.UTF-8
2023-06-23 11:50:53,469 - debian.py[DEBUG]: Generating locales for en_GB.UTF-8
2023-06-23 11:50:53,469 - subp.py[DEBUG]: Running command ['locale-gen', 'en_GB.UTF-8'] with allowed return codes [0] (shell=False, capture=False)
2023-06-23 11:50:53,488 - debian.py[DEBUG]: Updating /etc/default/locale with locale setting LANG=en_GB.UTF-8
2023-06-23 11:50:53,488 - subp.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)
2023-06-23 11:50:53,533 - handlers.py[DEBUG]: finish: modules-config/config-locale: FAIL: running config-locale with frequency once-per-instance
2023-06-23 11:50:53,534 - util.py[WARNING]: Running module locale () failed
2023-06-23 11:50:53,534 - util.py[DEBUG]: Running module locale () failed
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/cloudinit/config/modules.py", line 246, in _run_modules
ran, _r = cc.run(
^^^^^^^
File "/usr/lib/python3/dist-packages/cloudinit/cloud.py", line 67, in run
return self._runners.run(name, functor, args, freq, clear_on_fail)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/cloudinit/helpers.py", line 185, in run
results = functor(*args)
^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/cloudinit/config/cc_locale.py", line 70, in handle
cloud.distro.apply_locale(locale, locale_cfgfile)
File "/usr/lib/python3/dist-packages/cloudinit/distros/debian.py", line 132, in apply_locale
update_locale_conf(locale, out_fn, keyname=keyname)
File "/usr/lib/python3/dist-packages/cloudinit/distros/debian.py", line 374, in update_locale_conf
subp.subp(
File "/usr/lib/python3/dist-packages/cloudinit/subp.py", line 335, in subp
raise ProcessExecutionError(
cloudinit.subp.ProcessExecutionError: Unexpected error while running command.
Command: ['update-locale', '--locale-file=/etc/default/locale', 'LANG=en_GB.UTF-8']
Exit code: 255
Reason: -
Stdout: -
Stderr: -
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.