Skip to content

Sudo fails to ask for a password if locale of remote system is not English #1125

@philippemilink

Description

@philippemilink

Describe the bug

If remote system is configured with a locale different than English, sudo will fail to prompt for a password.

On remote system:

echo $LANG
fr_FR.UTF-8

Example of failing command:

pyinfra --debug-all -y 192.168.1.16 server.shell "echo foo" _sudo=true
--> Starting operation: server.shell (echo foo)
    [pyinfra.api.operations] Starting operation {'server.shell'} on 192.168.1.16
    [pyinfra.connectors.ssh] Running command on 192.168.1.16: (pty=False) sudo -H -n sh -c 'echo foo'
DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes
DEBUG:paramiko.transport:[chan 0] Max packet out: 32768 bytes
DEBUG:paramiko.transport:Secsh channel 0 opened.
DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok
DEBUG:paramiko.transport:[chan 0] EOF received (0)
DEBUG:paramiko.transport:[chan 0] EOF sent (0)
    [pyinfra.connectors.ssh] Waiting for exit status...
    [pyinfra.connectors.ssh] Command exit status: 1
    [192.168.1.16] sudo: il est nécessaire de saisir un mot de passe
    [192.168.1.16] Error: executed 0 commands
    [pyinfra.api.state] Failing hosts: 192.168.1.16

The problem comes from this line:

if last_line.strip() == "sudo: a password is required":

In this case, the remote system being in French, sudo prints sudo: il est nécessaire de saisir un mot de passe.

I "fixed" the bug by changing this line:

command_bits.extend(["sudo", "-H"])

into

command_bits.extend(["LANG=C", "sudo", "-H"])

but I'm not sure whether this is the right fix.

Meta

Observed with Pip package 3.0b2.

I just spent this week-end testing Pyinfra, it looks promising! 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugLabel for all kind of bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions