简体   繁体   中英

Python Fabric - No hosts found

I don't know what I'm doing wrong. It seems like a simple thing that should work. I can run the task "test_task" by itself and it works. If i run it as part of the "deploy_test" function then it prompts me with: No hosts found. Please specify (single) host string for connection:

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()  

The decorator only works if you execute the task from fab command:

fab test_task

If you want to use the task deploy_test , you have many options:

1.- Execute test_task as a task, not as function. This is the way to go if you have other tasks that should be executed on deploy_test() on a different host list:

def deploy_test():
   execute(test_task)  

2.- Put the role decorator on deploy_test() :

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

Keep in mind that a python function is different from a fabric task. A fabric task do some stuff under the hood, like setting the host list, the user, and this state is keeped if you call python functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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