Python Fabric: Skip logins needing passwords

荒凉一梦 提交于 2019-12-31 03:08:05

问题


I have a similar issue to this: How can I skip Fabric connections that ask for a password? which has no answer. I'm looking for a way to get Fabric to consider bad any host asking for a password instead of an SSH key login, since this means the user I'm connecting as doesn't have an account on the server (and I'm iterating through a large list of hosts). I've tried setting

env.password = None

and

env.password = 'none'

as well as

with setting(warn_only=True):

but Fabric keeps asking for the password. Any way around this?


回答1:


I believe env.abort_on_prompts will achieve what you need, i.e. fail if there is a need for any kind of user interaction, while working when public key authentication is possible.

According to the documentation, this option calls abort() which in turn make use of sys.exit, which raises SystemExit making it possible to detect and recover from inner calls to abort by using except SystemExit or similar.




回答2:


I just patched up the utils.py in fabric to return a raise instead of sys.exit(1). let's you handle it cleanly instead of it crapping itself.

(about line 34)
    else:
        #sys.exit(1)
        raise("I broke")


来源:https://stackoverflow.com/questions/12569225/python-fabric-skip-logins-needing-passwords

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!