Ansible:按其属性筛选列表我在Ansible中注册了名为“Network”的变量:{
"addresses": {
"private_ext": [
{
"type": "fixed",
"addr": "172.16.2.100"
}
],
"private_man": [
{
"type": "fixed",
"addr": "172.16.1.100"
},
{
"type": "floating",
"addr": "10.90.80.10"
}
]
}
}是否有可能得到这样的IP地址(“addr”)类型=“浮动”?- debug: var={{ network.addresses.private_man | filter type="fixed" | get "addr" }}我知道语法是错的,但你明白。
3 回答
慕标5832272
TA贡献1966条经验 获得超4个赞
network.addresses.private_man | selectattr("type", "equalto", "fixed")
match
search
match
将需要字符串中的完全匹配,而 search
将需要字符串内部的匹配。
network.addresses.private_man | selectattr("type", "match", "^fixed$")
addr
... | map(attribute='addr') | list
... | map(attribute='addr') | join(',')
- debug: msg={{ network.addresses.private_man | selectattr("type", "equalto", "fixed") | map(attribute='addr') | join(',') }}
慕哥9229398
TA贡献1877条经验 获得超6个赞
- debug: msg: "{% for address in network.addresses.private_man %}\ {% if address.type == 'fixed' %}\ {{ address.addr }}\ {% endif %}\ {% endfor %}"
- debug: msg: "{% for address in network.addresses.private_man if address.type == 'fixed' %}{{ address.addr }}{% endfor %}"
ok: [localhost] => { "msg": "172.16.1.100" }
- 3 回答
- 0 关注
- 396 浏览
添加回答
举报
0/150
提交
取消