Python 如何在fabric.operations.execute中指定env.shell
我使用fabric.tasks.execute在远程服务器上执行命令,并且需要根据系统使用不同的shell。现在我的代码是:Python 如何在fabric.operations.execute中指定env.shell,python,fabric,Python,Fabric,我使用fabric.tasks.execute在远程服务器上执行命令,并且需要根据系统使用不同的shell。现在我的代码是: def run_test(server_ip, server_shell): execute(test,server_ip,server_shell,host=server_ip) # host can be specified in execute argument def test(ip,shell): env.shell=shell run
def run_test(server_ip, server_shell):
execute(test,server_ip,server_shell,host=server_ip) # host can be specified in execute argument
def test(ip,shell):
env.shell=shell
run('command')
我可以接受这一点,但更喜欢执行指定命令将使用的env.shell,而不是在任务中分配它,这非常简单和干净。我可以使用类似于:
def run_test(server_ip, server_shell):
execute(test,server_ip,server_shell,host=server_ip,*shell=server_shell*) # host can be specified in execute argument
def test(ip,shell):
run('command')
假设只有主机
、主机
、角色
、角色
和排除主机
关键字参数是特殊的;其余部分按原样传递给任务,即,shell
传递给test()
:
def test(shell):
with settings(shell=shell):
run('command')
execute(test, shell=server_shell, host=server_ip)