2017-11-27 03:33:05 +00:00
# 1. CREATE/VERIFY CRITICAL DIRECTORIES & FILES ARE IN PLACE
2018-10-31 05:42:27 +00:00
- name : Create directory {{ iiab_zim_path }} and subdirs {content, index} for Kiwix ZIM files
2017-11-25 22:12:26 +00:00
file :
path : "{{ item }}"
owner : root
group : root
mode : 0755
state : directory
2017-05-27 18:09:50 +00:00
with_items :
2017-11-25 22:12:26 +00:00
- "{{ iiab_zim_path }}"
2017-11-27 03:33:05 +00:00
- "{{ iiab_zim_path }}/content"
2017-11-25 22:12:26 +00:00
- "{{ iiab_zim_path }}/index"
2017-05-27 18:09:50 +00:00
2018-10-31 05:42:27 +00:00
- name : Check for {{ kiwix_library_xml }} # /library/zims/library.xml
2017-11-25 22:12:26 +00:00
stat :
2017-11-26 15:38:48 +00:00
path : "{{ kiwix_library_xml }}"
register : kiwix_xml
2017-09-11 16:21:07 +00:00
2018-10-31 05:42:27 +00:00
- name : Install a stub /library/zims/library.xml if one doesn't exist
2017-11-25 22:12:26 +00:00
template :
src : "{{ item }}"
dest : "{{ kiwix_library_xml }}"
mode : 0644
owner : root
group : root
force : no
2017-05-27 18:09:50 +00:00
with_items :
2017-11-25 22:12:26 +00:00
- library.xml
2017-11-26 15:38:48 +00:00
when : not kiwix_xml.stat.exists
- name : Check for /opt/iiab/kiwix/bin/kiwix-serve binary
stat :
2017-11-27 18:07:28 +00:00
path : "{{ kiwix_path }}/bin/kiwix-serve"
2017-11-26 15:38:48 +00:00
register : kiwix_bin
2018-10-31 05:42:27 +00:00
- name : Set fact kiwix_force_install if kiwix-serve not found
2017-11-26 15:38:48 +00:00
set_fact :
2017-11-26 17:19:16 +00:00
kiwix_force_install : True
2017-11-27 03:33:05 +00:00
when : not kiwix_bin.stat.exists
2017-05-27 18:09:50 +00:00
2018-10-31 05:42:27 +00:00
- name : Install {{ iiab_zim_path }}/content/test.zim if kiwix_force_install
2017-11-25 22:12:26 +00:00
copy :
src : test.zim
2017-11-27 03:33:05 +00:00
dest : "{{ iiab_zim_path }}/content/test.zim"
2017-11-25 22:12:26 +00:00
mode : 0644
owner : root
group : root
force : no
2019-05-24 22:33:10 +00:00
when : kiwix_force_install | bool
2017-05-27 18:09:50 +00:00
2018-10-31 05:42:27 +00:00
- name : Create {{ kiwix_path }}/bin directory # /opt/iiab/kiwix/bin
2017-11-26 16:58:58 +00:00
file :
2017-11-27 18:07:28 +00:00
path : "{{ kiwix_path }}/bin"
2017-11-26 16:58:58 +00:00
owner : root
group : root
mode : 0755
state : directory
2017-11-27 03:33:05 +00:00
# 2. INSTALL KIWIX-TOOLS EXECUTABLES IF kiwix_force_install
2017-11-26 16:58:58 +00:00
2018-10-31 05:42:27 +00:00
- name : Unarchive {{ kiwix_src_file }} to /tmp # e.g. kiwix-tools_linux-armhf-0.6.1-1.tar.gz
2017-11-27 03:33:05 +00:00
unarchive :
src : "{{ downloads_dir }}/{{ kiwix_src_file }}"
dest : /tmp
owner : root
group : root
2019-05-24 22:33:10 +00:00
when : kiwix_force_install | bool
2018-03-27 15:48:56 +00:00
2018-07-02 12:26:26 +00:00
- name : Move /tmp/{{ kiwix_src_dir }}/* to permanent location /opt/iiab/kiwix/bin (armhf & linux64 & i686)
2018-03-27 16:02:58 +00:00
shell : "mv /tmp/{{ kiwix_src_dir }}/* {{ kiwix_path }}/bin/"
2019-05-24 22:33:10 +00:00
when : kiwix_force_install | bool
2017-11-27 03:33:05 +00:00
# 3. ENABLE MODS FOR APACHE PROXY IF DEBUNTU
2017-11-26 16:58:58 +00:00
2018-10-31 05:42:27 +00:00
- name : Enable the 4 mods which permit Apache to proxy (debuntu)
2017-11-26 15:38:48 +00:00
apache2_module :
name : "{{ item }}"
with_items :
- proxy
- proxy_html
- proxy_http
- rewrite
2019-05-24 22:33:10 +00:00
when : is_debuntu | bool
2017-11-26 15:38:48 +00:00
2018-09-15 04:27:44 +00:00
# 4. CREATE/ENABLE/RESTART (OR DISABLE) KIWIX SERVICE & ITS CRON JOB
2017-05-27 18:09:50 +00:00
2018-10-31 05:42:27 +00:00
- name: 'Install from templates : kiwix-serve.service, iiab-make-kiwix-lib, iiab-make-kiwix-lib.py, kiwix.conf'
2017-11-25 22:12:26 +00:00
template :
backup : no
src : "{{ item.src }}"
dest : "{{ item.dest }}"
owner : root
group : root
mode : "{{ item.mode }}"
2017-05-27 18:09:50 +00:00
with_items :
2017-11-25 22:12:26 +00:00
- { src: 'kiwix-serve.service.j2', dest: '/etc/systemd/system/kiwix-serve.service', mode : '0644' }
# - { src: 'kiwix-serve-init.j2', dest: '/usr/libexec/kiwix-serve-init', mode: '0755'}
- { src: 'iiab-make-kiwix-lib', dest: '/usr/bin/iiab-make-kiwix-lib', mode : '0755' }
- { src: 'iiab-make-kiwix-lib.py', dest: '/usr/bin/iiab-make-kiwix-lib.py', mode : '0755' }
2017-12-02 16:49:25 +00:00
# - { src: 'iiab-make-apache-config.py', dest: '/usr/bin/iiab-make-apache-config.py', mode: '0755'}
- { src: 'kiwix.conf.j2', dest : '/etc/{{ apache_config_dir }}/kiwix.conf' , mode : '0644' }
2018-10-31 05:42:27 +00:00
- name : Create softlink kiwix.conf from sites-enabled to sites-available - for Kiwix Proxy in Apache - is disabled by turning off service kiwix-serve (debuntu)
2018-09-15 04:27:44 +00:00
file :
src : /etc/apache2/sites-available/kiwix.conf
path : /etc/apache2/sites-enabled/kiwix.conf
state : link
2019-05-24 22:33:10 +00:00
when : is_debuntu | bool
2017-05-27 18:09:50 +00:00
2018-10-31 05:42:27 +00:00
- name : Enable & Restart 'kiwix-serve' service
2019-08-01 19:32:46 +00:00
systemd :
daemon_reload : yes
2017-11-26 15:38:48 +00:00
name : kiwix-serve
enabled : yes
state : restarted
2019-05-24 22:33:10 +00:00
when : kiwix_enabled | bool
2017-11-26 15:38:48 +00:00
2017-11-27 00:54:35 +00:00
- name : Disable 'kiwix-serve' service
2019-08-01 19:32:46 +00:00
systemd :
2017-11-27 00:54:35 +00:00
name : kiwix-serve
enabled : no
state : stopped
when : not kiwix_enabled
2017-11-27 03:33:05 +00:00
# IN THEORY: BOTH CRON ENTRIES BELOW *SHOULD* BE DELETED "when: not kiwix_enabled"
# In the past kiwix-serve did not stay running, so we'd been doing this hourly.
# @mgautierfr & others suggest kiwix-serve might be auto-restarted w/o cron in
# future, whenever service fails, if this really catches all cases??
# https://github.com/iiab/iiab/issues/484#issuecomment-342151726
- name : Make a crontab entry to restart kiwix-serve at 4AM (debuntu)
lineinfile :
# 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
- 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
2018-09-15 04:27:44 +00:00
- name : Restart Apache, so it picks up kiwix.conf
service :
name : "{{ apache_service }}"
state : restarted
2017-12-02 21:53:36 +00:00
2017-11-27 03:33:05 +00:00
# 5. FINALIZE
2017-11-26 15:38:48 +00:00
2018-10-31 05:42:27 +00:00
- name : Add 'kiwix' variable values to {{ iiab_ini_file }}
2017-11-25 22:12:26 +00:00
ini_file :
2018-10-31 05:42:27 +00:00
path : "{{ iiab_ini_file }}"
2017-12-08 11:26:40 +00:00
section : kiwix
2017-11-25 22:12:26 +00:00
option : "{{ item.option }}"
value : "{{ item.value }}"
2017-05-27 18:09:50 +00:00
with_items :
2017-11-25 22:12:26 +00:00
- option : name
2017-12-08 11:26:40 +00:00
value : Kiwix
2017-11-25 22:12:26 +00:00
- option : description
value : '"Part of https://github.com/kiwix/kiwix-tools/ - kiwix-serve is the most used web server for ZIM files."'
2017-11-27 18:09:32 +00:00
- option : kiwix_url
value : "{{ kiwix_url }}"
- option : kiwix_path
value : "{{ kiwix_path }}"
2017-11-25 22:12:26 +00:00
- option : kiwix_port
value : "{{ kiwix_port }}"
- option : iiab_zim_path
value : "{{ iiab_zim_path }}"
- option : kiwix_library_xml
value : "{{ kiwix_library_xml }}"
2019-01-10 22:26:47 +00:00
- option : kiwix_enabled
2017-11-27 03:57:03 +00:00
value : "{{ kiwix_enabled }}"