# Role "www_base" runs here, probably in 3-BASE-SERVER.
# Role "www_options" runs later, likely in 4-SERVER-OPTIONS.

# 2021-06-27: Antifragile roles can become less brittle by fully declaring
# their own dependencies (i.e. for modularity, separation-of-concerns,
# encapsulation, compartmentalization, scope sanity, etc).
#
#- name: Install 10 PHP packages (run 'php -m' or 'php -i' to verify)
#  package:
#    name:
#      - php{{ php_version }}           # On Ubuntu 20.04 (and prob other OS's) this unfortunately forces the install of: apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php{{ php_version }} ETC
#      - php{{ php_version }}-common    # 2021-06-27: @jvonau suggested this (2020-05-21) to avoid Apache packages dragged in above.  REGARDLESS: php{{ php_version }}-common superset php{{ php_version }}-cli is auto-installed by php{{ php_version }}-fpm in nginx/tasks/install.yml
#      - php{{ php_version }}-curl      # 2021-06-30: Installed in moodle/tasks/main.yml, nextcloud/tasks/install.yml, pbx/tasks/freepbx_dependencies.yml, wordpress/tasks/main.yml
#      - php{{ php_version }}-gd        # 2021-06-30: Installed in moodle/tasks/main.yml, nextcloud/tasks/install.yml, pbx/tasks/freepbx_dependencies.yml
#      - php{{ php_version }}-imap      # 2021-06-27: Installed in pbx/tasks/freepbx_dependencies.yml
#      - php{{ php_version }}-ldap      # 2021-06-27: Experimentally remove
#      - php{{ php_version }}-mysql     # 2021-06-30: Installed in mysql/tasks/install.yml, nextcloud/tasks/install.yml, pbx/tasks/freepbx_dependencies.yml, wordpress/tasks/main.yml
#      - php{{ php_version }}-odbc      # 2021-06-27: Experimentally remove
#      - php-pear                       # 2021-06-27: REQUIRED BY ADMIN CONSOLE https://github.com/iiab/iiab-admin-console/blob/master/roles/cmdsrv/tasks/main.yml#L19
#      - php{{ php_version }}-sqlite3   # 2020-07-10: Installed in osm-vector-maps/tasks/install.yml as part of OSM fix PR #2464 for #2461
#      - php{{ php_version }}-xml       # 2021-06-30: Installed in mediawiki/tasks/install.yml, moodle/tasks/install.yml, nextcloud/tasks/install.yml, pbx/tasks/freepbx_dependencies.yml, wordpress/tasks/main.yml
#      - php{{ php_version }}-xmlrpc    # 2021-06-27: Experimentally remove -- SEE EXPLANATION IN moodle/tasks/main.yml
#    state: present

- name: Install html.yml
  include_tasks: html.yml

- name: Install php-stem.yml if php_version == 7.4 and (ansible_machine == "armv6l" or ansible_machine == "armv7l" or ansible_machine == "aarch64" or ansible_machine == "x86_64")
  include_tasks: php-stem.yml
  when: php_version == 7.4 and (ansible_machine == "armv6l" or ansible_machine == "armv7l" or ansible_machine == "aarch64" or ansible_machine == "x86_64")
   # or php_version == 8.0 or php_version == 8.1 or php_version == 8.2 (IIAB MIGHT SUPPORT THESE LATER IN 2023)
   # or php_version == 7.2 or php_version == 7.3 (PROBABLY WORK, AT YOUR OWN RISK!)

- name: Create dir {{ doc_root }}/home -- if you customized var iiab_home_url e.g. in /etc/iiab/local_vars.yml, that dir is created later -- by www_options/tasks/main.yml
  file:
    state: directory
    path: "{{ doc_root }}/home"    # /library/www/html
    owner: "{{ apache_user }}"
    group: "{{ apache_user }}"

- name: Create dir {{ doc_root }}/info for http://box/info offline docs
  file:
    state: directory
    path: "{{ doc_root }}/info"    # /library/www/html
    owner: "{{ apache_user }}"
    group: "{{ apache_user }}"

- name: Install /usr/bin/iiab-refresh-wiki-docs (scraper script) to create http://box/info offline documentation.  (Script can be run manually and/or at the end of Stage 4 = roles/4-server-options/tasks/main.yml)
  template:
    src: iiab-refresh-wiki-docs.sh
    dest: /usr/bin/iiab-refresh-wiki-docs
    mode: '0755'


# RECORD www_base AS INSTALLED

- name: "Set 'www_base_installed: True'"
  set_fact:
    www_base_installed: True

- name: "Add 'www_base_installed: True' to {{ iiab_state_file }}"
  lineinfile:
    path: "{{ iiab_state_file }}"    # /etc/iiab/iiab_state.yml
    regexp: '^www_base_installed'
    line: 'www_base_installed: True'
