我如何使用Ansible检查特定文件系统的使用情况

时间:2019-03-20 10:26:35

标签: ansible

我需要创建一张与此处说明的支票非常相似的支票: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
    }
}

1 个答案:

答案 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 }}'