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

前端 未结 5 943
挽巷
挽巷 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:44

    Have you tried to used the hosts decorator?

    from fabric.api import env, run, hosts
    
    @hosts('myhost')
    def mycmd(foo):
        print(env.hosts)
        run('ls')
    

提交回复
热议问题