From 8643285dc9722a42484233acffb05039cfd1fc0e Mon Sep 17 00:00:00 2001 From: root Date: Tue, 4 Oct 2022 19:09:04 -0400 Subject: [PATCH 1/6] Auto-install latest/official kiwix-tools + tighten up code --- roles/kiwix/defaults/main.yml | 27 +++++++++++++----- roles/kiwix/tasks/install.yml | 53 ++++++++++------------------------- roles/kiwix/tasks/main.yml | 2 ++ 3 files changed, 37 insertions(+), 45 deletions(-) diff --git a/roles/kiwix/defaults/main.yml b/roles/kiwix/defaults/main.yml index 332eb6289..21737efc3 100644 --- a/roles/kiwix/defaults/main.yml +++ b/roles/kiwix/defaults/main.yml @@ -21,14 +21,27 @@ # - index = directory for legacy *.zim.idx's kiwix_library_xml: "{{ iiab_zim_path }}/library.xml" -# 3 lines below specify which version(s) of kiwix-tools to download from... -# https://download.iiab.io/packages/ ...as originally obtained from... -# https://download.kiwix.org/release/kiwix-tools/ ...or sometimes... -# https://download.kiwix.org/nightly/ +kiwix_base_url: https://download.kiwix.org/release/kiwix-tools/ +#kiwix_base_url: https://download.kiwix.org/nightly/2022-10-04/ +#kiwix_base_url: "{{ iiab_download_url }}/" # https://download.iiab.io/packages/ -kiwix_version_armhf: kiwix-tools_linux-armhf-3.3.0-1 -kiwix_version_linux64: kiwix-tools_linux-x86_64-3.3.0-1 -kiwix_version_i686: kiwix-tools_linux-i586-3.3.0-1 +kiwix_arch_dict: + #i386: + i686: i586 + x86_64: x86_64 + armv6l: armhf + armv7l: armhf + aarch64: armhf + +# ansible_architecture can also work: +# https://stackoverflow.com/questions/66828315/what-is-the-difference-between-ansible-architecture-and-ansible-machine-on-a/66828837#66828837 +kiwix_arch: "{{ kiwix_arch_dict[ansible_machine] | default('unsupported') }}" + +# Latest official kiwix-tools release, per Kiwix permalink redirects: +# https://www.kiwix.org/en/downloads/kiwix-serve/ +# https://github.com/kiwix/container-images/issues/236 +kiwix_tar_gz: "kiwix-tools_linux-{{ kiwix_arch }}.tar.gz" +#kiwix_tar_gz: "kiwix-tools_linux-{{ kiwix_arch }}-3.3.0-1.tar.gz" # Version can be hard-coded if you prefer (as was done til 2022-10-04) # kiwix_src_file_i686: "kiwix-linux-i686.tar.bz2" # v0.9 for i686 published May 2014 ("use it to test legacy ZIM content") diff --git a/roles/kiwix/tasks/install.yml b/roles/kiwix/tasks/install.yml index 3a6c6dcba..f9afc32ff 100644 --- a/roles/kiwix/tasks/install.yml +++ b/roles/kiwix/tasks/install.yml @@ -1,42 +1,22 @@ -# 0. SET CPU ARCHITECTURE +# 0. VERIFY CPU/OS ARCHITECTURE SUPPORTED -- name: "Initialize 'kiwix_src_dir: False' just in case CPU architecture is not supported" - set_fact: - kiwix_src_dir: False - -- name: "Set fact 'kiwix_src_dir: {{ kiwix_version_armhf }}' (armv6l or armv71 or aarch64)" - set_fact: - kiwix_src_dir: "{{ kiwix_version_armhf }}" - when: ansible_machine == "armv6l" or ansible_machine == "armv7l" or ansible_machine == "aarch64" - -- name: "Set fact 'kiwix_src_dir: {{ kiwix_version_linux64 }}' (x86_64)" - set_fact: - kiwix_src_dir: "{{ kiwix_version_linux64 }}" - when: ansible_machine == "x86_64" - -- name: "Set fact 'kiwix_src_dir: {{ kiwix_version_i686 }}' (i686)" - set_fact: - kiwix_src_dir: "{{ kiwix_version_i686 }}" - when: ansible_machine == "i686" -# COMMENT OUT LINE ABOVE TO TEST i686 CODE PATH ON X86_64 (WORKS NOV 2017) - -- name: Force Ansible to exit (FAIL) if kiwix-tools appears unavailable for your architecture ({{ ansible_machine }}) +- 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 }} OS/ARCHITECTURE." - when: not kiwix_src_dir - -- name: "Set fact 'kiwix_src_file: {{ kiwix_src_dir }}.tar.gz'" - set_fact: - kiwix_src_file: "{{ kiwix_src_dir }}.tar.gz" + msg: "WARNING: kiwix-tools SOFTWARE APPEARS UNAVAILABLE FOR YOUR {{ ansible_machine }} CPU/OS ARCHITECTURE." + when: kiwix_arch == "unsupported" # 1. PUT IN PLACE: /opt/iiab/downloads/kiwix-tools_linux-*.tar.gz, essential dirs, and test.zim if nec (library.xml is created later, by enable-or-disable.yml) -- name: Download {{ iiab_download_url }}/{{ kiwix_src_file }} to /opt/iiab/downloads +# 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 }} to /opt/iiab/downloads get_url: - url: "{{ iiab_download_url }}/{{ kiwix_src_file }}" # https://download.iiab.io/packages - dest: "{{ downloads_dir }}/{{ kiwix_src_file }}" # /opt/iiab/downloads + 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 timeout: "{{ download_timeout }}" + register: kiwix_dl # Kiwix URL redirects to a longer filename, including the actual kiwix-tools version (placed in kiwix_dl.dest with its path, for unarchive ~28 lines below) - 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: @@ -63,13 +43,11 @@ # 2. INSTALL KIWIX-TOOLS EXECUTABLES -- name: Unarchive {{ kiwix_src_file }} to /tmp # e.g. kiwix-tools_linux-armhf-3.1.2-3.tar.gz +- name: Unarchive {{ kiwix_dl.dest }} to {{ kiwix_path }}/bin -- use '--strip-components=1' to remove tarball's top-level dir during unpacking unarchive: - src: "{{ downloads_dir }}/{{ kiwix_src_file }}" - dest: /tmp - -- name: Move /tmp/{{ kiwix_src_dir }}/* to permanent location {{ kiwix_path }}/bin - shell: "mv /tmp/{{ kiwix_src_dir }}/* {{ kiwix_path }}/bin/" # /opt/iiab/kiwix + 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" # /opt/iiab/kiwix/bin + extra_opts: --strip-components=1 # 3. ENABLE MODS FOR APACHE PROXY IF DEBUNTU @@ -103,7 +81,6 @@ systemd: daemon_reload: yes -# install kiwix app - name: Install Kiwix Android app include_tasks: kiwix-apk.yml when: kiwix_incl_apk diff --git a/roles/kiwix/tasks/main.yml b/roles/kiwix/tasks/main.yml index ab5064fba..22c8820dc 100644 --- a/roles/kiwix/tasks/main.yml +++ b/roles/kiwix/tasks/main.yml @@ -42,6 +42,8 @@ value: "{{ kiwix_install }}" - option: kiwix_enabled value: "{{ kiwix_enabled }}" + - option: kiwix_tar_gz + value: "{{ kiwix_tar_gz }}" - option: kiwix_url value: "{{ kiwix_url }}" - option: kiwix_url_plus_slash From f2b74880e8c59a22ec864bf746e1f80f41d3d5ec Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 4 Oct 2022 19:49:19 -0400 Subject: [PATCH 2/6] kiwix/defaults/main.yml: Clarify ansible_machine safer than ansible_architecture --- roles/kiwix/defaults/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/roles/kiwix/defaults/main.yml b/roles/kiwix/defaults/main.yml index 21737efc3..acfa7a08b 100644 --- a/roles/kiwix/defaults/main.yml +++ b/roles/kiwix/defaults/main.yml @@ -33,8 +33,10 @@ kiwix_arch_dict: armv7l: armhf aarch64: armhf -# ansible_architecture can also work: +# ansible_architecture might also work, if not quite as well: # https://stackoverflow.com/questions/66828315/what-is-the-difference-between-ansible-architecture-and-ansible-machine-on-a/66828837#66828837 +# CLAIM: 'ansible_machine might be "i686", whereas ansible_architecture on the same host would be "i386"' +# https://stackoverflow.com/questions/44713880/how-do-i-make-decision-based-on-arch-in-ansible-playbooks/44714226#44714226 kiwix_arch: "{{ kiwix_arch_dict[ansible_machine] | default('unsupported') }}" # Latest official kiwix-tools release, per Kiwix permalink redirects: From 7e86d5e582d3f280eec3ce9610777693ddbc1b46 Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 4 Oct 2022 20:02:04 -0400 Subject: [PATCH 3/6] kiwix/tasks/install.yml: Clarify get_url "force: yes" implied b/c dest is a dir --- roles/kiwix/tasks/install.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/roles/kiwix/tasks/install.yml b/roles/kiwix/tasks/install.yml index f9afc32ff..db7b1a9c0 100644 --- a/roles/kiwix/tasks/install.yml +++ b/roles/kiwix/tasks/install.yml @@ -15,6 +15,7 @@ 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 # Implied b/c dest is a dir! (to recover from incomplete downloads, etc) timeout: "{{ download_timeout }}" register: kiwix_dl # Kiwix URL redirects to a longer filename, including the actual kiwix-tools version (placed in kiwix_dl.dest with its path, for unarchive ~28 lines below) From c1d0bd03dd1e7500c98eb0abab42c6b67068a103 Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 4 Oct 2022 20:11:25 -0400 Subject: [PATCH 4/6] Untar with '--strip-components=1' to chop tarball's top-level dir from path --- roles/kiwix/tasks/install.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/kiwix/tasks/install.yml b/roles/kiwix/tasks/install.yml index db7b1a9c0..ab3c8fc27 100644 --- a/roles/kiwix/tasks/install.yml +++ b/roles/kiwix/tasks/install.yml @@ -44,7 +44,7 @@ # 2. INSTALL KIWIX-TOOLS EXECUTABLES -- name: Unarchive {{ kiwix_dl.dest }} to {{ kiwix_path }}/bin -- use '--strip-components=1' to remove tarball's top-level dir during unpacking +- 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" # /opt/iiab/kiwix/bin From ff0384f7783e1068adcaa233ffc2da9a332cd7e7 Mon Sep 17 00:00:00 2001 From: A Holt Date: Tue, 4 Oct 2022 20:24:06 -0400 Subject: [PATCH 5/6] kiwix/defaults/main.yml: Clarify "e.g. https://download.iiab.io/packages/" --- roles/kiwix/defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/kiwix/defaults/main.yml b/roles/kiwix/defaults/main.yml index acfa7a08b..2696974fd 100644 --- a/roles/kiwix/defaults/main.yml +++ b/roles/kiwix/defaults/main.yml @@ -23,7 +23,7 @@ kiwix_library_xml: "{{ iiab_zim_path }}/library.xml" kiwix_base_url: https://download.kiwix.org/release/kiwix-tools/ #kiwix_base_url: https://download.kiwix.org/nightly/2022-10-04/ -#kiwix_base_url: "{{ iiab_download_url }}/" # https://download.iiab.io/packages/ +#kiwix_base_url: "{{ iiab_download_url }}/" # e.g. https://download.iiab.io/packages/ kiwix_arch_dict: #i386: From 35898a6f92a24ede5d34a24fc4ee46927d596357 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 5 Oct 2022 00:17:37 -0400 Subject: [PATCH 6/6] First move /opt/iiab/kiwib/bin aside + Explain better --- roles/kiwix/tasks/enable-or-disable.yml | 18 +++++++++--------- roles/kiwix/tasks/install.yml | 21 +++++++++++++++------ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/roles/kiwix/tasks/enable-or-disable.yml b/roles/kiwix/tasks/enable-or-disable.yml index 9f813f4ad..c3b2d617c 100644 --- a/roles/kiwix/tasks/enable-or-disable.yml +++ b/roles/kiwix/tasks/enable-or-disable.yml @@ -13,7 +13,7 @@ systemd: name: kiwix-serve enabled: yes - state: started # Not needed...but can't hurt + state: started when: kiwix_enabled @@ -28,15 +28,15 @@ # mn hr dy mo day-of-week[Sunday=0] username command-to-be-executed line: "0 4 * * * root /bin/systemctl restart kiwix-serve.service" dest: /etc/crontab - when: kiwix_enabled and is_debuntu + when: kiwix_enabled -- name: Make a crontab entry to restart kiwix-serve at 4AM (redhat) -# * * * * * user-name command to be executed - lineinfile: - # mn hr dy mo day-of-week[Sunday=0] username command-to-be-executed - line: "0 4 * * * root /usr/bin/systemctl restart kiwix-serve.service" - dest: /etc/crontab - when: kiwix_enabled and is_redhat +# - name: Make a crontab entry to restart kiwix-serve at 4AM (redhat) +# # * * * * * user-name command to be executed +# lineinfile: +# # mn hr dy mo day-of-week[Sunday=0] username command-to-be-executed +# line: "0 4 * * * root /usr/bin/systemctl restart kiwix-serve.service" +# dest: /etc/crontab +# when: kiwix_enabled and is_redhat - name: Enable/Disable/Restart NGINX diff --git a/roles/kiwix/tasks/install.yml b/roles/kiwix/tasks/install.yml index ab3c8fc27..8a95d52ba 100644 --- a/roles/kiwix/tasks/install.yml +++ b/roles/kiwix/tasks/install.yml @@ -6,25 +6,34 @@ when: kiwix_arch == "unsupported" -# 1. PUT IN PLACE: /opt/iiab/downloads/kiwix-tools_linux-*.tar.gz, essential dirs, and test.zim if nec (library.xml is created later, by enable-or-disable.yml) +# 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 }} to /opt/iiab/downloads +- 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 # Implied b/c dest is a dir! (to recover from incomplete downloads, etc) + #force: yes # Already implied b/c dest is a dir! (to recover from incomplete downloads, etc) timeout: "{{ download_timeout }}" - register: kiwix_dl # Kiwix URL redirects to a longer filename, including the actual kiwix-tools version (placed in kiwix_dl.dest with its path, for unarchive ~28 lines below) + register: kiwix_dl # PATH /opt/iiab/downloads + ACTUAL filename put in kiwix_dl.dest, for unarchive ~28 lines below + +- 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" # /opt/iiab/kiwix + - "{{ kiwix_path }}/bin" - "{{ iiab_zim_path }}/content" # /library/zims - "{{ iiab_zim_path }}/index" @@ -47,7 +56,7 @@ - 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" # /opt/iiab/kiwix/bin + dest: "{{ kiwix_path }}/bin" extra_opts: --strip-components=1