- 论坛徽章:
- 0
|
- #file hostlist
- #"host"\t"user"\t"password"
- #172.16.96.202 root password1
- #172.16.96.203 root password2
- #fabric threading
- #http://stackoverflow.com/questions/7798330/how-do-i-ensure-that-a-python-thread-dies-after-its-target-function-completes
- from fabric.api import *
- host_result = []
- host_passwd_result = {}
- fd = open('hostlist','r')
- for line in fd.readlines():
- str = line.strip()
- str = line.split('\t')
- str[-1] = str[-1].strip()
- add_str = "%s" % (str[0])
- host_result.append(add_str)
- host_passwd_result[str[0]] = str[-1]
- fd.close()
- env.user = 'root'
- env.roledefs['web'] = host_result
- env.passwords = host_passwd_result
- def comm_ls():
- run('ls /opt')
- def comm_whoami():
- run('whoami')
- def comm_put():
- put('/tmp/test.txt','/tmp/wiyun.txt')
- #exec command with shell
- #fab -R web comm_ls comm_whoami -f fab.py
- #parallel
- #fab -R web comm_ls -P comm_whoami -f fab.py
复制代码 回复 42# expert1
以前写过的。贴出来,有问题一起讨论。环境安装就不描述了
|
|