I'm trying to change hosts on a per-task basis. Here's my code:
@task
def process():
execute(get_file)
execute(transfer_file)
@task
def get_file():
env.hosts = [hexi_host]
This is really the only relevant bit of code. Basically, I'm not defining env.hosts anywhere outside of the get_file task. When I run the script I get:
No hosts found. Please specify (single) host string for connection:
Even though I'm defining it in get_file. If I define it prior to process, it will work, but then I can never change to a different host at a later time. Hope this makes sense, any help is greatly appreciated.
You have to set host before you call execute() function.
@task
def process():
env.roledefs = {'receiver': [hexi_host], 'sender': [otherhosts]}
execute(get_files)
execute(transfer_files)
@task
@roles('receiver')
def get_files():
run(...)
See also: http://docs.fabfile.org/en/1.10/api/core/decorators.html
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.