如何找到未找到主机。请指定(单个)主机字符串以进行连接:?
如何解决面料问题?
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"
> command run
>> fab bootstrap
> No hosts found. Please specify (single) host string for connection:
答案 0 :(得分:23)
您也可以使用env.host_string而不是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"
答案 1 :(得分:13)
不是在任务中设置主机,而是在使用装饰器调用它之前执行:
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"
有关详细信息,请查看Defining host lists - 根据您的需要,有很多不同的方法。
答案 2 :(得分:2)
另外,您可以在功能之外设置env设置
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')