mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-30 15:28:12 +02:00
Implemented draft for auto database credentials change moodle
This commit is contained in:
47
roles/web-app-moodle/tasks/database.yml
Normal file
47
roles/web-app-moodle/tasks/database.yml
Normal file
@@ -0,0 +1,47 @@
|
||||
- name: Check if config.php exists
|
||||
command: docker exec --user root {{ moodle_name }} 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: Copy config.php from container to host
|
||||
command: >
|
||||
docker cp {{ moodle_name }}:{{ moodle_config }} /opt/docker/moodle/_backup/config.php.bak
|
||||
|
||||
- name: Check if config.php exists
|
||||
command: docker exec --user root {{ moodle_name }} test -f {{ moodle_config }}
|
||||
register: config_file_exists
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Patch Moodle config.php with updated DB credentials
|
||||
when: config_file_exists.rc == 0
|
||||
block:
|
||||
- name: Update DB host
|
||||
command: >
|
||||
docker exec --user root {{ moodle_name }}
|
||||
sed -i "s/^\$CFG->dbhost *= *.*/\$CFG->dbhost = '{{ database_host }}';/" {{ moodle_config }}
|
||||
|
||||
- name: Update DB name
|
||||
command: >
|
||||
docker exec --user root {{ moodle_name }}
|
||||
sed -i "s/^\$CFG->dbname *= *.*/\$CFG->dbname = '{{ database_name }}';/" {{ moodle_config }}
|
||||
|
||||
- name: Update DB user
|
||||
command: >
|
||||
docker exec --user root {{ moodle_name }}
|
||||
sed -i "s/^\$CFG->dbuser *= *.*/\$CFG->dbuser = '{{ database_username }}';/" {{ moodle_config }}
|
||||
|
||||
- name: Update DB password
|
||||
command: >
|
||||
docker exec --user root {{ moodle_name }}
|
||||
sed -i "s/^\$CFG->dbpass *= *.*/\$CFG->dbpass = '{{ database_password }}';/" {{ moodle_config }}
|
@@ -3,6 +3,12 @@
|
||||
include_role:
|
||||
name: cmp-db-docker-proxy
|
||||
|
||||
- name: "Update database credentials"
|
||||
include_tasks: database.yml
|
||||
|
||||
- name: flush docker service
|
||||
meta: flush_handlers
|
||||
|
||||
- name: Wait until the Moodle container is healthy
|
||||
shell: docker inspect --format '{% raw %}{{.State.Health.Status}}{% endraw %}' {{ container_name }}
|
||||
register: health_check
|
||||
|
Reference in New Issue
Block a user