如何对fabri中的主机列表运行任务

2024-04-28 20:18:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用python2.6/Fabric 1.8.0,有几个主机包含不同的本地路径和变量。你知道吗

import 
....

def vmm_two_a():
  env.hosts = 'xxx.xx.xx.xx'
  env.user = 'tom'
  env.password = password_from_netrc(env.hosts,env.user)
  global local_path
  local_path = '/home/vmm_two_a/binaries'

def vmm_two_mgmt():
  env.hosts = 'xxx.xx.xx.xx'
  env.user = 'john'
  env.password = password_from_netrc(env.hosts,env.user)
  global local_path
  local_path = '/home/vmm_two_mgmt/binaries'


def get_etc_binaries():
''' Get all etc binaries deployed '''
with hide('stderr','stdout','output','running', 'warnings'):
    settings(warn_only=True)
    get('/usr/local/etc', local_path)

如何对所有主机运行此任务?我试过fab-H但没有成功。你知道吗

谢谢你的帮助


Tags: pathfromenvlocaldefetcpasswordxxx
1条回答
网友
1楼 · 发布于 2024-04-28 20:18:17

在本例中,您需要在每次执行get\u etc\u二进制文件任务之前调用设置env vars的任务。您还可以将本地路径设置为环境本地路径,因此更容易共享。你知道吗

这样的调用看起来像:fab vmm\u twomgmt get\u etc\u binaries vmm\u two\u a get\u etc\u binaries

相关问题 更多 >