New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ansible permits ssh to send local LANG and LC_ALL env vars (file misencoding, filename corruption) #10698
Comments
Yeah, this can have some annoying effect, especially if you parse the output of tools ( personal example with salt and chkconfig saltstack/salt-bootstrap#558 ). I think it would just be easier to force LC_ALL=C in the ssh plugin. |
This might have side effect on command line UI who will be in english, and this might cause issue to people, but I think that's a lesser problem that having silent breakage and corruption of filename.
In fact, maybe the code should be pushed higher in the stack, since the issue could occurs on differents plugins. |
So what about having ansible_env_LC_ALL=C to set the environment variable used for that connexion, like we have ansible_user= etc, etc for inventory ? |
or, perhaps:
? Some smarts are needed, though, because it's common for It might make sense to have an
Separately, though, |
See also comments on #10714 (comment) |
Maybe it would be nice if someone could write a short explanation of the current behavior of Ansible I have been running into similar issues yesterday and was about to open a ticket on the same topic, First I should say that having I started digging and found #7060 which was supposed to fix the problem but did not for me : indeed when I tried to run the following test task with ansible 1.7.2 (in which the patch was applied, I checked) :
I got I finally noticed that my locale on the local host was:
so I changed everything to I am not sure about it, but I think what happened is this: Ansible (or ssh) tries to send Please let me know if it makes sense... |
@FurcyPin Amusingly, I ran into this issue while using Ansible to automate deployment of a couple of PostgreSQL buildfarm members out at the OSU OSL. Right now Ansible doesn't care about the locale, as far as I can tell. So what happens is down to:
If you have So if you run the remote command
On Debian/Ubuntu this will spit errors because Debian systems don't include all locales by default. On Red Hat / Fedora systems it'll silently run in a different locale to the system default, because all locales are installed. You'll probably only notice problems if the locale's collation order is different to what you expect or it's #7060 looks like it actually unmasked this issue; prior to that commit, everything would be done in the BTW by setting:
you're overriding
This won't work if you've applied #10714 though. |
Ansible does provide the ANSIBLE_MODULE_LANG (just A quick example here shows things working as I'd expect: # ansible -m file -a "state=touch path=/tmp/Álvaro" localhost -c local localhost | SUCCESS => { "changed": true, "dest": "/tmp/Álvaro", "gid": 0, "group": "root", "mode": "0644", "owner": "root", "secontext": "unconfined_u:object_r:user_tmp_t:s0", "size": 0, "state": "file", "uid": 0 } # ll /tmp/Álvaro -rw-r--r--. 1 root root 0 Jul 12 00:25 /tmp/Álvaro Based on this, I'm going to close this issue. If you continue seeing any problems related to this issue, or if you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:
Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved. Thank you! |
postgres needs |
I know the topix is a bit old, but I ran into the same kind of issue. With Ansible 2.2 runnng on Ubuntu 16.10 in french to provision out of the box CentOS 7.3, I had some weird "Unable to communicate with yum" error (sorry, I don't remember the exact message) Turned out the CentOS's netwok was unproperly configured and yum ended up with a lot of "Connexion refusée", meaning Connection refused... And Ansible failing both my playbook's package: and bennojoy.nginx's on this. After a bit of browsing, I ended up commenting out CentOS's sshd_config AcceptEnv LANG LC etc + sshd reload, before any yum, it solved my issue. |
Newer ssh versions like to send
LANG
andLC_ALL
to the remote sshd, so that the remote ssh session has the same locale as the local user's session.This makes Ansible playbook execution, including things like files created on the remote end, dependent on the environment of the user running the playbook. Files may have different language text and/or be in a different text encoding. File names may have different encodings too, so that the file named
Álvaro
inen_US.utf-8
will be listed as??lvaro
inen_US
, even though it'll actually match the glob?lvaro
.E.g.
As far as I can tell Ansible doesn't support overriding environment variables for all tasks that run on a given host / hostgroup, nor does it support the
environment
keyword at the playbook level under thehosts
dictionary. So it's not currently easy to say "Always use the xx_XX locale for this host".These errors are often treated as minor and ignore-able, but they're anything but, especially when they result in mixing utf-8 and 1-byte encodings.
This does not (just) affect people who use non-English languages. I noticed the problem because I use the
en_AU.utf-8
locale on my workstation, but most of the hosts I manage only have theC
,C.UTF-8
anden_US.UTF-8
locales configured. The system falls back toC
.perl
is particularly noisy about this:The
locale
command will also complain:The best solution, IMO, is for Ansible to use the remote end's default locale, by suppressing sending of
LANG
andLC_ALL
overssh
by default.This is most visible on Debian and Ubuntu systems, which default to
in
/etc/ssh/sshd_config
.As a workaround for this issue, users may wish to remove the above
AcceptEnv
directive from thesshd_config
on the server, thus disallowing locales from being set by thessh
client. Alternately, on the client side, users may remove:from their
/etc/ssh/ssh_config
. It does not appear to be possible to disable this on a per-host basis, unfortunately; see:So the ideal would be for Ansible to override the
LC_
variables andLANG
before invokingssh
, or for Ansible to use its own global configuration file forssh
.The simplest workaround is to create a minimal
ansible_ssh_config
in your Ansible project trees, like:and then override
ansible
's default ssh command in anansible.cfg
in your project tree, like:The downside is that if Ansible's default ssh command changes, you won't see the change.
The text was updated successfully, but these errors were encountered: