如何写条件 when, 当可用播放书中有一节

当有一个部分时,我正在尝试写入任务 / var. 我使用了变量 assert

- name: Apply patch if /var exist and > 300MB
yum:
name: '*'
state: latest
loop: "{{ ansible_mounts }}"
when: item.mount == "/var" and item.size_available > 300000000

他必须失败或跳过 / var 不存在。 什么都不会发生。 告诉我,请跳过,如果是如何跳过 / var 不存在
已邀请:

石油百科

赞同来自:

这就是我所作工作的:

---
- name: answer serverfault
hosts: all
become: yes

tasks:
- name: Apply patch if /var exist and > 300MB
debug:
msg:
#- " Data type of 'ansible_facts['mounts'] is {{ ansible_facts['mounts'] | type_debug }} "
- item mount is {{ item.mount }}
- item size_available is {{ item.size_available }}
when: item.mount == "/data" and item.size_available > 300000000
loop: "{{ ansible_facts['mounts'] | flatten(levels=1) }}"

评论分区实际上显示了您正在处理的数据类型类型。 在这种情况下,这是一个列表。

要平滑列表,我使用了

"{{ ansible_facts['mounts'] | flatten(levels=1) }}"

由于该列表最初如此如此:

        "ansible_mounts": [
{
"block_available": 109019876,
"block_size": 4096,
"block_total": 961159932,
"block_used": 852140056,
"device": "/dev/sde1",
"fstype": "ext4",
"inode_available": 243543185,
"inode_total": 164195328,
"inode_used": 513143,
"mount": "/data",
"options": "rw,relatime",
"size_available": 444545412096,
"size_total": 3236911081442,
"uuid": "a35a0282-6eac-132d-abdf-fbea3a835522"
},

我测试过 playbook 靠他自己

/data*

安装点,因为我没有服务器

/var

现在可用 - 但它的工作原理。

有些链接:

https://docs.ansible.com/ansib ... lters
https://datacadamia.com/infra/ansible/list

要回复问题请先登录注册