Move roles/matrix* to roles/custom/matrix*
This paves the way for installing other roles into `roles/galaxy` using `ansible-galaxy`, similar to how it's done in: - https://github.com/spantaleev/gitea-docker-ansible-deploy - https://github.com/spantaleev/nextcloud-docker-ansible-deploy In the near future, we'll be removing a lot of the shared role code from here and using upstream roles for it. Some of the core `matrix-*` roles have already been extracted out into other reusable roles: - https://github.com/devture/com.devture.ansible.role.postgres - https://github.com/devture/com.devture.ansible.role.systemd_docker_base - https://github.com/devture/com.devture.ansible.role.timesync - https://github.com/devture/com.devture.ansible.role.vars_preserver - https://github.com/devture/com.devture.ansible.role.playbook_runtime_messages - https://github.com/devture/com.devture.ansible.role.playbook_help We just need to migrate to those.
This commit is contained in:
@ -0,0 +1,41 @@
|
||||
---
|
||||
|
||||
# It'd be better if this is belonged to `validate_config.yml`, but it would have to be some loop-within-a-loop there,
|
||||
# and that's ugly. We also don't expect this to catch errors often. It's more of a defensive last-minute check.
|
||||
- name: Fail if additional database data appears invalid
|
||||
ansible.builtin.fail:
|
||||
msg: "Additional database definition ({{ additional_db }} lacks a required key: {{ item }}"
|
||||
when: "item not in additional_db"
|
||||
with_items: "{{ ['name', 'username', 'password'] }}"
|
||||
|
||||
# The SQL statements that we'll run against Postgres are stored in a file that others can't read.
|
||||
# This file will be mounted into the container and fed to Postgres.
|
||||
# This way, we avoid passing sensitive data around in CLI commands that other users on the system can see.
|
||||
- name: Create additional database initialization SQL file for {{ additional_db.name }}
|
||||
ansible.builtin.template:
|
||||
src: "{{ role_path }}/templates/sql/init-additional-db-user-and-role.sql.j2"
|
||||
dest: "/tmp/matrix-postgres-init-additional-db-user-and-role.sql"
|
||||
mode: 0600
|
||||
owner: "{{ matrix_user_uid }}"
|
||||
group: "{{ matrix_user_gid }}"
|
||||
|
||||
- name: Execute Postgres additional database initialization SQL file for {{ additional_db.name }}
|
||||
ansible.builtin.command:
|
||||
cmd: >-
|
||||
{{ matrix_host_command_docker }} run
|
||||
--rm
|
||||
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
|
||||
--cap-drop=ALL
|
||||
--env-file={{ matrix_postgres_base_path }}/env-postgres-psql
|
||||
--network {{ matrix_docker_network }}
|
||||
--mount type=bind,src=/tmp/matrix-postgres-init-additional-db-user-and-role.sql,dst=/matrix-postgres-init-additional-db-user-and-role.sql,ro
|
||||
--entrypoint=/bin/sh
|
||||
{{ matrix_postgres_docker_image_to_use }}
|
||||
-c
|
||||
'psql -h {{ matrix_postgres_connection_hostname }} --file=/matrix-postgres-init-additional-db-user-and-role.sql'
|
||||
changed_when: true
|
||||
|
||||
- name: Delete additional database initialization SQL file for {{ additional_db.name }}
|
||||
ansible.builtin.file:
|
||||
path: /tmp/matrix-postgres-init-additional-db-user-and-role.sql
|
||||
state: absent
|
@ -0,0 +1,23 @@
|
||||
---
|
||||
|
||||
- name: Ensure matrix-postgres is started
|
||||
ansible.builtin.service:
|
||||
name: matrix-postgres
|
||||
state: started
|
||||
daemon_reload: true
|
||||
register: matrix_postgres_service_start_result
|
||||
|
||||
- name: Wait a bit, so that Postgres can start
|
||||
ansible.builtin.wait_for:
|
||||
timeout: "{{ matrix_postgres_additional_databases_postgres_start_wait_timeout_seconds }}"
|
||||
delegate_to: 127.0.0.1
|
||||
become: false
|
||||
when: "matrix_postgres_service_start_result.changed | bool"
|
||||
|
||||
- name: Create additional Postgres user and database
|
||||
ansible.builtin.include_tasks: "{{ role_path }}/tasks/util/create_additional_database.yml"
|
||||
with_items: "{{ matrix_postgres_additional_databases }}"
|
||||
loop_control:
|
||||
loop_var: additional_db
|
||||
# Suppress logging to avoid dumping the credentials to the shell
|
||||
no_log: true
|
Reference in New Issue
Block a user