saltstack/salt — pull request #6264 by boltronics (2013-07-22 05:37:53+00:00)
Title: More reliably fetch locale LANG env

On a clean Debian wheezy install, my /etc/default/locale file looks as follows:

# File generated by update-locale
LANG="en_AU.UTF-8"
LANGUAGE="en_AU:en"

As part of my state.highstate, I call salt.states.locale.system, but this always prints output of the locale module run in blue (instead of green) - indicating that it was changed during the execution. It actually does change /etc/default/locale.bak, which would annoyingly appear on an AIDE report.

Currently, the localemod.py calls

grep LANG /etc/default/locale | grep -vE "#"

to check if a change is required. That doesn't sufficiently narrow down the required line though - it captures both LANG and LANGUAGE variables (and also calls grep twice unnecessarily). This later causes the test in states/locale.py to fail, which then causes set_locale to execute on every run.

Interestingly, set_locale does a similar test with grep, but invokes the command more accurately such that it doesn't fail. Hence, my patch below makes sure get_locale does the same thing. After applying, Debian wheezy works as it should. I also made a similar change to RedHat for consistency.