简体   繁体   English

架构未接收到环境主机更改

[英]Fabric not picking up env.hosts change

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. 基本上,我不会在get_file任务之外的任何地方定义env.hosts。 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. 即使我在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. 在调用execute()函数之前,必须设置主机。

@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 另请参阅: http : //docs.fabfile.org/en/1.10/api/core/decorators.html

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

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