错误来自这一行:
- "{{ min_value }}.00 GB" <= item.value.size <= "{{ max_value }}.00 GB"
这里有一些问题。从根本上说,你正在尝试进行数值比较( <= )关于非数字值( 50.00 GB ,这永远不会奏效。但那并不是你错误的根源。由于您使用引号启动值,因此会出现错误( " ),因此YAML解析器期望引用整行,如下所示:
<=
50.00 GB
"
- '"{{ min_value }}.00 GB" <= item.value.size <= "{{ max_value }}.00 GB"'
这摆脱了你的错误信息,但它在几个方面仍然存在问题。除了“与非数字值的数字比较”问题,在a when 条件你已经在Jinja模板上下文中,所以你不需要 {{ 和 }} 标记。你想写这样的表达式:
when
{{
}}
- '"%s.00 GB" % min_value <= item.value.size <= "%s.00 GB" % max_value
但是在语法上正确的时候,我仍然遇到了我发现的第一个问题。我们真的需要提出要使用的数值。一种选择是假设总是指定尺寸 GB 并将其剥离,如:
GB
- min_value <= int(item.value.size[:-3]) <= max_value
另一种选择是使用计算磁盘大小 sectors 和 sectorsize 相反,像这样:
sectors
sectorsize
- min_value <= (item.value.sectors * item.value.sectorsize) <= max_value
这需要 min_value 和 max_value 以字节为单位指定。
min_value
max_value
希望这里足以指出你正确的方向。