我需要创建一张与此处所述支票非常相似的支票:
Ansible to check diskspace for mounts mentioned as variable
{{ ansible_mounts }}
是一个字典数组,每个字典都包含变量
mount
{{ansible_mounts}
我想用伪代码实现的示例:
foreach (mountpoint in ansible_mounts)
{
if (mountpoint["mount"] == "/var" || mountpoint["mount"] == "/opt")
{
// do the check
}
}
我怎么能在Jinja/Ansible这样做?此代码检查每个项目。我只需要为显式指定的路径筛选它:
- name: Ensure that free space on the tested volume is greater than 15%
assert:
that:
- mount.size_available > mount.size_total|float * 0.15
msg: Disk space has reached 85% threshold
vars:
mount: "{{ ansible_mounts | selectattr('mount','equalto',item.mount) | list | first }}"
with_items:
- "{{ ansible_mounts }}"