How to continue a task when Fabric receives an error

后端 未结 7 1513
迷失自我
迷失自我 2020-12-04 23:16

When I define a task to run on several remote servers, if the task runs on server one and exits with an error, Fabric will stop and abort the task. But I want to make fabric

7条回答
  •  广开言路
    2020-12-04 23:39

    As of Fabric 1.5, there is a ContextManager that makes this easier:

    from fabric.api import sudo, warn_only
    
    with warn_only():
        sudo('mkdir foo')
    

    Update: I re-confirmed that this works in ipython using the following code.

    from fabric.api import local, warn_only
    
    #aborted with SystemExit after 'bad command'
    local('bad command'); local('bad command 2')
    
    #executes both commands, printing errors for each
    with warn_only():
        local('bad command'); local('bad command 2')
    

提交回复
热议问题