可以在Fabric中使用条件执行吗?

Tim*_*ara 4 python fabric

是否可以要求面料有条件地执行操作?这应该是相当简单的,因为它只是"Python",但我不是100%确定如何运行命令并捕获它们的返回代码或输出.

作为一个例子,我如何拥有以主机中环境变量的值为条件的行为?

Yuv*_*dam 6

这非常简单:

@hosts('host.example.com')
def task():
    if run('echo $SOME_VAR') == 'some value':
        run('some_other_command.sh')
Run Code Online (Sandbox Code Playgroud)