Files
computer-playbook/roles/web-app-mediawiki/tasks/_ensure_require.yml
Kevin Veen-Birkenbach aaedaab3da refactor(web-app-mediawiki): unify debug & oidc handling via _ensure_require, introduce host-side prep, switch to bind mounts
- Removed obsolete Installation.md, TODO.md, 02_debug.yml, 05_oidc.yml and legacy debug enable/disable tasks
- Added 01_prep.yml to render debug.php/oidc.php on host side before container start
- Introduced _ensure_require.yml for generic require_once management in LocalSettings.php
- Renamed 01_install.yml -> 02_install.yml to align with new numbering
- Updated docker-compose.yml.j2 to bind-mount mw-local into /opt/mw-local
- Adjusted vars/main.yml to define MEDIAWIKI_LOCAL_MOUNT_DIR and MEDIAWIKI_LOCAL_PATH
- Templates debug.php.j2 and oidc.php.j2 now gated by MODE_DEBUG and MEDIAWIKI_OIDC_ENABLED
- main.yml now orchestrates prep, install, debug, extensions, oidc require, admin consistently

Ref: https://chatgpt.com/share/68b57db2-efcc-800f-a733-aca952298437
2025-09-01 13:04:57 +02:00

30 lines
1.1 KiB
YAML

---
# Inputs (per include übergeben):
# - ensure_present: bool (true => sicherstellen, dass Zeile existiert; false => entfernen)
# - require_path: string (z. B. "{{ MEDIAWIKI_LOCAL_PATH }}/debug.php")
- name: "Ensure require_once('{{ require_path }}') present/absent in LocalSettings.php"
shell: |
docker exec -u {{ MEDIAWIKI_USER }} {{ MEDIAWIKI_CONTAINER}} bash -lc '
set -e
LSP={{ MEDIAWIKI_HTML_DIR }}/LocalSettings.php
LINE="require_once '\''{{ require_path }}'\'';"
test -f "$LSP" || exit 0
if {{ (ensure_present | bool) | ternary("true","false") }}; then
if ! grep -Fqx -- "$LINE" "$LSP"; then
printf "%s\n" "$LINE" >> "$LSP"
echo ADDED_REQUIRE
fi
else
if grep -Fqx -- "$LINE" "$LSP"; then
sed -i "\#require_once '{{ require_path }}';#d" "$LSP"
echo REMOVED_REQUIRE
fi
fi
'
args: { executable: /bin/bash }
register: _req_mut
changed_when: >
'ADDED_REQUIRE' in (_req_mut.stdout | default('')) or
'REMOVED_REQUIRE' in (_req_mut.stdout | default(''))