cli/ssh: allocate tty by default
-t is only enabled when the local ssh command is also connected to a tty, so it seems to be enabled by default.
This commit is contained in:
parent
bd989085ac
commit
0e2cb172e6
@ -400,6 +400,7 @@ class Host:
|
|||||||
check: bool = True,
|
check: bool = True,
|
||||||
verbose_ssh: bool = False,
|
verbose_ssh: bool = False,
|
||||||
timeout: float = math.inf,
|
timeout: float = math.inf,
|
||||||
|
tty: bool = True,
|
||||||
) -> subprocess.CompletedProcess[str]:
|
) -> subprocess.CompletedProcess[str]:
|
||||||
"""
|
"""
|
||||||
Command to run on the host via ssh
|
Command to run on the host via ssh
|
||||||
@ -444,7 +445,7 @@ class Host:
|
|||||||
bash_cmd += cmd
|
bash_cmd += cmd
|
||||||
# FIXME we assume bash to be present here? Should be documented...
|
# FIXME we assume bash to be present here? Should be documented...
|
||||||
ssh_cmd = [
|
ssh_cmd = [
|
||||||
*self.ssh_cmd(verbose_ssh=verbose_ssh),
|
*self.ssh_cmd(verbose_ssh=verbose_ssh, tty=tty),
|
||||||
"--",
|
"--",
|
||||||
f"{sudo}bash -c {quote(bash_cmd)} -- {' '.join(map(quote, bash_args))}",
|
f"{sudo}bash -c {quote(bash_cmd)} -- {' '.join(map(quote, bash_args))}",
|
||||||
]
|
]
|
||||||
@ -462,6 +463,7 @@ class Host:
|
|||||||
def ssh_cmd(
|
def ssh_cmd(
|
||||||
self,
|
self,
|
||||||
verbose_ssh: bool = False,
|
verbose_ssh: bool = False,
|
||||||
|
tty: bool = True,
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
if self.user is not None:
|
if self.user is not None:
|
||||||
ssh_target = f"{self.user}@{self.host}"
|
ssh_target = f"{self.user}@{self.host}"
|
||||||
@ -484,6 +486,8 @@ class Host:
|
|||||||
ssh_opts.extend(["-o", "UserKnownHostsFile=/dev/null"])
|
ssh_opts.extend(["-o", "UserKnownHostsFile=/dev/null"])
|
||||||
if verbose_ssh or self.verbose_ssh:
|
if verbose_ssh or self.verbose_ssh:
|
||||||
ssh_opts.extend(["-v"])
|
ssh_opts.extend(["-v"])
|
||||||
|
if tty:
|
||||||
|
ssh_opts.extend(["-t"])
|
||||||
|
|
||||||
return ["ssh", ssh_target, *ssh_opts]
|
return ["ssh", ssh_target, *ssh_opts]
|
||||||
|
|
||||||
@ -547,6 +551,7 @@ class HostGroup:
|
|||||||
check: bool = True,
|
check: bool = True,
|
||||||
verbose_ssh: bool = False,
|
verbose_ssh: bool = False,
|
||||||
timeout: float = math.inf,
|
timeout: float = math.inf,
|
||||||
|
tty: bool = True,
|
||||||
) -> None:
|
) -> None:
|
||||||
try:
|
try:
|
||||||
proc = host.run_local(
|
proc = host.run_local(
|
||||||
@ -575,6 +580,7 @@ class HostGroup:
|
|||||||
check: bool = True,
|
check: bool = True,
|
||||||
verbose_ssh: bool = False,
|
verbose_ssh: bool = False,
|
||||||
timeout: float = math.inf,
|
timeout: float = math.inf,
|
||||||
|
tty: bool = True,
|
||||||
) -> None:
|
) -> None:
|
||||||
try:
|
try:
|
||||||
proc = host.run(
|
proc = host.run(
|
||||||
@ -586,6 +592,7 @@ class HostGroup:
|
|||||||
check=check,
|
check=check,
|
||||||
verbose_ssh=verbose_ssh,
|
verbose_ssh=verbose_ssh,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
|
tty=tty,
|
||||||
)
|
)
|
||||||
results.append(HostResult(host, proc))
|
results.append(HostResult(host, proc))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -617,6 +624,7 @@ class HostGroup:
|
|||||||
cwd: None | str | Path = None,
|
cwd: None | str | Path = None,
|
||||||
check: bool = True,
|
check: bool = True,
|
||||||
verbose_ssh: bool = False,
|
verbose_ssh: bool = False,
|
||||||
|
tty: bool = True,
|
||||||
timeout: float = math.inf,
|
timeout: float = math.inf,
|
||||||
) -> Results:
|
) -> Results:
|
||||||
results: Results = []
|
results: Results = []
|
||||||
@ -636,6 +644,7 @@ class HostGroup:
|
|||||||
check=check,
|
check=check,
|
||||||
verbose_ssh=verbose_ssh,
|
verbose_ssh=verbose_ssh,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
|
tty=tty,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
thread.start()
|
thread.start()
|
||||||
@ -659,6 +668,7 @@ class HostGroup:
|
|||||||
check: bool = True,
|
check: bool = True,
|
||||||
verbose_ssh: bool = False,
|
verbose_ssh: bool = False,
|
||||||
timeout: float = math.inf,
|
timeout: float = math.inf,
|
||||||
|
tty: bool = True,
|
||||||
) -> Results:
|
) -> Results:
|
||||||
"""
|
"""
|
||||||
Command to run on the remote host via ssh
|
Command to run on the remote host via ssh
|
||||||
@ -679,6 +689,7 @@ class HostGroup:
|
|||||||
check=check,
|
check=check,
|
||||||
verbose_ssh=verbose_ssh,
|
verbose_ssh=verbose_ssh,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
|
tty=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
def run_local(
|
def run_local(
|
||||||
|
Loading…
Reference in New Issue
Block a user