How can I properly set the `env.hosts` in a function in my Python Fabric `fabfile.py`?

前端 未结 5 944
挽巷
挽巷 2021-01-11 23:08

When I run this fabfile.py...

from fabric.api import env, run, local, cd

def setenv(foo):
  env.hosts = [\'myhost\']

def mycmd(foo):
  setenv(         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-11 23:38

    I have figured out how to make it work:

    from fabric.api import env, run, local, cd
    
    def setenv(foo):
      env.hosts = ['myhost']
      return env
    
    def mycmd(foo):
      env = setenv(foo)
      print(env.hosts)
      run('ls')
    

提交回复
热议问题