[英]Ansible dictionary inside list - get keys and values of the dictionary
我有一個Ansible劇本,其可變值如下所示-
"instances": [
{
"architecture": "x86_64",
"tags": {
"A": "B",
"C": "D"
}
},
{
"architecture": "x86",
"tags": {
"A": "X",
"G": "D"
}
}
]
實例列表是動態的,並且#values每次運行可能會有所不同。
我想要 -
我嘗試了with_subelements
但沒有運氣,因為它需要一個列表。
第一個任務可以使用純Jinja來實現,第二個任務則需要一些JMESPath。
- name: List archs with tag A present
debug:
msg: >-
{{ instances
| selectattr('tags.A','defined')
| map(attribute='architecture')
| list
| unique
}}
- name: List archs with any tag set to D
debug:
msg: >-
{{ instances
| json_query('[?contains(values(tags),`D`)]')
| map(attribute='architecture')
| list
| unique
}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.