1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-02-12 19:22:24 +00:00
iiab/roles/kiwix/tasks/install.yml

145 lines
5.9 KiB
YAML

# 0. VERIFY CPU/OS ARCHITECTURE SUPPORTED
- name: Force Ansible to exit (FAIL) if kiwix-tools appears unavailable for your CPU/OS architecture ({{ ansible_machine }})
fail:
msg: "WARNING: kiwix-tools SOFTWARE APPEARS UNAVAILABLE FOR YOUR {{ ansible_machine }} CPU/OS ARCHITECTURE."
when: kiwix_arch == "unsupported"
- name: Record (initial) disk space used
shell: df -B1 --output=used / | tail -1
register: df1
# 1. PUT IN PLACE: /opt/iiab/downloads/kiwix-tools_linux-*.tar.gz, move /opt/iiab/kiwix/bin aside if nec, create essential dirs, and test.zim if nec (library.xml is created later, by enable-or-disable.yml)
# 2022-10-04: get_url might be removed in future (unarchive below can handle
# everything!) Conversely: (1) unarchive doesn't support timeout (2) one day
# /opt/iiab/downloads might have practical value beyond hoarding (unlikely!)
- name: Download {{ kiwix_base_url }}{{ kiwix_tar_gz }} into /opt/iiab/downloads (ACTUAL filename should include kiwix-tools version, or nightly build date)
get_url:
url: "{{ kiwix_base_url }}{{ kiwix_tar_gz }}" # e.g. https://download.kiwix.org/release/kiwix-tools/ + kiwix-tools_linux-x86_64.tar.gz
dest: "{{ downloads_dir }}" # /opt/iiab/downloads
#force: yes # Already implied b/c dest is a dir! (to recover from incomplete downloads, etc)
timeout: "{{ download_timeout }}"
register: kiwix_dl # PATH /opt/iiab/downloads + ACTUAL filename put in kiwix_dl.dest, for unarchive ~28 lines below
# - name: "2023-05-14: TEMPORARY PATCH REVERTING TO KIWIX-TOOLS 3.4.0 IF BUGGY 32-BIT (armhf) VERSION 3.5.0 IS DETECTED -- #3574"
# get_url:
# url: https://download.kiwix.org/release/kiwix-tools/kiwix-tools_linux-armhf-3.4.0.tar.gz
# dest: "{{ downloads_dir }}"
# timeout: "{{ download_timeout }}"
# #register: kiwix_dl # CLOBBERS kiwix_dl.dest WHEN THIS STANZA DOES NOT RUN :/
# when: kiwix_dl.dest == "/opt/iiab/downloads/kiwix-tools_linux-armhf-3.5.0.tar.gz"
#
# # Ansible does not allow changing individuals subfields in a dictionary, but
# # this crude hack works, overwriting the entire kiwix_dl dictionary var with
# # the single (needed) key/value pair. (Or "register: tmp_dl" could be set
# # above, if its other [subfields, key/value pairs, etc] really mattered...)
# - name: "2023-05-15: TEMPORARY PATCH REVERTING TO KIWIX-TOOLS 3.4.0 IF BUGGY 32-BIT (armhf) VERSION 3.5.0 IS DETECTED -- #3574"
# set_fact:
# kiwix_dl:
# dest: /opt/iiab/downloads/kiwix-tools_linux-armhf-3.4.0.tar.gz
# when: kiwix_dl.dest == "/opt/iiab/downloads/kiwix-tools_linux-armhf-3.5.0.tar.gz"
- name: Does {{ kiwix_path }}/bin already exist? (as a directory, symlink or file)
stat:
path: "{{ kiwix_path }}/bin" # /opt/iiab/kiwix
register: kiwix_bin
- name: If so, move {{ kiwix_path }}/bin to {{ kiwix_path }}/bin.DATE_TIME_TZ
shell: "mv {{ kiwix_path }}/bin {{ kiwix_path }}/bin.$(date +%F_%T_%Z)"
when: kiwix_bin.stat.exists
- name: "Create dirs, including parent dirs: {{ kiwix_path }}/bin (executables), {{ iiab_zim_path }}/content (ZIM files), {{ iiab_zim_path }}/index (legacy indexes) (by default 0755)"
file:
path: "{{ item }}"
state: directory
with_items:
- "{{ kiwix_path }}/bin"
- "{{ iiab_zim_path }}/content" # /library/zims
- "{{ iiab_zim_path }}/index"
- name: Count *.zim files in {{ iiab_zim_path }}/content
find:
paths: "{{ iiab_zim_path }}/content"
patterns: '*.zim'
register: kiwix_zims
- name: If there were none, install {{ iiab_zim_path }}/content/test.zim
copy:
src: test.zim
dest: "{{ iiab_zim_path }}/content/test.zim"
#force: no
when: kiwix_zims.matched == 0
# 2. INSTALL KIWIX-TOOLS EXECUTABLES
- name: Unarchive {{ kiwix_dl.dest }} to {{ kiwix_path }}/bin -- untar with '--strip-components=1' to chop tarball's top-level dir from path
unarchive:
src: "{{ kiwix_dl.dest }}" # See ~28 lines above, e.g. /opt/iiab/downloads/kiwix-tools_linux-x86_64-3.3.0-1.tar.gz
dest: "{{ kiwix_path }}/bin"
extra_opts: --strip-components=1
owner: root # 2023-05-14: When unpacking let's avoid bogus owner/group,
group: root # arising from UID/GID on Kiwix's build machine.
# 3. ENABLE MODS FOR APACHE PROXY IF DEBUNTU
# 2019-10-07: Moved to roles/httpd/tasks/main.yml
# 2019-09-29: Compare roles/kolibri/defaults/main.yml using just 1 (proxy_http)
#- name: Enable the 4 mods which permit Apache to proxy (debuntu)
# apache2_module:
# name: "{{ item }}"
# with_items:
# - proxy
# - proxy_html
# - proxy_http
# - rewrite
# when: is_debuntu
# 4. INSTALL iiab-make-kiwix-lib*, kiwix-serve.service, kiwix.conf for Apache
- name: 'Install from templates: kiwix-serve.service, iiab-make-kiwix-lib, iiab-make-kiwix-lib.py'
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: "{{ item.mode }}"
with_items:
- { src: 'kiwix-serve.service.j2', dest: '/etc/systemd/system/kiwix-serve.service', mode: '0644' }
- { src: 'iiab-make-kiwix-lib', dest: '/usr/bin/iiab-make-kiwix-lib', mode: '0755' }
- { src: 'iiab-make-kiwix-lib3.py', dest: '/usr/bin/iiab-make-kiwix-lib.py', mode: '0755' }
- name: daemon_reload, so systemd (re)reads newly installed kiwix-serve.service
systemd:
daemon_reload: yes
- name: Install Kiwix Android app
include_tasks: kiwix-apk.yml
when: kiwix_incl_apk
# 5. RECORD Kiwix AS INSTALLED
- name: Record (final) disk space used
shell: df -B1 --output=used / | tail -1
register: df2
- name: Add 'kiwix_disk_usage = {{ df2.stdout|int - df1.stdout|int }}' to {{ iiab_ini_file }}
ini_file:
path: "{{ iiab_ini_file }}" # /etc/iiab/iiab.ini
section: kiwix
option: kiwix_disk_usage
value: "{{ df2.stdout|int - df1.stdout|int }}"
- name: "Set 'kiwix_installed: True'"
set_fact:
kiwix_installed: True
- name: "Add 'kiwix_installed: True' to {{ iiab_state_file }}"
lineinfile:
path: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
regexp: '^kiwix_installed'
line: 'kiwix_installed: True'