簡體   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