Optimized moodle variable names

This commit is contained in:
Kevin Veen-Birkenbach 2025-07-17 06:38:51 +02:00
parent 725fea1169
commit 529efc0bd7
No known key found for this signature in database
GPG Key ID: 44D8F11FD62F878E
7 changed files with 22 additions and 20 deletions

View File

@ -35,4 +35,6 @@ docker:
volumes: volumes:
data: data:
name: moodle_data name: moodle_data
code:
name: moodle_code

View File

@ -1,5 +1,5 @@
- name: Check if config.php exists - name: Check if config.php exists
command: docker exec --user root {{ moodle_name }} test -f {{ moodle_config }} command: docker exec --user root {{ moodle_container }} test -f {{ moodle_config }}
register: config_file_exists register: config_file_exists
changed_when: false changed_when: false
failed_when: false failed_when: false
@ -15,10 +15,10 @@
- name: Copy config.php from container to host - name: Copy config.php from container to host
command: > command: >
docker cp {{ moodle_name }}:{{ moodle_config }} /opt/docker/moodle/_backup/config.php.bak docker cp {{ moodle_container }}:{{ moodle_config }} /opt/docker/moodle/_backup/config.php.bak
- name: Check if config.php exists - name: Check if config.php exists
command: docker exec --user root {{ moodle_name }} test -f {{ moodle_config }} command: docker exec --user root {{ moodle_container }} test -f {{ moodle_config }}
register: config_file_exists register: config_file_exists
changed_when: false changed_when: false
failed_when: false failed_when: false
@ -28,20 +28,20 @@
block: block:
- name: Update DB host - name: Update DB host
command: > command: >
docker exec --user root {{ moodle_name }} docker exec --user root {{ moodle_container }}
sed -i "s/^\$CFG->dbhost *= *.*/\$CFG->dbhost = '{{ database_host }}';/" {{ moodle_config }} sed -i "s/^\$CFG->dbhost *= *.*/\$CFG->dbhost = '{{ database_host }}';/" {{ moodle_config }}
- name: Update DB name - name: Update DB name
command: > command: >
docker exec --user root {{ moodle_name }} docker exec --user root {{ moodle_container }}
sed -i "s/^\$CFG->dbname *= *.*/\$CFG->dbname = '{{ database_name }}';/" {{ moodle_config }} sed -i "s/^\$CFG->dbname *= *.*/\$CFG->dbname = '{{ database_name }}';/" {{ moodle_config }}
- name: Update DB user - name: Update DB user
command: > command: >
docker exec --user root {{ moodle_name }} docker exec --user root {{ moodle_container }}
sed -i "s/^\$CFG->dbuser *= *.*/\$CFG->dbuser = '{{ database_username }}';/" {{ moodle_config }} sed -i "s/^\$CFG->dbuser *= *.*/\$CFG->dbuser = '{{ database_username }}';/" {{ moodle_config }}
- name: Update DB password - name: Update DB password
command: > command: >
docker exec --user root {{ moodle_name }} docker exec --user root {{ moodle_container }}
sed -i "s/^\$CFG->dbpass *= *.*/\$CFG->dbpass = '{{ database_password }}';/" {{ moodle_config }} sed -i "s/^\$CFG->dbpass *= *.*/\$CFG->dbpass = '{{ database_password }}';/" {{ moodle_config }}

View File

@ -10,7 +10,7 @@
meta: flush_handlers meta: flush_handlers
- name: Wait until the Moodle container is healthy - name: Wait until the Moodle container is healthy
shell: docker inspect --format '{% raw %}{{.State.Health.Status}}{% endraw %}' {{ container_name }} shell: docker inspect --format '{% raw %}{{.State.Health.Status}}{% endraw %}' {{ moodle_container }}
register: health_check register: health_check
until: health_check.stdout.strip() == "healthy" until: health_check.stdout.strip() == "healthy"
retries: 120 retries: 120
@ -25,7 +25,7 @@
- name: Run Moodle system check - name: Run Moodle system check
command: > command: >
docker exec --user {{ bitnami_user }} {{ container_name }} docker exec --user {{ bitnami_user }} {{ moodle_container }}
php /opt/bitnami/moodle/admin/cli/checks.php php /opt/bitnami/moodle/admin/cli/checks.php
register: moodle_checks register: moodle_checks
changed_when: false changed_when: false

View File

@ -2,7 +2,7 @@
- name: Check if OIDC plugin is present in container - name: Check if OIDC plugin is present in container
command: > command: >
docker exec --user root {{ container_name }} test -d {{ bitnami_oidc_plugin_dir }} docker exec --user root {{ moodle_container }} test -d {{ bitnami_oidc_plugin_dir }}
register: oidc_plugin_check register: oidc_plugin_check
ignore_errors: true ignore_errors: true
changed_when: false changed_when: false
@ -13,11 +13,11 @@
when: oidc_plugin_check.rc != 0 when: oidc_plugin_check.rc != 0
#- name: "Upgrade Moodle to apply OIDC plugin" #- name: "Upgrade Moodle to apply OIDC plugin"
# command: "docker exec --user {{ bitnami_user }} {{ container_name }} php /opt/bitnami/moodle/admin/cli/upgrade.php --non-interactive" # command: "docker exec --user {{ bitnami_user }} {{ moodle_container }} php /opt/bitnami/moodle/admin/cli/upgrade.php --non-interactive"
# #
#- name: Clear Moodle cache #- name: Clear Moodle cache
# command: > # command: >
# docker exec --user {{ bitnami_user }} {{ container_name }} php /opt/bitnami/moodle/admin/cli/purge_caches.php # docker exec --user {{ bitnami_user }} {{ moodle_container }} php /opt/bitnami/moodle/admin/cli/purge_caches.php
- name: "Set Moodle OIDC configuration via CLI" - name: "Set Moodle OIDC configuration via CLI"
loop: loop:
@ -43,11 +43,11 @@
loop_control: loop_control:
label: "{{ item.name }}" label: "{{ item.name }}"
command: > command: >
docker exec --user {{ bitnami_user }} {{ container_name }} php /opt/bitnami/moodle/admin/cli/cfg.php --component=auth_oidc docker exec --user {{ bitnami_user }} {{ moodle_container }} php /opt/bitnami/moodle/admin/cli/cfg.php --component=auth_oidc
--name={{ item.name }} --set="{{ item.value }}" --name={{ item.name }} --set="{{ item.value }}"
- name: "Enable OIDC login" - name: "Enable OIDC login"
command: "docker exec --user {{ bitnami_user }} {{ container_name }} php /opt/bitnami/moodle/admin/cli/cfg.php --name=auth --set=oidc" command: "docker exec --user {{ bitnami_user }} {{ moodle_container }} php /opt/bitnami/moodle/admin/cli/cfg.php --name=auth --set=oidc"
- name: Set auth = 'oidc' for all users except guest - name: Set auth = 'oidc' for all users except guest
shell: > shell: >
@ -57,4 +57,4 @@
executable: /bin/bash executable: /bin/bash
#- name: Prevent Account Creation #- name: Prevent Account Creation
# command: docker exec --user {{ bitnami_user }} {{ container_name }} php /opt/bitnami/moodle/admin/cli/cfg.php --name=authpreventaccountcreation --set=1 # command: docker exec --user {{ bitnami_user }} {{ moodle_container }} php /opt/bitnami/moodle/admin/cli/cfg.php --name=authpreventaccountcreation --set=1

View File

@ -7,13 +7,13 @@
- "{{ bitnami_data_dir }}" - "{{ bitnami_data_dir }}"
block: block:
- name: Ensure ownership is correct - name: Ensure ownership is correct
command: "docker exec --user root {{ container_name }} chown -R {{ bitnami_user_group }} {{ item }}" command: "docker exec --user root {{ moodle_container }} chown -R {{ bitnami_user_group }} {{ item }}"
loop: "{{ moodle_dirs }}" loop: "{{ moodle_dirs }}"
- name: Set directory permissions (770) - name: Set directory permissions (770)
command: "docker exec --user root {{ container_name }} find {{ item }} -type d -exec chmod 770 {} \\;" command: "docker exec --user root {{ moodle_container }} find {{ item }} -type d -exec chmod 770 {} \\;"
loop: "{{ moodle_dirs }}" loop: "{{ moodle_dirs }}"
- name: Set file permissions (660) - name: Set file permissions (660)
command: "docker exec --user root {{ container_name }} find {{ item }} -type f -exec chmod 660 {} \\;" command: "docker exec --user root {{ moodle_container }} find {{ item }} -type f -exec chmod 660 {} \\;"
loop: "{{ moodle_dirs }}" loop: "{{ moodle_dirs }}"

View File

@ -2,7 +2,7 @@
moodle: moodle:
{% set container_port = 8080 %} {% set container_port = 8080 %}
container_name: {{ container_name }} moodle_container: {{ moodle_container }}
build: build:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile

View File

@ -13,6 +13,6 @@ docker_compose_flush_handlers: false # Wait for env update
moodle_config: "/bitnami/moodle/config.php" moodle_config: "/bitnami/moodle/config.php"
moodle_version: "{{ applications | get_app_conf(application_id, 'docker.services.moodle.version', True) }}" moodle_version: "{{ applications | get_app_conf(application_id, 'docker.services.moodle.version', True) }}"
moodle_image: "{{ applications | get_app_conf(application_id, 'docker.services.moodle.image', True) }}" moodle_image: "{{ applications | get_app_conf(application_id, 'docker.services.moodle.image', True) }}"
moodle_name: "{{ applications | get_app_conf(application_id, 'docker.services.moodle.name', True) }}" moodle_container: "{{ applications | get_app_conf(application_id, 'docker.services.moodle.name', True) }}"
moodle_volume: "{{ applications | get_app_conf(application_id, 'docker.volumes.data', True) }}" moodle_volume: "{{ applications | get_app_conf(application_id, 'docker.volumes.data', True) }}"
moodle_code: "{{ applications | get_app_conf(application_id, 'docker.volumes.code', True) }}" moodle_code: "{{ applications | get_app_conf(application_id, 'docker.volumes.code', True) }}"