How to continue a task when Fabric receives an error

后端 未结 7 1507
迷失自我
迷失自我 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:24

    You should set the abort_exception environment variable and catch the exception.

    For example:

    from fabric.api        import env
    from fabric.operations import sudo
    
    class FabricException(Exception):
        pass
    
    env.abort_exception = FabricException
    # ... set up the rest of the environment...
    
    try:
        sudo('reboot')
    except FabricException:
        pass  # This is expected, we can continue.
    

    You can also set it in a with block. See the documentation here.

提交回复
热议问题