Python Fabric - No hosts found. Please specify (single) host string for connection:

匿名 (未验证) 提交于 2019-12-03 03:04:01

问题:

How do I get No hosts found. Please specify (single) host string for connection: ?

How to a resolve with fabric?

def bootstrap():     host = 'ec2-54-xxx.xxx.xxx.compute-1.amazonaws.com'     env.hosts = [host]     env.user = "ubuntu"     env.key_filename = "/home/ubuntu/omg.pem"  fab boostrap No hosts found. Please specify (single) host string for connection:  

回答1:

Instead of setting hosts inside your task, do it before it gets called with a decorator:

from fabric.api import hosts, env  @hosts(['ec2-54-xxx.xxx.xxx.compute-1.amazonaws.com']) def bootstrap():     env.user = "ubuntu"     env.key_filename = "/home/ubuntu/omg.pem" 

For more information on this, check out Defining host lists - there are a lot of different ways to do it depending on what you need.



回答2:

Also you can use env.host_string instead of env.hosts:

def bootstrap():     env.host_string # 'ec2-54-xxx.xxx.xxx.compute-1.amazonaws.com'     env.user = "ubuntu"     env.key_filename = "/home/ubuntu/omg.pem" 


回答3:

Alternatevly you can set env settings in outside your functions

from fabric.api import env, run  host = 'ec2-54-xxx.xxx.xxx.compute-1.amazonaws.com' env.hosts = [host] env.user = "ubuntu" env.key_filename = "/home/ubuntu/omg.pem"  def test():     run('ls -la') 


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