More ansible-lint fixes

This commit is contained in:
Slavi Pantaleev
2022-07-18 11:22:05 +03:00
parent 34cdaade08
commit ddf18eadc7
337 changed files with 1720 additions and 1720 deletions

View File

@ -78,7 +78,7 @@ matrix_postgres_import_roles_to_ignore: [matrix_postgres_connection_username]
# which is unsupported by default by newer Postgres versions (v14+).
# When users are created and passwords are set by the playbook, they end up hashed as `scram-sha-256` on Postgres v14+.
# If an md5-hashed password is restored on top, Postgres v14+ will refuse to authenticate users with it by default.
matrix_postgres_import_roles_ignore_regex: "^(CREATE|ALTER) ROLE ({{ matrix_postgres_import_roles_to_ignore|join('|') }})(;| WITH)"
matrix_postgres_import_roles_ignore_regex: "^(CREATE|ALTER) ROLE ({{ matrix_postgres_import_roles_to_ignore | join('|') }})(;| WITH)"
# A list of databases to avoid creating when importing (or upgrading) the database.
# If a dump file contains the databases and they've also been created beforehand (see `matrix_postgres_additional_databases`),
@ -86,7 +86,7 @@ matrix_postgres_import_roles_ignore_regex: "^(CREATE|ALTER) ROLE ({{ matrix_post
# We either need to not create them or to ignore the `CREATE DATABASE` statements in the dump.
matrix_postgres_import_databases_to_ignore: [matrix_postgres_db_name]
matrix_postgres_import_databases_ignore_regex: "^CREATE DATABASE ({{ matrix_postgres_import_databases_to_ignore|join('|') }})\\s"
matrix_postgres_import_databases_ignore_regex: "^CREATE DATABASE ({{ matrix_postgres_import_databases_to_ignore | join('|') }})\\s"
# The number of seconds to wait after starting `matrix-postgres.service`
# and before trying to run queries for creating additional databases/users against it.

View File

@ -5,7 +5,7 @@
- name: Fail if Postgres not enabled
ansible.builtin.fail:
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import."
when: "not matrix_postgres_enabled|bool"
when: "not matrix_postgres_enabled | bool"
- name: Fail if playbook called incorrectly
ansible.builtin.fail:
@ -13,7 +13,7 @@
when: "sqlite_database_path is not defined or sqlite_database_path.startswith('<')"
- name: Check if the provided SQLite database file exists
stat:
ansible.builtin.stat:
path: "{{ sqlite_database_path }}"
register: sqlite_database_path_stat_result
@ -48,7 +48,7 @@
- name: Set postgres_start_wait_time, if not provided
ansible.builtin.set_fact:
postgres_start_wait_time: 15
when: "postgres_start_wait_time|default('') == ''"
when: "postgres_start_wait_time | default('') == ''"
# Actual import work
@ -61,11 +61,11 @@
register: matrix_postgres_service_start_result
- name: Wait a bit, so that Postgres can start
wait_for:
ansible.builtin.wait_for:
timeout: "{{ postgres_start_wait_time }}"
delegate_to: 127.0.0.1
become: false
when: "matrix_postgres_service_start_result.changed|bool"
when: "matrix_postgres_service_start_result.changed | bool"
- name: Import SQLite database from {{ sqlite_database_path }} into Postgres
ansible.builtin.command:
@ -89,7 +89,7 @@
ansible.builtin.set_fact:
matrix_playbook_runtime_results: |
{{
matrix_playbook_runtime_results|default([])
matrix_playbook_runtime_results | default([])
+
[
"NOTE: Your SQLite database file has been imported into Postgres. The original file has been moved from `{{ sqlite_database_path }}` to `{{ sqlite_database_path }}.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete this file."

View File

@ -5,7 +5,7 @@
- name: Fail if Postgres not enabled
ansible.builtin.fail:
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import."
when: "not matrix_postgres_enabled|bool"
when: "not matrix_postgres_enabled | bool"
- name: Fail if playbook called incorrectly
ansible.builtin.fail:
@ -13,7 +13,7 @@
when: "server_path_postgres_dump is not defined or server_path_postgres_dump.startswith('<')"
- name: Check if the provided Postgres dump file exists
stat:
ansible.builtin.stat:
path: "{{ server_path_postgres_dump }}"
register: result_server_path_postgres_dump_stat
@ -28,19 +28,19 @@
- name: Set postgres_start_wait_time, if not provided
ansible.builtin.set_fact:
postgres_start_wait_time: 15
when: "postgres_start_wait_time|default('') == ''"
when: "postgres_start_wait_time | default('') == ''"
- name: Set postgres_import_wait_time, if not provided
ansible.builtin.set_fact:
postgres_import_wait_time: "{{ 7 * 86400 }}"
when: "postgres_import_wait_time|default('') == ''"
when: "postgres_import_wait_time | default('') == ''"
# By default, we connect and import into the main (`matrix`) database.
# Single-database dumps for Synapse may wish to import into `synapse` instead.
- name: Set postgres_default_import_database, if not provided
ansible.builtin.set_fact:
postgres_default_import_database: "{{ matrix_postgres_db_name }}"
when: "postgres_default_import_database|default('') == ''"
when: "postgres_default_import_database | default('') == ''"
# Actual import work
@ -51,17 +51,17 @@
daemon_reload: true
- name: Wait a bit, so that Postgres can start
wait_for:
ansible.builtin.wait_for:
timeout: "{{ postgres_start_wait_time }}"
delegate_to: 127.0.0.1
become: false
- import_tasks: tasks/util/detect_existing_postgres_version.yml
- ansible.builtin.import_tasks: tasks/util/detect_existing_postgres_version.yml
- name: Abort, if no existing Postgres version detected
ansible.builtin.fail:
msg: "Could not find existing Postgres installation"
when: "not matrix_postgres_detected_existing|bool"
when: "not matrix_postgres_detected_existing | bool"
# Starting the database container had automatically created the default
# role (`matrix_postgres_connection_username`) and database (`matrix_postgres_db_name`).
@ -76,10 +76,10 @@
--cap-drop=ALL
--network={{ matrix_docker_network }}
--env-file={{ matrix_postgres_base_path }}/env-postgres-psql
--mount type=bind,src={{ server_path_postgres_dump }},dst=/{{ server_path_postgres_dump|basename }},ro
--mount type=bind,src={{ server_path_postgres_dump }},dst=/{{ server_path_postgres_dump | basename }},ro
--entrypoint=/bin/sh
{{ matrix_postgres_docker_image_latest }}
-c "cat /{{ server_path_postgres_dump|basename }} |
-c "cat /{{ server_path_postgres_dump | basename }} |
{{ 'gunzip |' if server_path_postgres_dump.endswith('.gz') else '' }}
grep -vE '{{ matrix_postgres_import_roles_ignore_regex }}' |
grep -vE '{{ matrix_postgres_import_databases_ignore_regex }}' |

View File

@ -5,7 +5,7 @@
- name: Fail if Postgres not enabled
ansible.builtin.fail:
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import."
when: "not matrix_postgres_enabled|bool"
when: "not matrix_postgres_enabled | bool"
- name: Fail if playbook called incorrectly
ansible.builtin.fail:
@ -13,7 +13,7 @@
when: "server_path_homeserver_db is not defined or server_path_homeserver_db.startswith('<')"
- name: Check if the provided SQLite homeserver.db file exists
stat:
ansible.builtin.stat:
path: "{{ server_path_homeserver_db }}"
register: result_server_path_homeserver_db_stat
@ -28,7 +28,7 @@
- name: Set postgres_start_wait_time, if not provided
ansible.builtin.set_fact:
postgres_start_wait_time: 15
when: "postgres_start_wait_time|default('') == ''"
when: "postgres_start_wait_time | default('') == ''"
# Actual import work
@ -59,7 +59,7 @@
daemon_reload: true
- name: Wait a bit, so that Postgres can start
wait_for:
ansible.builtin.wait_for:
timeout: "{{ postgres_start_wait_time }}"
delegate_to: 127.0.0.1
become: false
@ -81,6 +81,6 @@
--entrypoint=python
--mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data
--mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/matrix-media-store-parent/media-store
--mount type=bind,src={{ server_path_homeserver_db }},dst=/{{ server_path_homeserver_db|basename }}
--mount type=bind,src={{ server_path_homeserver_db }},dst=/{{ server_path_homeserver_db | basename }}
{{ matrix_synapse_docker_image }}
/usr/local/bin/synapse_port_db --sqlite-database /{{ server_path_homeserver_db|basename }} --postgres-config /data/homeserver.yaml
/usr/local/bin/synapse_port_db --sqlite-database /{{ server_path_homeserver_db | basename }} --postgres-config /data/homeserver.yaml

View File

@ -2,4 +2,4 @@
- ansible.builtin.set_fact:
matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-postgres.service'] }}"
when: matrix_postgres_enabled|bool
when: matrix_postgres_enabled | bool

View File

@ -1,45 +1,45 @@
---
- import_tasks: "{{ role_path }}/tasks/init.yml"
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/init.yml"
tags:
- always
- import_tasks: "{{ role_path }}/tasks/validate_config.yml"
when: "run_setup|bool and matrix_postgres_enabled|bool"
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/validate_config.yml"
when: "run_setup | bool and matrix_postgres_enabled | bool"
tags:
- setup-all
- setup-postgres
- import_tasks: "{{ role_path }}/tasks/setup_postgres.yml"
when: run_setup|bool
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/setup_postgres.yml"
when: run_setup | bool
tags:
- setup-all
- setup-postgres
- import_tasks: "{{ role_path }}/tasks/import_postgres.yml"
when: run_postgres_import|bool
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/import_postgres.yml"
when: run_postgres_import | bool
tags:
- import-postgres
# The `run_postgres_import_sqlite_db` variable had better be renamed to be consistent,
# but that's a breaking change which may cause trouble for people.
- import_tasks: "{{ role_path }}/tasks/import_synapse_sqlite_db.yml"
when: run_postgres_import_sqlite_db|bool
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/import_synapse_sqlite_db.yml"
when: run_postgres_import_sqlite_db | bool
tags:
- import-synapse-sqlite-db
# Perhaps we need a new variable here, instead of `run_postgres_import_sqlite_db`.
- import_tasks: "{{ role_path }}/tasks/import_generic_sqlite_db.yml"
when: run_postgres_import_sqlite_db|bool
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/import_generic_sqlite_db.yml"
when: run_postgres_import_sqlite_db | bool
tags:
- import-generic-sqlite-db
- import_tasks: "{{ role_path }}/tasks/upgrade_postgres.yml"
when: run_postgres_upgrade|bool
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/upgrade_postgres.yml"
when: run_postgres_upgrade | bool
tags:
- upgrade-postgres
- import_tasks: "{{ role_path }}/tasks/run_vacuum.yml"
when: run_postgres_vacuum|bool
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/run_vacuum.yml"
when: run_postgres_vacuum | bool
tags:
- run-postgres-vacuum

View File

@ -11,7 +11,7 @@
# which still store it in the parent directory (`/matrix/postgres`).
- name: Check if old Postgres data directory is used
stat:
ansible.builtin.stat:
path: "{{ matrix_postgres_base_path }}/PG_VERSION"
register: result_pg_old_data_dir_stat
@ -33,7 +33,7 @@
when: "result_pg_old_data_dir_stat.stat.exists"
- name: Find files and directories in old Postgres data path
find:
ansible.builtin.find:
paths: "{{ matrix_postgres_base_path }}"
file_type: any
excludes: ["data"]
@ -51,7 +51,7 @@
- block:
- name: Relocate Postgres data files from old directory to new
ansible.builtin.command: "mv {{ item.path }} {{ matrix_postgres_data_path }}/{{ item.path|basename }}"
ansible.builtin.command: "mv {{ item.path }} {{ matrix_postgres_data_path }}/{{ item.path | basename }}"
with_items: "{{ result_pg_old_data_dir_find.files }}"
when: "result_pg_old_data_dir_stat.stat.exists"

View File

@ -5,7 +5,7 @@
- name: Fail if Postgres not enabled
ansible.builtin.fail:
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot run vacuum."
when: "not matrix_postgres_enabled|bool"
when: "not matrix_postgres_enabled | bool"
# Defaults
@ -13,12 +13,12 @@
- name: Set postgres_start_wait_time, if not provided
ansible.builtin.set_fact:
postgres_start_wait_time: 15
when: "postgres_start_wait_time|default('') == ''"
when: "postgres_start_wait_time | default('') == ''"
- name: Set postgres_vacuum_wait_time, if not provided
ansible.builtin.set_fact:
postgres_vacuum_wait_time: "{{ 7 * 86400 }}"
when: "postgres_vacuum_wait_time|default('') == ''"
when: "postgres_vacuum_wait_time | default('') == ''"
# Actual vacuuming work
@ -30,17 +30,17 @@
daemon_reload: true
- name: Wait a bit, so that Postgres can start
wait_for:
ansible.builtin.wait_for:
timeout: "{{ postgres_start_wait_time }}"
delegate_to: 127.0.0.1
become: false
- import_tasks: tasks/util/detect_existing_postgres_version.yml
- ansible.builtin.import_tasks: tasks/util/detect_existing_postgres_version.yml
- name: Abort, if no existing Postgres version detected
ansible.builtin.fail:
msg: "Could not find existing Postgres installation"
when: "not matrix_postgres_detected_existing|bool"
when: "not matrix_postgres_detected_existing | bool"
- name: Generate Postgres database vacuum command
ansible.builtin.set_fact:
@ -62,7 +62,7 @@
and manually run the above command directly on the server.
- name: Populate service facts
service_facts:
ansible.builtin.service_facts:
- ansible.builtin.set_fact:
matrix_postgres_synapse_was_running: "{{ ansible_facts.services['matrix-synapse.service']|default(none) is not none and ansible_facts.services['matrix-synapse.service'].state == 'running' }}"
@ -87,4 +87,4 @@
name: matrix-synapse
state: started
daemon_reload: true
when: "matrix_postgres_synapse_was_running|bool"
when: "matrix_postgres_synapse_was_running | bool"

View File

@ -4,11 +4,11 @@
# Tasks related to setting up an internal postgres server
#
- import_tasks: "{{ role_path }}/tasks/migrate_postgres_data_directory.yml"
when: matrix_postgres_enabled|bool
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/migrate_postgres_data_directory.yml"
when: matrix_postgres_enabled | bool
- import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml"
when: matrix_postgres_enabled|bool
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml"
when: matrix_postgres_enabled | bool
# If we have found an existing version (installed from before), we use its corresponding Docker image.
# If not, we install using the latest Postgres.
@ -16,24 +16,24 @@
# Upgrading is supposed to be performed separately and explicitly (see `upgrade_postgres.yml`).
- ansible.builtin.set_fact:
matrix_postgres_docker_image_to_use: "{{ matrix_postgres_docker_image_latest if matrix_postgres_detected_version_corresponding_docker_image == '' else matrix_postgres_detected_version_corresponding_docker_image }}"
when: matrix_postgres_enabled|bool
when: matrix_postgres_enabled | bool
- name: Abort if on an unsupported Postgres version
ansible.builtin.fail:
msg: "You're on Postgres {{ matrix_postgres_detected_version }}, which is no longer supported. To upgrade, see docs/maintenance-postgres.md"
when: "matrix_postgres_enabled|bool and matrix_postgres_detected_version.startswith('9.')"
when: "matrix_postgres_enabled | bool and matrix_postgres_detected_version.startswith('9.')"
- name: Inject warning if on an old version of Postgres
ansible.builtin.set_fact:
matrix_playbook_runtime_results: |
{{
matrix_playbook_runtime_results|default([])
matrix_playbook_runtime_results | default([])
+
[
"NOTE: Your setup is on an old Postgres version ({{ matrix_postgres_docker_image_to_use }}), while {{ matrix_postgres_docker_image_latest }} is supported. You can upgrade using --tags=upgrade-postgres"
]
}}
when: "matrix_postgres_enabled|bool and matrix_postgres_docker_image_to_use != matrix_postgres_docker_image_latest"
when: "matrix_postgres_enabled | bool and matrix_postgres_docker_image_to_use != matrix_postgres_docker_image_latest"
# Even if we don't run the internal server, we still need this for running the CLI
- name: Ensure postgres Docker image is pulled
@ -42,7 +42,7 @@
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
force_source: "{{ matrix_postgres_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_postgres_docker_image_force_pull }}"
when: matrix_postgres_enabled|bool
when: matrix_postgres_enabled | bool
register: result
retries: "{{ matrix_container_retries_count }}"
delay: "{{ matrix_container_retries_delay }}"
@ -58,7 +58,7 @@
with_items:
- "{{ matrix_postgres_base_path }}"
- "{{ matrix_postgres_data_path }}"
when: matrix_postgres_enabled|bool
when: matrix_postgres_enabled | bool
# We do this as a separate task, because:
# - we'd like to do it for the data path only, not for the base path (which contains root-owned environment variable files we'd like to leave as-is)
@ -70,7 +70,7 @@
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_groupname }}"
recurse: true
when: matrix_postgres_enabled|bool
when: matrix_postgres_enabled | bool
- name: Ensure Postgres environment variables file created
ansible.builtin.template:
@ -82,41 +82,41 @@
with_items:
- "env-postgres-psql"
- "env-postgres-server"
when: matrix_postgres_enabled|bool
when: matrix_postgres_enabled | bool
- name: Ensure matrix-postgres-cli script created
ansible.builtin.template:
src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-cli.j2"
dest: "{{ matrix_local_bin_path }}/matrix-postgres-cli"
mode: 0755
when: matrix_postgres_enabled|bool
when: matrix_postgres_enabled | bool
- name: Ensure matrix-postgres-cli-non-interactive script created
ansible.builtin.template:
src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-cli-non-interactive.j2"
dest: "{{ matrix_local_bin_path }}/matrix-postgres-cli-non-interactive"
mode: 0755
when: matrix_postgres_enabled|bool
when: matrix_postgres_enabled | bool
- name: Ensure matrix-change-user-admin-status script created
ansible.builtin.template:
src: "{{ role_path }}/templates/usr-local-bin/matrix-change-user-admin-status.j2"
dest: "{{ matrix_local_bin_path }}/matrix-change-user-admin-status"
mode: 0755
when: matrix_postgres_enabled|bool
when: matrix_postgres_enabled | bool
- name: (Migration) Ensure old matrix-make-user-admin script deleted
ansible.builtin.file:
path: "{{ matrix_local_bin_path }}/matrix-make-user-admin"
state: absent
when: matrix_postgres_enabled|bool
when: matrix_postgres_enabled | bool
- name: Ensure matrix-postgres-update-user-password-hash script created
ansible.builtin.template:
src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-update-user-password-hash.j2"
dest: "{{ matrix_local_bin_path }}/matrix-postgres-update-user-password-hash"
mode: 0755
when: matrix_postgres_enabled|bool
when: matrix_postgres_enabled | bool
- name: Ensure matrix-postgres.service installed
ansible.builtin.template:
@ -124,37 +124,37 @@
dest: "{{ matrix_systemd_path }}/matrix-postgres.service"
mode: 0644
register: matrix_postgres_systemd_service_result
when: matrix_postgres_enabled|bool
when: matrix_postgres_enabled | bool
- name: Ensure systemd reloaded after matrix-postgres.service installation
ansible.builtin.service:
daemon_reload: true
when: "matrix_postgres_enabled|bool and matrix_postgres_systemd_service_result.changed"
when: "matrix_postgres_enabled | bool and matrix_postgres_systemd_service_result.changed"
- include_tasks:
- ansible.builtin.include_tasks:
ansible.builtin.file: "{{ role_path }}/tasks/util/create_additional_databases.yml"
apply:
tags:
- always
when: "matrix_postgres_enabled|bool and matrix_postgres_additional_databases|length > 0"
when: "matrix_postgres_enabled | bool and matrix_postgres_additional_databases|length > 0"
- name: Check existence of matrix-postgres backup data path
stat:
ansible.builtin.stat:
path: "{{ matrix_postgres_data_path }}-auto-upgrade-backup"
register: matrix_postgres_data_backup_path_stat
when: "matrix_postgres_enabled|bool"
when: "matrix_postgres_enabled | bool"
- name: Inject warning if backup data remains
ansible.builtin.set_fact:
matrix_playbook_runtime_results: |
{{
matrix_playbook_runtime_results|default([])
matrix_playbook_runtime_results | default([])
+
[
"NOTE: You have some Postgres backup data in `{{ matrix_postgres_data_path }}-auto-upgrade-backup`, which was created during the last major Postgres update you ran. If your setup works well after this upgrade, feel free to delete this whole directory."
]
}}
when: "matrix_postgres_enabled|bool and matrix_postgres_data_backup_path_stat.stat.exists"
when: "matrix_postgres_enabled | bool and matrix_postgres_data_backup_path_stat.stat.exists"
#
@ -162,47 +162,47 @@
#
- name: Check existence of matrix-postgres service
stat:
ansible.builtin.stat:
path: "{{ matrix_systemd_path }}/matrix-postgres.service"
register: matrix_postgres_service_stat
when: "not matrix_postgres_enabled|bool"
when: "not matrix_postgres_enabled | bool"
- name: Ensure matrix-postgres is stopped
ansible.builtin.service:
name: matrix-postgres
state: stopped
daemon_reload: true
when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
when: "not matrix_postgres_enabled | bool and matrix_postgres_service_stat.stat.exists"
- name: Ensure matrix-postgres.service doesn't exist
ansible.builtin.file:
path: "{{ matrix_systemd_path }}/matrix-postgres.service"
state: absent
when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
when: "not matrix_postgres_enabled | bool and matrix_postgres_service_stat.stat.exists"
- name: Ensure systemd reloaded after matrix-postgres.service removal
ansible.builtin.service:
daemon_reload: true
when: "not matrix_postgres_enabled|bool and matrix_postgres_service_stat.stat.exists"
when: "not matrix_postgres_enabled | bool and matrix_postgres_service_stat.stat.exists"
- name: Check existence of matrix-postgres local data path
stat:
ansible.builtin.stat:
path: "{{ matrix_postgres_data_path }}"
register: matrix_postgres_data_path_stat
when: "not matrix_postgres_enabled|bool"
when: "not matrix_postgres_enabled | bool"
# We just want to notify the user. Deleting data is too destructive.
- name: Inject warning if matrix-postgres local data remains
ansible.builtin.set_fact:
matrix_playbook_runtime_results: |
{{
matrix_playbook_runtime_results|default([])
matrix_playbook_runtime_results | default([])
+
[
"NOTE: You are not using a local PostgreSQL database, but some old data remains from before in `{{ matrix_postgres_data_path }}`. Feel free to delete it."
]
}}
when: "not matrix_postgres_enabled|bool and matrix_postgres_data_path_stat.stat.exists"
when: "not matrix_postgres_enabled | bool and matrix_postgres_data_path_stat.stat.exists"
- name: Remove Postgres scripts
ansible.builtin.file:
@ -212,4 +212,4 @@
- matrix-postgres-cli
- matrix-change-user-admin-status
- matrix-postgres-update-user-password-hash
when: "not matrix_postgres_enabled|bool"
when: "not matrix_postgres_enabled | bool"

View File

@ -3,35 +3,35 @@
- name: Set default postgres_dump_dir, if not provided
ansible.builtin.set_fact:
postgres_dump_dir: "/tmp"
when: "postgres_dump_dir|default('') == ''"
when: "postgres_dump_dir | default('') == ''"
- name: Set postgres_dump_name, if not provided
ansible.builtin.set_fact:
postgres_dump_name: "matrix-postgres-dump.sql.gz"
when: "postgres_dump_name|default('') == ''"
when: "postgres_dump_name | default('') == ''"
- name: Set postgres_auto_upgrade_backup_data_path, if not provided
ansible.builtin.set_fact:
postgres_auto_upgrade_backup_data_path: "{{ matrix_postgres_data_path }}-auto-upgrade-backup"
when: "postgres_auto_upgrade_backup_data_path|default('') == ''"
when: "postgres_auto_upgrade_backup_data_path | default('') == ''"
- name: Set postgres_start_wait_time, if not provided
ansible.builtin.set_fact:
postgres_start_wait_time: 15
when: "postgres_start_wait_time|default('') == ''"
when: "postgres_start_wait_time | default('') == ''"
- name: Set postgres_force_upgrade, if not provided
ansible.builtin.set_fact:
postgres_force_upgrade: false
when: "postgres_force_upgrade|default('') == ''"
when: "postgres_force_upgrade | default('') == ''"
- name: Fail, if trying to upgrade external Postgres database
ansible.builtin.fail:
msg: "Your configuration indicates that you're not using Postgres from this role. There is nothing to upgrade."
when: "not matrix_postgres_enabled|bool"
when: "not matrix_postgres_enabled | bool"
- name: Check Postgres auto-upgrade backup data directory
stat:
ansible.builtin.stat:
path: "{{ postgres_auto_upgrade_backup_data_path }}"
register: result_auto_upgrade_path
@ -40,12 +40,12 @@
msg: "Detected that a left-over {{ postgres_auto_upgrade_backup_data_path }} exists. You should rename it to {{ matrix_postgres_data_path }} if the previous upgrade went wrong, or delete it if it went well."
when: "result_auto_upgrade_path.stat.exists"
- import_tasks: tasks/util/detect_existing_postgres_version.yml
- ansible.builtin.import_tasks: tasks/util/detect_existing_postgres_version.yml
- name: Abort, if no existing Postgres version detected
ansible.builtin.fail:
msg: "Could not find existing Postgres installation"
when: "not matrix_postgres_detected_existing|bool"
when: "not matrix_postgres_detected_existing | bool"
- name: Abort, if already at latest Postgres version
ansible.builtin.fail:
@ -67,7 +67,7 @@
daemon_reload: true
- name: Wait a bit, so that Postgres can start
wait_for:
ansible.builtin.wait_for:
timeout: "{{ postgres_start_wait_time }}"
delegate_to: 127.0.0.1
become: false
@ -102,7 +102,7 @@
- ansible.builtin.debug:
msg: "NOTE: Your Postgres data directory has been moved from `{{ matrix_postgres_data_path }}` to `{{ postgres_auto_upgrade_backup_data_path }}`. In the event of failure, you can move it back and run the playbook with --tags=setup-postgres to restore operation."
- import_tasks: tasks/setup_postgres.yml
- ansible.builtin.import_tasks: tasks/setup_postgres.yml
- name: Ensure matrix-postgres autoruns and is restarted
ansible.builtin.service:
@ -112,7 +112,7 @@
daemon_reload: true
- name: Wait a bit, so that Postgres can start
wait_for:
ansible.builtin.wait_for:
timeout: "{{ postgres_start_wait_time }}"
delegate_to: 127.0.0.1
become: false

View File

@ -8,14 +8,14 @@
register: matrix_postgres_service_start_result
- name: Wait a bit, so that Postgres can start
wait_for:
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"
when: "matrix_postgres_service_start_result.changed | bool"
- name: Create additional Postgres user and database
include_tasks: "{{ role_path }}/tasks/util/create_additional_database.yml"
ansible.builtin.include_tasks: "{{ role_path }}/tasks/util/create_additional_database.yml"
with_items: "{{ matrix_postgres_additional_databases }}"
loop_control:
loop_var: additional_db

View File

@ -11,7 +11,7 @@
matrix_postgres_detected_version_corresponding_docker_image: ""
- name: Determine existing Postgres version (check PG_VERSION file)
stat:
ansible.builtin.stat:
path: "{{ matrix_postgres_detection_pg_version_path }}"
register: result_pg_version_stat
@ -23,12 +23,12 @@
ansible.builtin.slurp:
src: "{{ matrix_postgres_detection_pg_version_path }}"
register: result_pg_version
when: matrix_postgres_detected_existing|bool
when: matrix_postgres_detected_existing | bool
- name: Determine existing Postgres version (make sense of PG_VERSION file)
ansible.builtin.set_fact:
matrix_postgres_detected_version: "{{ result_pg_version['content']|b64decode|replace('\n', '') }}"
when: matrix_postgres_detected_existing|bool
when: matrix_postgres_detected_existing | bool
- name: Determine corresponding Docker image to detected version (assume default of latest)
ansible.builtin.set_fact:

View File

@ -3,7 +3,7 @@
- name: Fail if Postgres not enabled
ansible.builtin.fail:
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot migrate."
when: "not matrix_postgres_enabled|bool"
when: "not matrix_postgres_enabled | bool"
- name: Fail if util called incorrectly (missing matrix_postgres_db_migration_request)
ansible.builtin.fail:
@ -22,7 +22,7 @@
when: "item not in matrix_postgres_db_migration_request"
- name: Check if the provided source database file exists
stat:
ansible.builtin.stat:
path: "{{ matrix_postgres_db_migration_request.src }}"
register: matrix_postgres_db_migration_request_src_stat_result
@ -69,7 +69,7 @@
dockerfile: Dockerfile
path: "{{ matrix_postgres_pgloader_container_image_self_build_src_path }}"
pull: true
when: "matrix_postgres_pgloader_container_image_self_build|bool"
when: "matrix_postgres_pgloader_container_image_self_build | bool"
- name: Ensure pgloader Docker image is pulled
docker_image:
@ -84,7 +84,7 @@
- name: Set postgres_start_wait_time, if not provided
ansible.builtin.set_fact:
postgres_start_wait_time: 15
when: "postgres_start_wait_time|default('') == ''"
when: "postgres_start_wait_time | default('') == ''"
# Actual import work
@ -97,11 +97,11 @@
register: matrix_postgres_service_start_result
- name: Wait a bit, so that Postgres can start
wait_for:
ansible.builtin.wait_for:
timeout: "{{ postgres_start_wait_time }}"
delegate_to: 127.0.0.1
become: false
when: "matrix_postgres_service_start_result.changed|bool"
when: "matrix_postgres_service_start_result.changed | bool"
# We only stop services here, leaving it to the caller to start them later.
#
@ -130,12 +130,12 @@
--entrypoint=/bin/sh
{{ matrix_postgres_pgloader_docker_image }}
-c
'pgloader {{ matrix_postgres_db_migration_request.pgloader_options|default([])|join(' ') }} /in.db {{ matrix_postgres_db_migration_request.dst }}'
'pgloader {{ matrix_postgres_db_migration_request.pgloader_options | default([]) | join(' ') }} /in.db {{ matrix_postgres_db_migration_request.dst }}'
- block:
# We can't use `{{ role_path }}` here, neither with `import_tasks`, nor with `include_tasks`,
# because it refers to the role that included this util, and not to the role this file belongs to.
- import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/detect_existing_postgres_version.yml"
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/detect_existing_postgres_version.yml"
- ansible.builtin.set_fact:
matrix_postgres_docker_image_to_use: "{{ matrix_postgres_docker_image_latest if matrix_postgres_detected_version_corresponding_docker_image == '' else matrix_postgres_detected_version_corresponding_docker_image }}"
@ -153,7 +153,7 @@
psql --host=matrix-postgres --dbname={{ matrix_postgres_db_migration_request.additional_psql_statements_db_name }} --command='{{ item }}'
with_items: "{{ matrix_postgres_db_migration_request.additional_psql_statements_list }}"
when: "matrix_postgres_db_migration_request.additional_psql_statements_list|default([])|length > 0"
when: "matrix_postgres_db_migration_request.additional_psql_statements_list | default([])|length > 0"
- name: Archive {{ matrix_postgres_db_migration_request.engine_old }} database ({{ matrix_postgres_db_migration_request.src }} -> {{ matrix_postgres_db_migration_request.src }}.backup)
ansible.builtin.command:
@ -163,7 +163,7 @@
ansible.builtin.set_fact:
matrix_playbook_runtime_results: |
{{
matrix_playbook_runtime_results|default([])
matrix_playbook_runtime_results | default([])
+
[
"NOTE: Your {{ matrix_postgres_db_migration_request.engine_old }} database file has been imported into Postgres. The original database file has been moved from `{{ matrix_postgres_db_migration_request.src }}` to `{{ matrix_postgres_db_migration_request.src }}.backup`. When you've confirmed that the import went well and everything works, you should be able to safely delete this file."