- block: - name: validate input fail: msg: package must be defined and a dictionary when: package is not defined or package is not mapping - name: define package dict set_fact: pkg: "{{ {'assets': false, 'sources': false} | combine(package) }}" - name: fail if package name is not defined fail: msg: package name is not defined when: pkg.name is not defined - name: fail if both assets and sources are enabled fail: msg: both assets and sources are enabled when: (pkg.assets | d(false) == true) and (pkg.sources | d(false) == true) - block: - name: install pip3 include_tasks: tasks/install_packages.yml vars: package: - alpine: py3-pip debian: python3-pip - name: install lastversion from pip pip: name: lastversion - name: set lastversion install result for caching purposes set_fact: lastversion_installed: yes when: lastversion_installed | d(false) == false - name: construct lastversion parameters set_fact: lv_params: "{%- if pkg.major_branch is defined and pkg.major_branch is string -%}--major {{ pkg.major_branch | quote }}\ {% endif -%}\ {%- if pkg.location is defined and pkg.location is string -%}--at {{ pkg.location | quote }}\ {% endif -%}\ {%- if pkg.prerelease | d(false) == true -%}--pre\ {% endif -%}\ {%- if pkg.release_filter is defined and pkg.release_filter is string -%}--only {{ pkg.release_filter | quote }}\ {% endif -%}" - name: invoke lastversion shell: cmd: "lastversion {{ lv_params }}{{ pkg.name | quote }}" changed_when: false environment: "{{ {'GITHUB_API_TOKEN': github_api_token} if (github_api_token is defined) else {} }}" register: lv_result - name: save last version set_fact: package_last_version: "{{ lv_result.stdout.strip() }}" - block: - name: add asset-related lastversion parameters set_fact: lv_params_new: "{{ lv_params }}\ {%- if pkg.assets | d(false) == true -%}--assets\ {% endif -%}\ {%- if pkg.asset_filter is defined and pkg.asset_filter is string -%}--filter {{ pkg.asset_filter | quote }}\ {% endif -%}" - name: invoke lastversion shell: cmd: "lastversion {{ lv_params_new }}{{ pkg.name | quote }}" changed_when: false environment: "{{ {'GITHUB_API_TOKEN': github_api_token} if (github_api_token is defined) else {} }}" register: lv_result - name: save asset urls set_fact: package_url: "{{ lv_result.stdout.strip().split('\n') }}" when: pkg.assets | d(false) == true - block: - name: add source-related lastversion parameters set_fact: lv_params_new: "{{ lv_params }}\ {%- if pkg.sources | d(false) == true -%}--source\ {% endif -%}" - name: invoke lastversion shell: cmd: "lastversion {{ lv_params_new }}{{ pkg.name | quote }}" changed_when: false environment: "{{ {'GITHUB_API_TOKEN': github_api_token} if (github_api_token is defined) else {} }}" register: lv_result - name: save source urls set_fact: package_url: "{{ lv_result.stdout.strip().split('\n') }}" when: pkg.sources | d(false) == true delegate_to: localhost - block: - name: save last version info to file copy: content: "{{ package_last_version }}" dest: "{{ pkg.file }}" mode: "{{ pkg.mode | d(omit) }}" owner: "{{ pkg.user | d(omit) }}" group: "{{ pkg.group | d(omit) }}" register: lv_copy notify: "{{ pkg.notify | d(omit) }}" - name: check if the file was changed set_fact: package_changed: "{{ lv_copy.changed }}" when: pkg.file is defined - block: - name: ensure there is only one url fail: msg: multiple asset urls or no asset urls found when: (package_url | length) != 1 - name: install tar include_tasks: tasks/install_packages.yml vars: package: - tar - pause: when: interactive | d(true) == true - name: download and extract assets unarchive: src: "{{ package_url[0] }}" dest: "{{ pkg.extract }}/" remote_src: yes mode: "{{ pkg.mode | d(omit) }}" owner: "{{ pkg.user | d(omit) }}" group: "{{ pkg.group | d(omit) }}" extra_opts: "{%- if pkg.strip_first_dir | d(false) == true -%}{{ [ '--strip-components=1' ] }}\ {%- else -%}{{ [] }}\ {%- endif -%}" notify: "{{ pkg.notify | d(omit) }}" when: (lv_copy.changed or (pkg.force_download | d(false) == true)) and pkg.extract is defined