RexOps/Rex

Commands executed on remote hosts have their locale unexpectedly switched

Open

#1230 aperta il 23 set 2019

Vedi su GitHub
 (3 commenti) (0 reazioni) (0 assegnatari)Perl (218 fork)batch import
help wanted

Metriche repository

Star
 (671 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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.

Guida contributor