peopledoc / ansible-role-boot

Ansible role to boot .lxc hosts in an inventory, Vagrantfile provided in novafloss/ansible-setup
4 stars 0 forks source link

Override the LANG environment variable while container creation #8

Open FlogFr opened 8 years ago

FlogFr commented 8 years ago

Hey there,

thanks for this awesome work and role first :)

When you don't set correctly your LANG variable on your host, the container creation will dump a msg of error of type:

# this dump is with LANG=en_US.utf8
Generating locales (this might take a while)...
  en_US.utf8...character map file `utf8' not found: No such file or directory
 done
Generation complete.

If you correctly set the LANG variable to a correct locale + encoding (like en_US.UTF-8), the container creation will be ok, and dump a successful message:

Generating locales (this might take a while)...
  en_US.UTF-8... done
  en_US.UTF-8... done
Generation complete.

I'm under jessie, with the default /usr/share/lxc/template/lxc-debian file.

novafloss.boot could try to check if the LANG is correct, if not, then fallback to en_US.UTF-8 as default ?

jpic commented 8 years ago

Let's see, are you saying en_US.utf8 comes from /usr/share/lxc/template/lxc-debian ?

If not, where does it comes from ? Cause that's probably something we need to patch.

I have nothing against fixing it here although it's too bad it would only benefit our users, it seems like a bigger issue.

FlogFr commented 8 years ago

the "wrong" environement variable (en_US.utf8) comes from my ~/.bashrc. But at the container creation it doesn't check that the LANG environment variable is a good one for the locale, maybe it is in the lxc template that should be fixed in order to fallback to a default good locale.

jpic commented 8 years ago

Perhaps it should just fail if the LANG is not right ?

How do you suggest to check that LANG is correct ? ​

FlogFr commented 8 years ago

I don't know if the creation of a container should fail because a locale is not properly set. And I don't know how to pre-check that the LANG is available in the locale.

jpic commented 8 years ago

I'm missing something here, my locale seems properly set but locale -a shows en_US.utf8

02/08 2016 15:20:24 jpic@lue ~ 
$ cat /etc/locale.gen  | grep en_US
#  en_US ISO-8859-1
#  en_US.UTF-8 UTF-8
en_US.UTF-8 UTF-8  
#en_US ISO-8859-1  

02/08 2016 15:20:28 jpic@lue ~ 
$ cat /etc/locale.conf 
LANG=en_US.UTF-8

02/08 2016 15:20:35 jpic@lue ~ 
$ echo $LANG
en_US.UTF-8

02/08 2016 15:20:42 jpic@lue ~ 
$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

02/08 2016 15:20:43 jpic@lue ~ 
$ locale -a
C
en_US.utf8 <------------- WTF ?
POSIX
jpic commented 8 years ago

@aRkadeFR could you paste the output when it's not properly set for you please ? I'm making a case for serverfault so we can get to the bottom of this.

Thxxxx

:guitar:

FlogFr commented 8 years ago

Yes, locale -a shows en_US.utf8 but I set manually LANG to en_US.utf8. This is a wrong $LANG env variable.

decidedlygray commented 7 years ago

I've run into the same error message, but from a different route (just using locale-gen while tracking down an issue with postgresql):

{17-01-02 12:53}hostname:/opt@master✗✗✗✗✗✗ root# locale-gen
Generating locales (this might take a while)...
  en_US.ISO-8859-1... done
  en_US.utf8...character map file `utf8' not found: No such file or directory
 done
Generation complete.

Interestingly, @aRkadeFR you opened another ticket here for a different project, that I believe is directly related.

For me this was on a fresh LXC Debian jessie container, with only a few other packages installed. The culprit is /etc/locale.gen contains:

# (lots of commented out stuff, finally ending with:)
en_US.utf8 utf8

utf8 isn't a valid character map file. /etc/local.gen should contain this instead:

en_US.utf8 UTF-8

After making that correction locale-gen can correctly generate locale information. I believe this is the root cause of this issue.

What's interesting though, and could mean that I am wrong, is that @jpic it looks like your local.gen contains:

en_US.UTF-8 UTF-8

I'm not sure who "owns" the source of this bug, if it is something with debconf, something with the locales package, or what, but I'm hoping either of you in this thread might help report this to the correct maintainer so it can be fixed.

Cheers, DG

jpic commented 7 years ago

Couldn't find utf8 in a fresh jessie container's /etc/locale.gen with lxc 2.0.6:

root@jessie:/# /bin/grep -v '^#' /etc/locale.gen 

en_US.UTF-8 UTF-8
en_US.UTF-8 UTF-8
root@jessie:/# 

@decidedlygray could you report your LXC version and exact lxc-create command to reproduce this ?

decidedlygray commented 7 years ago

Hmm.. Ok, I think I'm wrong then and this might be specific to my setup.

Not entirely sure how to get lxc version info, but I think it's this?:

root@hostname:cache/debconf # lxc-info --version
1.1.5

I'm on a system that uses custom templates to deploy LXC containers, so I don't have the exact lxc-create command. I might be a lost cause.. sorry

FlogFr commented 7 years ago

@decidedlygray you actually pointed the right issue IMHO Some of my colleagues and me got en_US.utf8 UTF-8 in their host /etc/locale.gen, which is not LXC related but from the debian setup. Not sure how to reproduce this setup with wrong values on /etc/locale.gen. I may suspect that this value was a correct on old setup (wheezy / beginning jessie) and while upgrading these values are not replaced.