2
我不明白如何在python结构中定义多个主机。我有一个hosts.txt
文件中包含这种形式的连接数据:如何通过python命令将命令推送到多个主机?
[email protected]:22 password
[email protected]:22 password
[email protected]:22 password
和示例代码:
#!/usr/bin/python
import pprint
from fabric.api import *
for line in open('hosts.txt','r').readlines():
host, passw = line.split()
env.hosts.append(host)
env.passwords[host] = passw
pprint.pprint(env.hosts)
def test():
sudo("mkdir /a")
test();
不幸的是我得到的消息
没有找到主机。请指定(单个)主机字符串进行连接
pprint
向我显示一个正确的主机列表。我应该怎么做hosts.txt
文件中的所有主机执行我的任务?
也看到http://stackoverflow.com/a/15621751/489590 –