0

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.

Willem Ellis
  • 4,886
  • 7
  • 38
  • 55
  • See this similar [question](http://stackoverflow.com/questions/9075364/how-can-i-properly-set-the-env-hosts-in-a-function-in-my-python-fabric-fabfil). – tobltobs Jul 20 '15 at 01:50

1 Answers1

0

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