繁体   English   中英

Python Fabric - 找不到主机

[英]Python Fabric - No hosts found

我不知道我做错了什么。 这似乎是一件应该有效的简单事情。 我可以自己运行任务“test_task”并且它可以工作。 如果我作为“deploy_test”函数的一部分运行它,它会提示我: 找不到主机。 请指定(单个)主机字符串以进行连接:

env.roledefs = {
    'test_servers': ['testserver1.domain.com', 'testserver2.domain.com']
}

@roles("test_servers")
def test_task():
    env.user = "test_user"
    sudo("sh /usr/bin/something", user="other_user")

def deploy_test():
    test_task()  

只有从fab命令执行任务时,装饰器才有效:

fab test_task

如果要使用任务deploy_test ,则有许多选项:

1.-将test_task作为任务执行,而不是作为函数执行。 如果您有其他任务应该在另一个主机列表上的deploy_test()上执行,那么这是deploy_test()

def deploy_test():
   execute(test_task)  

2.-将角色装饰器放在deploy_test()

@roles("test_servers")
def deploy_test():
   test_task()

请记住,python函数与fabric任务不同。 一个结构任务做一些事情,比如设置主机列表,用户,如果你调用python函数,这个状态就会保持不变。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM