- name: Check if zsync is installed
  ansible.builtin.command: zsync -V
  register: zsync_installed
  ignore_errors: true

- name: Install zsync from source
  ansible.builtin.get_url:
    url: http://zsync.moria.org.uk/download/zsync-0.6.2.tar.bz2
    dest: /tmp/zsync-0.6.2.tar.bz2
    mode: '0644'
  when: zsync_installed.rc != 0

- name: Extract zsync source
  ansible.builtin.unarchive:
    src: /tmp/zsync-0.6.2.tar.bz2
    dest: /tmp
    remote_src: false
    creates: /tmp/zsync-0.6.2
  when: zsync_installed.rc != 0

- name: Install zsync from source (./configure)
  ansible.builtin.command: ./configure
  args:
    chdir: /tmp/zsync-0.6.2
  when: zsync_installed.rc != 0

- name: Install zsync from source (make)
  ansible.builtin.command: make
  args:
    chdir: /tmp/zsync-0.6.2
  when: zsync_installed.rc != 0

- name: Install zsync from source (sudo make install)
  ansible.builtin.command: make install
  args:
    chdir: /tmp/zsync-0.6.2
  become: true
  when: zsync_installed.rc != 0
