|
| 1 | +--- |
| 2 | +################################################## |
| 3 | +# Pandoc Install (Linux + macOS) |
| 4 | +# For generating man pages in JDK24+ |
| 5 | +################################################## |
| 6 | + |
| 7 | +- name: Install Pandoc |
| 8 | + block: |
| 9 | + # Work out the platform (OS + arch) and support status ( arm64e reported on gha runners ) |
| 10 | + - name: Normalize architecture to Pandoc naming (amd64/arm64) |
| 11 | + set_fact: |
| 12 | + arch_normalized: >- |
| 13 | + {{ ({ |
| 14 | + 'x86_64': 'amd64', |
| 15 | + 'amd64': 'amd64', |
| 16 | + 'aarch64': 'arm64', |
| 17 | + 'arm64': 'arm64', |
| 18 | + 'arm64e': 'arm64' |
| 19 | + })[ansible_architecture] | default(ansible_architecture) }} |
| 20 | + changed_when: false |
| 21 | + tags: pandoc |
| 22 | + |
| 23 | + - name: Build platform key from architecture and system |
| 24 | + set_fact: |
| 25 | + platform_key: "{{ ansible_system }}:{{ arch_normalized }}" |
| 26 | + changed_when: false |
| 27 | + tags: pandoc |
| 28 | + |
| 29 | + - name: Determine if this platform is supported and select download |
| 30 | + set_fact: |
| 31 | + supported: "{{ platform_key in pandoc_downloads }}" |
| 32 | + download: "{{ pandoc_downloads[platform_key] if (platform_key in pandoc_downloads) else {} }}" |
| 33 | + changed_when: false |
| 34 | + tags: pandoc |
| 35 | + |
| 36 | + - name: Skip on unsupported platforms |
| 37 | + when: not supported |
| 38 | + debug: |
| 39 | + msg: "Skipping Pandoc: unsupported {{ ansible_system }}/{{ ansible_architecture }} (key: {{ platform_key }})" |
| 40 | + changed_when: false |
| 41 | + tags: pandoc |
| 42 | + |
| 43 | + # Build paths and URLs for downloads |
| 44 | + - name: Set Correct Pandoc Download Parameters (name, sha, URL) |
| 45 | + when: supported |
| 46 | + set_fact: |
| 47 | + archive_name: "{{ download.filename }}" |
| 48 | + archive_sha: "sha256:{{ download.sha256 }}" |
| 49 | + download_url: "{{ pandoc_base_url }}/{{ pandoc_version }}/{{ download.filename }}" |
| 50 | + changed_when: false |
| 51 | + tags: pandoc |
| 52 | + |
| 53 | + - name: Set Pandoc Base Directory Paths |
| 54 | + when: supported |
| 55 | + set_fact: |
| 56 | + install_dir: "{{ pandoc_install_root }}/pandoc-{{ pandoc_version }}" |
| 57 | + download_dir: "/tmp/pandoc-{{ pandoc_version }}" |
| 58 | + changed_when: false |
| 59 | + tags: pandoc |
| 60 | + |
| 61 | + - name: Derive local file paths (archive & unified bin path) |
| 62 | + when: supported |
| 63 | + set_fact: |
| 64 | + archive_path: "{{ download_dir }}/{{ archive_name }}" |
| 65 | + bin_path: "{{ install_dir }}/bin/pandoc" |
| 66 | + mac_inner: "{{ install_dir }}/pandoc-{{ pandoc_version }}-{{ arch_normalized }}" |
| 67 | + changed_when: false |
| 68 | + tags: pandoc |
| 69 | + |
| 70 | + - name: Check existing Pandoc version in PATH |
| 71 | + when: supported |
| 72 | + become: true |
| 73 | + command: "{{ pandoc_bin_dir }}/pandoc --version" |
| 74 | + register: pandoc_check |
| 75 | + changed_when: false |
| 76 | + failed_when: false |
| 77 | + tags: pandoc |
| 78 | + |
| 79 | + - name: Decide whether we need to install |
| 80 | + when: supported |
| 81 | + set_fact: |
| 82 | + need_install: "{{ (pandoc_check.rc != 0) or (pandoc_version not in (pandoc_check.stdout | default(''))) }}" |
| 83 | + changed_when: false |
| 84 | + tags: pandoc |
| 85 | + |
| 86 | + # Download + unpack Pandoc (only when needed) |
| 87 | + - name: Ensure download directory exists |
| 88 | + when: [supported, need_install] |
| 89 | + become: true |
| 90 | + file: |
| 91 | + path: "{{ download_dir }}" |
| 92 | + state: directory |
| 93 | + mode: "0755" |
| 94 | + tags: pandoc |
| 95 | + |
| 96 | + - name: Download Pandoc archive |
| 97 | + when: [supported, need_install] |
| 98 | + become: true |
| 99 | + get_url: |
| 100 | + url: "{{ download_url }}" |
| 101 | + dest: "{{ archive_path }}" |
| 102 | + mode: "0644" |
| 103 | + checksum: "{{ archive_sha }}" |
| 104 | + tags: pandoc |
| 105 | + |
| 106 | + - name: Create install directory |
| 107 | + when: [supported, need_install] |
| 108 | + become: true |
| 109 | + file: |
| 110 | + path: "{{ install_dir }}" |
| 111 | + state: directory |
| 112 | + mode: "0755" |
| 113 | + tags: pandoc |
| 114 | + |
| 115 | + # macOS uses .zip (extracts to {{ mac_inner }}) |
| 116 | + - name: Unpack Pandoc on macOS |
| 117 | + when: |
| 118 | + - supported |
| 119 | + - need_install |
| 120 | + - ansible_system == "Darwin" |
| 121 | + become: true |
| 122 | + unarchive: |
| 123 | + src: "{{ archive_path }}" |
| 124 | + dest: "{{ install_dir }}" |
| 125 | + remote_src: true |
| 126 | + tags: pandoc |
| 127 | + |
| 128 | + # Linux uses .tar.gz (strip the top-level folder so bin/ is directly under install_dir) |
| 129 | + - name: Unpack Pandoc on Linux |
| 130 | + when: |
| 131 | + - supported |
| 132 | + - need_install |
| 133 | + - ansible_system == "Linux" |
| 134 | + become: true |
| 135 | + unarchive: |
| 136 | + src: "{{ archive_path }}" |
| 137 | + dest: "{{ install_dir }}" |
| 138 | + remote_src: true |
| 139 | + extra_opts: ["--strip-components=1"] |
| 140 | + tags: pandoc |
| 141 | + |
| 142 | + # Normalise macOS layout to match Linux |
| 143 | + |
| 144 | + - name: Ensure macOS bin symlink exists (bin -> mac_inner/bin) |
| 145 | + when: |
| 146 | + - supported |
| 147 | + - need_install |
| 148 | + - ansible_system == "Darwin" |
| 149 | + become: true |
| 150 | + file: |
| 151 | + src: "{{ mac_inner }}/bin" |
| 152 | + dest: "{{ install_dir }}/bin" |
| 153 | + state: link |
| 154 | + force: true |
| 155 | + follow: false |
| 156 | + tags: pandoc |
| 157 | + |
| 158 | + - name: Ensure macOS share symlink exists (share -> mac_inner/share) |
| 159 | + when: |
| 160 | + - supported |
| 161 | + - need_install |
| 162 | + - ansible_system == "Darwin" |
| 163 | + become: true |
| 164 | + file: |
| 165 | + src: "{{ mac_inner }}/share" |
| 166 | + dest: "{{ install_dir }}/share" |
| 167 | + state: link |
| 168 | + force: true |
| 169 | + follow: false |
| 170 | + tags: pandoc |
| 171 | + |
| 172 | + # Configure & Verify Symlink To Pandoc |
| 173 | + # ------------------------------------------------------- |
| 174 | + - name: Check that unified bin_path exists |
| 175 | + when: [supported, need_install] |
| 176 | + stat: |
| 177 | + path: "{{ bin_path }}" |
| 178 | + register: bin_stat |
| 179 | + changed_when: false |
| 180 | + tags: pandoc |
| 181 | + |
| 182 | + - name: Fail early if unified bin_path missing |
| 183 | + when: |
| 184 | + - supported |
| 185 | + - need_install |
| 186 | + - not bin_stat.stat.exists |
| 187 | + fail: |
| 188 | + msg: "Expected pandoc at {{ bin_path }} but it was not found after extraction/normalisation." |
| 189 | + tags: pandoc |
| 190 | + |
| 191 | + - name: Symlink pandoc into {{ pandoc_bin_dir }} |
| 192 | + when: [supported, need_install] |
| 193 | + become: true |
| 194 | + file: |
| 195 | + src: "{{ bin_path }}" |
| 196 | + dest: "{{ pandoc_bin_dir }}/pandoc" |
| 197 | + state: link |
| 198 | + force: true |
| 199 | + follow: false |
| 200 | + tags: pandoc |
| 201 | + |
| 202 | + - name: Verify Pandoc installation |
| 203 | + when: supported |
| 204 | + become: true |
| 205 | + command: "{{ pandoc_bin_dir }}/pandoc --version" |
| 206 | + changed_when: false |
| 207 | + failed_when: false |
| 208 | + tags: pandoc |
| 209 | + |
| 210 | + # Cleanup (remove archive) |
| 211 | + - name: Remove downloaded archive |
| 212 | + when: [supported, need_install] |
| 213 | + become: true |
| 214 | + file: |
| 215 | + path: "{{ archive_path }}" |
| 216 | + state: absent |
| 217 | + tags: pandoc |
0 commit comments