公司因为需要用到很多服务器定时任务,让我写了一个fabric的可视化控制页面。而在后台中,我实际上是跑了一个fab -f的脚本命令,具体如下:
fab --hide running,status -f cmd.py excute:command='/usr/bin/rsync -avrtopg --password-file=/root/scripts/longyuan_pass.txt game@*.*.*.*::game/gamecenter_qpid_device_data /data/webserver/bi.game.pps.tv/logs/',host="*.*.*.*"
运行这个脚本会出现这个错误
Traceback (most recent call last):
File "/usr/lib64/python2.6/site-packages/fabric/main.py", line 703, in main
commands_to_run = parse_arguments(arguments)
File "/usr/lib64/python2.6/site-packages/fabric/main.py", line 539, in parse_arguments
k, v = result
随后我去源码中看fabric源码在解析这条命令时的实现:
def parse_arguments(arguments):
"""
Parse string list into list of tuples: command, args, kwargs, hosts, roles.
See sites/docs/usage/fab.rst, section on "per-task arguments" for details.
"""
cmds = []
for cmd in arguments:
args = []
kwargs = {}
hosts = []
roles = []
exclude_hosts = []
if ':' in cmd:
cmd, argstr = cmd.split(':', 1)
for pair in _escape_split(',', argstr):
result = _escape_split('=', pair)
if len(result) > 1:
k, v = result
# Catch, interpret host/hosts/role/roles/exclude_hosts
# kwargs
if k in ['host', 'hosts', 'role', 'roles', 'exclude_hosts']:
if k == 'host':
hosts = [v.strip()]
elif k == 'hosts':
hosts = [x.strip() for x in v.split(';')]
elif k == 'role':
roles = [v.strip()]
elif k == 'roles':
roles = [x.strip() for x in v.split(';')]
elif k == 'exclude_hosts':
exclude_hosts = [x.strip() for x in v.split(';')]
红色字体处发现了这个错误的根本原因,他把命令中,我们需要用到的rsync中password对应的密码文件中赋值的=也当成了“=”
所以我们要用转意字符“\=”来处理。感觉新手在使用时,很容易碰到这个坑。
阅读(1622) | 评论(0) | 转发(0) |