Weird bug with locale

I’m trying to set up provisioning for Vagrant VM with Ansible, but constantly get an error:

locale: Cannot set LC_ALL to default locale: No such file or directory

Here is the full output.

I’ve tried to place this task in pre_tasks:

- name: set up locale
apt: pkg=language-pack-en

And also tried to put this in task that fails:

environment:
LC_ALL: "en_US.UTF-8"

But it didnt helped.
Does anybody saw an error like that, and found solutions? Kindly help.

Just yesterday we merged in a slight change in the way that we’re setting the localization environment and other environment variables. What version are you running to produce the above output?

I use . I thought that this is the issue with Ubuntu (I use ) or with Vagrant. Because there is a lot of topics on the internet about such errrors, but all of them in general solved with setting up and re-generation of locales - doesnt work in my case. Is there some workarounds with version for this? Or maybe you can describe what actually cause the error, because I’m totally can’t get why it happens. Also I do some debugging right now - check the - I’ve discovered, that if first task is commented - error does not being throwed.

Previously in 1.5.x we set LANG=C specifically to ensure a consistent shell environment. This does create problems for Unicode however, so recently we modified the way it works. In your case, you should set ‘module_lang = en_RU.UTF-8’ (or en_US.UTF-8 if you wish) in your ansible.cfg under the “[defaults]” section. That value will then be used instead of “C”.

Previously in 1.5.x we set LANG=C specifically to ensure a consistent shell environment. This does create problems for Unicode however, so recently we modified the way it works. In your case, you should set 'module_lang = en_RU.UTF-8' (or en_US.UTF-8 if you wish) in your ansible.cfg under the "[defaults]" section. That value will then be used instead of "C".

If I want to override this variable only for that project or playbook and keep everything else with default values, what is the cleanest way to do that?
Docs says that:

Settings in files are not merged together.

So, I need to copy all stuff from /etc/ansible/ansible.cfg to myproj/ansible.cfg and tweak needed values?

There line in ansible.cfg:

nearly all parameters can be overridden in ansible-playbook

Does it mean, that I can just put module_lang setting in a playbook?

False alert! I didnt noticed error messages "cannot allocate memory" in the middle of output. I've just increased VMs memory and everything became OK.

By the way, I was found that locale can be fixed with this:

     - name: set up locale
       shell: echo "echo $'LANGUAGE=en_US.UTF-8\n' > /etc/default/locale" | sudo -s;
              echo "echo $'LANG=en_US.UTF-8\n' >> /etc/default/locale" | sudo -s;
              echo "echo $'LC_ALL=en_US.UTF-8\n' >> /etc/default/locale"

sudo -s;

              echo "echo $'LC_MESSAGES=POSIX\n' >> /etc/default/locale"

sudo -s;

              locale-gen en_US.UTF-8;
              dpkg-reconfigure locales;
              touch /etc/locale_configured;
              creates=/etc/locale_configured

Works on Ubuntu 12.04

FWIW, if you have something like that again, the ‘script’ module makes for cleaner playbooks.

It just pushes and runs a remote script.