如何在Fabric中捕获身份验证错误并重试? [英] How to catch auth errors in Fabric and retry?

查看:70
本文介绍了如何在Fabric中捕获身份验证错误并重试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个用于管理服务器的用户名和相应的密码,有没有办法让我的fab脚本/模块使用,如果第一个失败,则使用一个,然后使用第二个,而无需维护完整列表每个主机甚至每个主机组的凭据.

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 failed, with out having to maintain a full list of credentials for each host or even group of them.

除了在run()或类似的地方,我看不到文档可以尝试/尝试...

I see no way in the docs to doa try/except around run() or similar...

推荐答案

run和其他命令引发SystemExit

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()

这篇关于如何在Fabric中捕获身份验证错误并重试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆