如何比较接口

时间:2018-04-24 14:01:39

标签: ansible

主持人可能有2个以上的接口[" lo"," eth0"," eth1"]

如果主机只有2个接口,我想运行一个when条件[" lo"," eth0"]

when: 'ansible_interfaces == 2'

但它返回:

"ansible_interfaces == 2": false

它有2个接口,为什么它是假的?

1 个答案:

答案 0 :(得分:1)

您没有将count中的ansible_interfaces元素与2进行比较,而将变量ansible_interfaces的值与2进行比较。

你应该使用:

when: ansible_interfaces|length == 2

相关问题