49 lines
1.8 KiB
YAML

- name: Check if config.php exists
command: docker exec --user root {{ moodle_container }} test -f {{ moodle_config }}
register: config_file_exists
changed_when: false
failed_when: false
- name: Backup config.php to host
when: config_file_exists.rc == 0
block:
- name: Create backup directory on host
ansible.builtin.file:
path: "/opt/docker/moodle/_backup"
state: directory
mode: "0755"
- name: Check if config.php exists
command: docker exec --user root {{ moodle_container }} test -f {{ moodle_config }}
register: config_file_exists
changed_when: false
failed_when: false
- name: Patch Moodle config.php with updated DB and wwwroot credentials
when: config_file_exists.rc == 0
block:
- name: Update DB host
command: >
docker exec --user root {{ moodle_container }}
sed -i "s/^\$CFG->dbhost *= *.*/\$CFG->dbhost = '{{ database_host }}';/" {{ moodle_config }}
- name: Update DB name
command: >
docker exec --user root {{ moodle_container }}
sed -i "s/^\$CFG->dbname *= *.*/\$CFG->dbname = '{{ database_name }}';/" {{ moodle_config }}
- name: Update DB user
command: >
docker exec --user root {{ moodle_container }}
sed -i "s/^\$CFG->dbuser *= *.*/\$CFG->dbuser = '{{ database_username }}';/" {{ moodle_config }}
- name: Update DB password
command: >
docker exec --user root {{ moodle_container }}
sed -i "s/^\$CFG->dbpass *= *.*/\$CFG->dbpass = '{{ database_password }}';/" {{ moodle_config }}
- name: Update CFG->wwwroot via sed in container
command: >
docker exec --user root {{ moodle_container }}
sed -i -E "s|^(\$CFG->wwwroot[[:space:]]*=[[:space:]]*).*$|\1'{{ domains | get_url(application_id, WEB_PROTOCOL) }}';|" {{ moodle_config }}