module_set_locale default changed for 2.2 -- module authors need to set environment variables when screenscraping output

Greetings all,

For 2.2 we’re making a change to when Ansible sets the LC_ALL and LANG environment variablesfor running modules. Here’s what that means for you:

Executive summary for users:

If you notice Ansible modules in devel throwing errors because the module is not finding a string it expects when running a command, please file a bug for us to fix before 2.2 is out. You can work around any issues temporarily by setting module_set_locale = True in your ansible.cfg. There shouldn’t be many of these but we wanted to let people know why they might be seeing a change.

For Module Authors:

As we were working on the late stages of 2.1, a bug was raised regarding Ansible setting LC_ALL, LANG, and LC_MESSAGES when it invokes modules on remote systems: https://github.com/ansible/ansible/issues/15138 When we evaluated that bug we came to realize that Ansible was setting LC_ALL, LANG, and LC_MESSAGES for all modules to try to sanitize the environment for a relatively small number of modules which needed to read the output of other command line programs. This both caused the bug in question and seemed to be trying to drive in a finishing nail with a sledgehammer. Additionally, the implementation of the code which added LC_ALL didn’t lead to a predictable LC setting on the remote machine – by default it was taking whatever the LC settings were on the control host and pushing them to the remote machines.

In light of these we decided to add a config option, module_set-locale, to turn Ansible’s setting of LC* and LANG variables on or off. In 2.1, for backwards compatibility, we set this config option to True which is the previous behaviour. In currrent devel (2.2) we’ve changed the option to False. Most modules should not be affected by this change but modules which invoke a command line tool and then read the tool’s output will need to be sure that they’re setting the LC_ALL and LANG environment variables when they call the program so that they get predictable output from the tools. Note that due to the previous implementation’s unpredictablity, many modules which do this have already been adapted to set the environment variables but with over 600 modules, there’s probably more that need to be changed.

There’s a few ways to fix this. Here’s an example from the yum module that sets the environment variables for each call to another program: https://github.com/ansible/ansible-modules-core/blob/devel/packaging/os/yum.py#L262

If you want to set it globally, you can take a look at how the apt module does it:
https://github.com/ansible/ansible-modules-core/blob/devel/packaging/os/apt.py#L202

https://github.com/ansible/ansible-modules-core/blob/devel/packaging/os/apt.py#L693

-Toshio