ansible 获取列表变量长度

使用过滤器获取list length

shell: "[[ {{ groups.test | length }} = 1 ]]

三种方式都可以

when:
     - ( groups.test | lenght ) == 2

when:
     - (( groups.test | lenght ) == 2)

when:
     - groups.test|lenght == 2

小括号内是表达式组

逻辑符 说明
and 如果左操作数和右操作数同为真,返回 true 。
or 如果左操作数和右操作数有一个为真,返回 true 。
not 对一个表达式取反(见下)。
(expr) 表达式组。

when中变量无需使用 {{}}

判断对象是否相等使用   ==

参考:https://www.jianshu.com/p/ae74f5f39828

猜你喜欢

转载自blog.csdn.net/JackLiu16/article/details/81811656