ansible-tw / AMA

Helping Ansible users in Taiwan with any questions.
https://github.com/ansible-tw/ama/issues
33 stars 4 forks source link

如何篩選「特定 Json 的物件陣列中,指定屬性值包含指定子字串的物件」 #53

Open brlin-tw opened 4 years ago

brlin-tw commented 4 years ago
    - name: 查詢 GitHub 釋出軟體 API 取得當前 Trojan-Go 最新釋出版本資訊
      register: trojan_go_latest_release_info_raw
      uri:
        url: https://api.github.com/repos/p4gefau1t/trojan-go/releases?per_page=1&page=1
        headers:
          Accept: application/vnd.github.v3+json

我要篩選出 trojan_go_latest_release_info_raw.json[0].assets 陣列中包含 name 屬性值包含「linux-amd64」子字串的物件,如何在 Ansible 中辦到呢?

目前找到 selectattrsjson_query 過濾器都湊不出來想要的結果,請大家幫忙

linzeyan commented 4 years ago

trojan_go_latest_release_info_raw.json[0] | json_query('assets[*]') | selectattr('name', 'search', 'linux-amd64') | map(attribute='name')