Ansible - Download latest release binary from Github repo

前端 未结 2 762
耶瑟儿~
耶瑟儿~ 2021-02-15 15:10

With Ansible please advise how i could download the latest release binary from Github repository. As per my current understanding the steps would be: a. get URL of latest releas

2条回答
  •  难免孤独
    2021-02-15 15:51

    I am using the following recipe to download and extract latest watchexec binary for Linux from GitHub releases.

    - hosts: localhost                                                     
      tasks:                                                               
    
      - name: check latest watchexec
        uri:
          url: https://api.github.com/repos/watchexec/watchexec/releases/latest
          return_content: true
        register: watchexec_latest
    
      - name: "installing watchexec {{ watchexec_latest.json.tag_name }}"
        loop: "{{ watchexec_latest.json.assets }}"
        when: "'x86_64-unknown-linux-musl.tar.xz' in item.name"
        unarchive:
          remote_src: yes
          src: "{{ item.browser_download_url }}"
          dest: "{{ ansible_env.HOME }}/bin/"
          keep_newer: yes
          extra_opts:
          - --strip=1
          - --no-anchored
          - watchexec
    

    tar extra_opts explained here.

    This still downloads the binary every time a playbook is called. As an improvement, it might be possible to use set_fact for caching node_id attribute that corresponds to the unpacked file.

提交回复
热议问题