diff --git a/roles/web-app-mediawiki/tasks/main.yml b/roles/web-app-mediawiki/tasks/main.yml index a8f78fae..da6fb1e9 100644 --- a/roles/web-app-mediawiki/tasks/main.yml +++ b/roles/web-app-mediawiki/tasks/main.yml @@ -3,16 +3,52 @@ include_role: name: sys-stk-full-stateful vars: - docker_compose_flush_handlers: false + docker_compose_flush_handlers: true -- name: "Deploy MediaWiki LocalSettings.php" - template: - src: "LocalSettings.php.j2" - dest: "{{ MEDIAWIKI_SETTINGS_HOST_PATH }}" - mode: '0644' +- name: "Wait for DB to be reachable" + command: > + docker exec {{ MEDIAWIKI_CONTAINER }} + php /var/www/html/maintenance/sql.php --query "SELECT 1;" + register: mw_db_ready + retries: 15 + delay: 2 + until: mw_db_ready.rc == 0 + changed_when: false + failed_when: false -- name: "Flush docker compose handlers" - meta: flush_handlers +- name: "Install MediaWiki if no schema exists" + command: > + docker exec -u {{ MEDIAWIKI_USER }} {{ MEDIAWIKI_CONTAINER }} + php /var/www/html/maintenance/install.php + --dbname="{{ database_name }}" + --dbuser="{{ database_username }}" + --dbpass="{{ database_password }}" + --dbserver="{{ database_host }}:{{ database_port }}" + --installdbuser="{{ database_username }}" + --installdbpass="{{ database_password }}" + --server="{{ MEDIAWIKI_URL }}" + --scriptpath="" + --lang={{ HOST_LL }} + --pass="{{ MEDIAWIKI_ADMINISTRATOR_PASSWORD }}" + "{{ MEDIAWIKI_SITENAME }}" + "{{ MEDIAWIKI_ADMINISTRATOR_NAME }}" + no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}" + register: mw_install + changed_when: mw_install.rc == 0 + failed_when: > + mw_install.rc != 0 and + ('LocalSettings.php file has been detected' not in (((mw_install.stdout | default('')) ~ (mw_install.stderr | default(''))))) and + ('run update.php instead' not in (((mw_install.stdout | default('')) ~ (mw_install.stderr | default(''))))) + +- name: "Initialize / migrate MediaWiki database schema" + command: > + docker exec + -u {{ MEDIAWIKI_USER }} + {{ MEDIAWIKI_CONTAINER }} + php /var/www/html/maintenance/update.php --quick + register: mw_update + changed_when: "'...done.' in (mw_update.stdout | default(''))" + failed_when: mw_update.rc != 0 - name: "Create MediaWiki admin user" command: > @@ -26,8 +62,12 @@ {{ MEDIAWIKI_ADMINISTRATOR_EMAIL }} register: create_admin changed_when: > - 'created' in (create_admin.stdout | default('')) or - 'Created' in (create_admin.stdout | default('')) + ('created' in ((create_admin.stdout | default('')) ~ (create_admin.stderr | default('')))) or + ('Created' in ((create_admin.stdout | default('')) ~ (create_admin.stderr | default('')))) failed_when: > create_admin.rc != 0 and - ('already exists' not in (create_admin.stdout | default('') ~ create_admin.stderr | default(''))) + ('already exists' not in ((create_admin.stdout | default('')) ~ (create_admin.stderr | default('')))) and + ('Account exists' not in ((create_admin.stdout | default('')) ~ (create_admin.stderr | default('')))) + async: "{{ ASYNC_TIME if ASYNC_ENABLED | bool else omit }}" + poll: "{{ ASYNC_POLL if ASYNC_ENABLED | bool else omit }}" + no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}" diff --git a/roles/web-app-mediawiki/templates/LocalSettings.php.j2 b/roles/web-app-mediawiki/templates/LocalSettings.php.j2 deleted file mode 100644 index 8035aca0..00000000 --- a/roles/web-app-mediawiki/templates/LocalSettings.php.j2 +++ /dev/null @@ -1,29 +0,0 @@ -