通过 Ansible 从 GitHub API url 获取特定数据?

Get specific data from GitHub API url via Ansible?

我尝试从包含 gnu_no-wallet.tar.gz

https://api.github.com/repos/LIMXTEC/BitCore/releases/latest 中获取 browser_download_url

我是 Ansible 的新手,我试着了解如何以最简单的方式做到这一点。

您可以使用模块 uri and, from its results using register, use a combination of a loop and a when 来实现您正在寻找的东西,以精确定位您正在寻找的值。

使用剧本:

- hosts: all
  gather_facts: no
      
  tasks:
    - uri: 
        url: https://api.github.com/repos/LIMXTEC/BitCore/releases/latest
      register: github_call
    
    - debug:
        msg: "{{ item.browser_download_url }}"
      loop: "{{ github_call.json.assets }}"
      when: "'gnu_no-wallet.tar.gz' in item.browser_download_url"
      loop_control:
        label: "{{ item.name }}"

您将获得回顾:

PLAY [all] *******************************************************************************************************

TASK [uri] *******************************************************************************************************
ok: [localhost]

TASK [debug] *****************************************************************************************************
skipping: [localhost] => (item=bitcore-0.90.9.7-win32-setup.exe) 
skipping: [localhost] => (item=bitcore-0.90.9.7-win64-setup.exe) 
skipping: [localhost] => (item=bitcore-arm-linux-gnueabihf.tar.gz) 
skipping: [localhost] => (item=bitcore-i686-pc-linux-gnu.tar.gz) 
skipping: [localhost] => (item=bitcore-qt-win32.exe) 
skipping: [localhost] => (item=bitcore-qt-win64.exe) 
skipping: [localhost] => (item=bitcore-win32-daemon.zip) 
skipping: [localhost] => (item=bitcore-win64-daemon.zip) 
ok: [localhost] => (item=bitcore-x86_64-linux-gnu_no-wallet.tar.gz) => {
    "msg": "https://github.com/LIMXTEC/BitCore/releases/download/0.90.9.7/bitcore-x86_64-linux-gnu_no-wallet.tar.gz"
}
skipping: [localhost] => (item=bitcore-x86_64-linux-gnu_qt5-dev.tar.gz) 
skipping: [localhost] => (item=bitcore-x86_64-linux-gnu_qt5_with-libs.tar.gz) 

PLAY RECAP *******************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0