我需要创建一张与此处说明的支票非常相似的支票:Ansible to check diskspace for mounts mentioned as variable
除了我只需要用于指定的路径(例如/ var)。
None
是一个字典数组,每个字典包含实际路径的变量{{ ansible_mounts }}
。仅当mount等于某个值时,我才需要对mount
中的所有项目执行循环检查。
我想用伪代码实现的示例:
{{ ansible_mounts }}
如何在Jinja / Ansible中做到这一点?该代码对每个项目进行检查。我只需要对明确指定的路径进行过滤:
foreach (mountpoint in ansible_mounts)
{
if (mountpoint["mount"] == "/var" || mountpoint["mount"] == "/opt")
{
// do the check
}
}
答案 0 :(得分:0)
例如,您需要添加一个when
条件
vars:
my_mounts:
- '/var/log'
- '/var/logs/foo'
tasks:
- name: do the check
when: item.mount in my_mounts
with_items: '{{ ansible_mounts }}'