How to catch auth errors in Fabric and retry?

前端 未结 1 1560
借酒劲吻你
借酒劲吻你 2021-01-24 08:06

I have two usernames and corresponding passwords that I use to admin my servers, is there a way to have my fab scripts/modules, use one and then the second if the first one fail

相关标签:
1条回答
  • 2021-01-24 08:42

    run and other commands raise SystemExit

    from fabric.api import run,cd,put,sudo,settings
    
    def do_stuff():
        run('ls derp')
    
    try:
        with(settings(host_string='%s@localhost' % first_user,password = first_password)):
            do_stuff()
    except SystemExit:
        with(settings(host_string='%s@localhost' % second_user,password = second_password)):
            do_stuff()
    
    0 讨论(0)
提交回复
热议问题