Get the current value of env.hosts list with Python Fabric Library

前端 未结 3 1026
感情败类
感情败类 2021-01-01 12:22

I\'ve got this code (foo and bar are local servers):

env.hosts = [\'foo\', \'bar\']

def mytask():
    print(env.hosts[0])
<         


        
相关标签:
3条回答
  • 2021-01-01 12:34

    Use env.host_string. You can find a full list of env variables here.

    0 讨论(0)
  • 2021-01-01 12:43

    Thanks Marcelo.

    If you want to actually use env.host_string (for concatenation purpose for instance), be sure to be inside a task. Its value is None outside.

    0 讨论(0)
  • 2021-01-01 12:55

    You can just do:

    env.hosts = ['foo', 'bar']
    
    def mytask():
         print(env.host)
    

    Because when you're in the task as executed by fab, you'll have that var set for free.

    0 讨论(0)
提交回复
热议问题