--- - name: "Check forgejo installed version" ansible.builtin.shell: "set -eo pipefail; {{ gitea_full_executable_path }} -v | cut -d' ' -f 3" args: executable: '/bin/bash' register: gitea_active_version changed_when: false failed_when: false - name: "Determine 'latest' version release" when: gitea_version == "latest" block: - name: "Get latest forgejo release metadata" ansible.builtin.uri: url: 'https://codeberg.org/api/v1/repos/forgejo/forgejo/releases?limit=1' return_content: true register: gitea_forgejo_remote_metadata become: false when: not ansible_check_mode - name: "Fail if running in check mode without versions set." ansible.builtin.fail: msg: | "You are running this playbook in check mode: Please set the Gitea version with the variable 'gitea_version', because the URI module cannot detect the latest version in this mode." when: ansible_check_mode and (gitea_version == 'latest' or gitea_version == 'present') - name: "Set fact latest forgejo release" ansible.builtin.set_fact: gitea_remote_version: "{{ gitea_forgejo_remote_metadata.json.0.tag_name[1:] }}" when: not ansible_check_mode - name: "Set forgejo version target (latest)" ansible.builtin.set_fact: gitea_version_target: "{{ gitea_remote_version }}" when: not ansible_check_mode - name: "Set forgejo version target {{ gitea_version }}" ansible.builtin.set_fact: gitea_version_target: "{{ gitea_version }}" when: gitea_version != "latest" - name: "Download forgejo version {{ gitea_version_target }}" when: not ansible_check_mode block: - name: "Get specific forgejo release metadata" ansible.builtin.uri: url: 'https://codeberg.org/api/v1/repos/forgejo/forgejo/releases/tags/v{{ gitea_version_target }}' return_content: true register: gitea_forgejo_remote_tags_metadata become: false rescue: - name: "Error Downloading https://codeberg.org/api/v1/repos/forgejo/forgejo/releases/tags/v{{ gitea_version_target }}" ansible.builtin.fail: msg: "We did not find the forgejo version you specified. Are you sure that '{{ gitea_version_target }}' is a valid forgejo version?" - name: "Generate forgejo download url" ansible.builtin.set_fact: gitea_forgejo_dl_url: "{{ gitea_forgejo_remote_tags_metadata.json | community.general.json_query(gitea_forgejo_query_download) }}" when: not ansible_check_mode - name: "Generate forgejo download checksum url" ansible.builtin.set_fact: gitea_forgejo_checksum_url: "{{ gitea_forgejo_remote_tags_metadata.json | community.general.json_query(gitea_forgejo_query_checksum) }}" when: not ansible_check_mode - name: Get forgejo checksum ansible.builtin.uri: url: "{{ gitea_forgejo_checksum_url | first }}" return_content: true register: _gitea_forgejo_dl_checksum become: false when: not ansible_check_mode - name: Set forjeo checksum ansible.builtin.set_fact: gitea_forgejo_checksum: "{{ _gitea_forgejo_dl_checksum.content.split(' ')[0] }}" when: not ansible_check_mode - name: "Generate forgejo download signed url" ansible.builtin.set_fact: gitea_forgejo_signed_url: "{{ gitea_forgejo_remote_tags_metadata.json | community.general.json_query(gitea_forgejo_query_signed) }}" when: not ansible_check_mode - name: "Set a example forgejo download link if in check mode" ansible.builtin.set_fact: gitea_forgejo_dl_url: ['https://codeberg.org/attachments/a00333ad-250a-4d30-a764-9a37fb24f419'] when: ansible_check_mode - name: "Set a example forgejo checksum link if in check mode" ansible.builtin.set_fact: gitea_forgejo_checksum: 'f8c71464d1b250bf022eaa3df270c810950904ceb71da5cefc7ec24a034a4c87' when: ansible_check_mode - name: "Set a example forgejo checksum link if in check mode" ansible.builtin.set_fact: gitea_forgejo_signed_url: ['https://codeberg.org/attachments/ae5e50c6-e86e-4202-b95f-f142e8138e2f'] when: ansible_check_mode - name: 'Assert that remote version is higher' ansible.builtin.assert: that: - gitea_active_version is version(gitea_remote_version, 'lt') fail_msg: ERROR: Remote version is lower then current version! - name: Show Download URLs # noqa: H500 ansible.builtin.debug: msg: "{{ item }}" verbosity: 1 loop: - "gitea_forgejo_dl_url: {{ gitea_forgejo_dl_url | first }}" - "gitea_forgejo_checksum: {{ gitea_forgejo_checksum }}" - "gitea_forgejo_signed_url: {{ gitea_forgejo_signed_url | first }}"