如何为Fabric2/Paramiko/Invoke指定本地shell?

问题描述 投票:0回答:1

当尝试创建

fabric2.Connection
时,Paramiko 尝试调用 local
/bin/bash
命令:

$ fab2 db-shell
Traceback (most recent call last):
  File "/nix/store/m2iyj18cifr4a1rvpfgphg7kfgsf2pj2-python3.9-fabric2-2.7.1/bin/.fab2-wrapped", line 9, in <module>
    sys.exit(program.run())
  File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/program.py", line 384, in run
    self.execute()
  File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/program.py", line 566, in execute
    executor.execute(*self.tasks)
  File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/executor.py", line 129, in execute
    result = call.task(*args, **call.kwargs)
  File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/tasks.py", line 127, in __call__
    result = self.body(*args, **kwargs)
  File "/home/username/project/fabfile.py", line 645, in db_shell
    bastion_connection().run(
  File "/home/username/project/fabfile_utils.py", line 141, in bastion_connection
    conn = Connection(
  File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/fabric2/connection.py", line 403, in __init__
    self.ssh_config = self.config.base_ssh_config.lookup(host)
  File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/paramiko/config.py", line 223, in lookup
    options = self._lookup(hostname=hostname)
  File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/paramiko/config.py", line 250, in _lookup
    or self._does_match(
  File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/paramiko/config.py", line 389, in _does_match
    passed = invoke.run(exec_cmd, hide="stdout", warn=True).ok
  File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/__init__.py", line 48, in run
    return Context().run(command, **kwargs)
  File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/context.py", line 95, in run
    return self._run(runner, command, **kwargs)
  File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/context.py", line 102, in _run
    return runner.run(command, **kwargs)
  File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/runners.py", line 380, in run
    return self._run_body(command, **kwargs)
  File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/runners.py", line 431, in _run_body
    self.start(command, self.opts["shell"], self.env)
  File "/nix/store/20k85mfdkbrj5w1pq0d7dzagygfip70h-python3-3.9.13-env/lib/python3.9/site-packages/invoke/runners.py", line 1291, in start
    self.process = Popen(
  File "/nix/store/0zzvjh5gnz0ny7ckilzyn9hmg5lypszf-python3-3.9.13/lib/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/nix/store/0zzvjh5gnz0ny7ckilzyn9hmg5lypszf-python3-3.9.13/lib/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/bin/bash'

我还没有在文档中找到任何与此相关的内容。

我在 NixOS stable 22.11 上运行 Fabric2==2.7.1、invoke==1.6.0 和 paramiko==2.8.0。

python shell paramiko fabric pyinvoke
1个回答
0
投票

Invoke 目前默认为

/bin/bash
,这是一个已知问题,因为 Alpine 和 NixOS 等操作系统没有该路径。幸运的是,我们可以在
$PATH
中指定命令,而不是手动查找,因此将以下内容添加到
Connection
调用即可解决问题:
config=invoke.Config(overrides={"shell": "bash"})

© www.soinside.com 2019 - 2024. All rights reserved.