# Setting locale in one play and have the change take effect in subsequent plays

**URL:** <https://forum.ansible.com/t/setting-locale-in-one-play-and-have-the-change-take-effect-in-subsequent-plays/12136>\
**Category:** Ansible Project\
**Created:** [December 11, 2012, 9:42pm UTC](https://forum.ansible.com/t/setting-locale-in-one-play-and-have-the-change-take-effect-in-subsequent-plays/12136 "2012-12-11T21:42:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lorin\_Hochstein1](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lorin\_Hochstein1](https://forum.ansible.com/u/Lorin_Hochstein1)\
**Post date:** [December 11, 2012, 9:42pm UTC](https://forum.ansible.com/t/setting-locale-in-one-play-and-have-the-change-take-effect-in-subsequent-plays/12136/1 "2012-12-11T21:42:36Z")

</div>

In my playbooks, I need to set the locale, and have the changes go into effect so that in a subsequent play, when postgresql is installed it will use the appropriate locale settings.

However, if I set the locale in one play using ansible, the locale change does not take effect in subsequent plays. I know that when you’re interacting with a traditional ssh session, you need to log out and back in for a locale change to take effect. What can I do to cause the locale setting change to take effect in subsequent plays? Note that I’m using ssh for transport, with default settings.

See [https://gist.github.com/4262334](https://gist.github.com/4262334) for an example playbook, output, and my ansible.cfg file. Here you can see the issue being reproduced using the “ansible”

$ ansible vagrant -s -m command -a “/usr/sbin/update-locale LANG=en\_US.UTF-8 LC\_ALL=en\_US.UTF-8”  
[vagrant.nimbis.net](http://vagrant.nimbis.net) | success | rc=0 \>\>

$ ansible vagrant -m command -a locale  
[vagrant.nimbis.net](http://vagrant.nimbis.net) | success | rc=0 \>\>  
LANG=C  
LANGUAGE=  
LC\_CTYPE=“en\_US”  
LC\_NUMERIC=“en\_US”  
LC\_TIME=“en\_US”  
LC\_COLLATE=“en\_US”  
LC\_MONETARY=“en\_US”  
LC\_MESSAGES=“en\_US”  
LC\_PAPER=“en\_US”  
LC\_NAME=“en\_US”  
LC\_ADDRESS=“en\_US”  
LC\_TELEPHONE=“en\_US”  
LC\_MEASUREMENT=“en\_US”  
LC\_IDENTIFICATION=“en\_US”  
LC\_ALL=en\_US

If I connect via ssh, it shows the correct thing

$ ssh vagrant locale  
LANG=en\_US.UTF-8  
LANGUAGE=  
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=en\_US.UTF-8

$ ansible --version  
ansible 1.0 (devel 637883164e) last updated 2012/12/08 14:06:41 (GMT -400)

Take care,

Lorin

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [December 11, 2012, 10:10pm UTC](https://forum.ansible.com/t/setting-locale-in-one-play-and-have-the-change-take-effect-in-subsequent-plays/12136/2 "2012-12-11T22:10:28Z")

</div>

Try removing the controlmaster option, it will slow things down but should correctly present you with updated locale on the remote side.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [December 12, 2012, 12:13am UTC](https://forum.ansible.com/t/setting-locale-in-one-play-and-have-the-change-take-effect-in-subsequent-plays/12136/3 "2012-12-12T00:13:34Z")

</div>

I should also add, in case someone wants to fiddle with it, the  
modules themselves set try to set the locale to C while they execute,  
partly to avoid encoding issues.

Various underlying code here  
([https://github.com/ansible/ansible/blob/devel/lib/ansible/module\_common.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/module_common.py))  
and in runner/\_\_init\_\_.py

Not sure if that is playing a role in things or not.

--Michael

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [December 12, 2012, 12:48am UTC](https://forum.ansible.com/t/setting-locale-in-one-play-and-have-the-change-take-effect-in-subsequent-plays/12136/4 "2012-12-12T00:48:06Z")

</div>

Do you think we can pull that into a config (default C) that we can override on command line and/or playbook?

Brian Coca

---

<div class="post-metadata">

**Author:** ![Stephen\_Fromm](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@Stephen\_Fromm](https://forum.ansible.com/u/Stephen_Fromm)\
**Post date:** [December 12, 2012, 1:14am UTC](https://forum.ansible.com/t/setting-locale-in-one-play-and-have-the-change-take-effect-in-subsequent-plays/12136/5 "2012-12-12T01:14:53Z")

</div>

You should be able to set module\_lang in your config or ANSIBLE\_MODULE\_LANG  
environment variable to change that (see  
[https://github.com/ansible/ansible/blob/devel/lib/ansible/constants.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/constants.py)).  
Let us know if that doesn't work.

sf

---

<div class="post-metadata">

**Author:** ![Lorin\_Hochstein1](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lorin\_Hochstein1](https://forum.ansible.com/u/Lorin_Hochstein1)\
**Post date:** [December 14, 2012, 6:36pm UTC](https://forum.ansible.com/t/setting-locale-in-one-play-and-have-the-change-take-effect-in-subsequent-plays/12136/6 "2012-12-14T18:36:30Z")

</div>

Thanks, Brian.

In order to keep the speed boost with control master, I’m doing this as a workaround.

vars:  
locale: en\_US.UTF-8

tasks:

- name: workaround to install postgresql with locale set  
shell: LANG=$locale LC\_COLLATE=$locale LC\_CTYPE=$locale LC\_MESSAGES=$locale LC\_MONETARY=$locale LC\_NUMERIC=$locale LC\_TIME=$locale LC\_ALL=$locale apt-get install -y postgresql

But it’s good to know that I can disable controlmaster if needed to avoid doing something ugly like this.

Take care,

Lorin
