RexOps/Rex

Commands executed on remote hosts have their locale unexpectedly switched

Open

#1,230 建立於 2019年9月23日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)Perl (671 star) (218 fork)batch import
help wanted

描述

When I ssh to a remote host manually and run locale I get the following result:

$ locale
LANG=en_US.utf8
LC_CTYPE="en_US.utf8"
LC_NUMERIC="en_US.utf8"
LC_TIME="en_US.utf8"
LC_COLLATE="en_US.utf8"
LC_MONETARY="en_US.utf8"
LC_MESSAGES="en_US.utf8"
LC_PAPER="en_US.utf8"
LC_NAME="en_US.utf8"
LC_ADDRESS="en_US.utf8"
LC_TELEPHONE="en_US.utf8"
LC_MEASUREMENT="en_US.utf8"
LC_IDENTIFICATION="en_US.utf8"
LC_ALL=

However, when I launch this task on the same host as the same user using Rex:

#!/usr/bin/env perl

use 5.026;
use strict;
use warnings;

use Rex -feature => [qw/1.3/];

task 'test_locale' => sub {
    my $out = run 'locale';

    say 'locale on remote host: ' . $out;
};

auth for => 'test_locale', user => 'myuser';

I get the following result:

% rex -H target.host test_locale
[2019-09-23 11:19:29] INFO - Running task test_locale on target.host                    
locale on remote host: LANG=en_US.utf8
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=C

This suggests that Rex enforces certain locale for remote connections, which can lead to hard to debug consequences ( one real example: if a Postgres database is created from inside such Rex connection, it will have its locale set to C and some collation operations will behave strangely ).

This behavior is completely unexpected and surprising because the documentation for 'run' https://metacpan.org/pod/Rex::Commands::Run does not say a word about locale switching.

I think Rex should not touch user's locale settings unless explicitly instructed to do so.

貢獻者指南

Commands executed on remote hosts have their locale unexpectedly switched · RexOps/Rex#1230 | Good First Issue