Import tasks from other roles in a better way

One that doesn't trip up ansible-lint, causing `load-failure` errors.
This commit is contained in:
Slavi Pantaleev 2022-07-18 16:15:04 +03:00
parent 3408c710ee
commit 7831dc91b3
28 changed files with 79 additions and 30 deletions

View file

@ -1,6 +1,9 @@
--- ---
- block: - block:
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/detect_existing_postgres_version.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: detect_existing_postgres_version
- name: Fail if detected Postgres version is unsupported - name: Fail if detected Postgres version is unsupported
ansible.builtin.fail: ansible.builtin.fail:

View file

@ -18,7 +18,9 @@
engine_old: 'sqlite' engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-bot-buscarron.service'] systemd_services_to_stop: ['matrix-bot-buscarron.service']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_bot_buscarron_requires_restart: true matrix_bot_buscarron_requires_restart: true

View file

@ -18,7 +18,9 @@
engine_old: 'sqlite' engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-bot-honoroit.service'] systemd_services_to_stop: ['matrix-bot-honoroit.service']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_bot_honoroit_requires_restart: true matrix_bot_honoroit_requires_restart: true

View file

@ -19,7 +19,9 @@
engine_old: 'sqlite' engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-bot-matrix-reminder-bot.service'] systemd_services_to_stop: ['matrix-bot-matrix-reminder-bot.service']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_bot_matrix_reminder_bot_requires_restart: true matrix_bot_matrix_reminder_bot_requires_restart: true

View file

@ -19,7 +19,9 @@
engine_old: 'sqlite' engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-appservice-discord.service'] systemd_services_to_stop: ['matrix-appservice-discord.service']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_appservice_discord_requires_restart: true matrix_appservice_discord_requires_restart: true

View file

@ -28,7 +28,9 @@
systemd_services_to_stop: ['matrix-go-skype-bridge.service'] systemd_services_to_stop: ['matrix-go-skype-bridge.service']
pgloader_options: ['--with "quote identifiers"'] pgloader_options: ['--with "quote identifiers"']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_go_skype_bridge_requires_restart: true matrix_go_skype_bridge_requires_restart: true

View file

@ -27,7 +27,9 @@
engine_old: 'sqlite' engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-mautrix-facebook.service'] systemd_services_to_stop: ['matrix-mautrix-facebook.service']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_mautrix_facebook_requires_restart: true matrix_mautrix_facebook_requires_restart: true

View file

@ -27,7 +27,9 @@
engine_old: 'sqlite' engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-mautrix-googlechat.service'] systemd_services_to_stop: ['matrix-mautrix-googlechat.service']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_mautrix_googlechat_requires_restart: true matrix_mautrix_googlechat_requires_restart: true

View file

@ -27,7 +27,9 @@
engine_old: 'sqlite' engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-mautrix-hangouts.service'] systemd_services_to_stop: ['matrix-mautrix-hangouts.service']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_mautrix_hangouts_requires_restart: true matrix_mautrix_hangouts_requires_restart: true

View file

@ -27,7 +27,9 @@
engine_old: 'sqlite' engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-mautrix-telegram.service'] systemd_services_to_stop: ['matrix-mautrix-telegram.service']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_mautrix_telegram_requires_restart: true matrix_mautrix_telegram_requires_restart: true

View file

@ -28,7 +28,9 @@
systemd_services_to_stop: ['matrix-mautrix-whatsapp.service'] systemd_services_to_stop: ['matrix-mautrix-whatsapp.service']
pgloader_options: ['--with "quote identifiers"'] pgloader_options: ['--with "quote identifiers"']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_mautrix_whatsapp_requires_restart: true matrix_mautrix_whatsapp_requires_restart: true

View file

@ -61,7 +61,9 @@
engine_old: 'sqlite' engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-mx-puppet-discord.service'] systemd_services_to_stop: ['matrix-mx-puppet-discord.service']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_mx_puppet_discord_requires_restart: true matrix_mx_puppet_discord_requires_restart: true

View file

@ -59,7 +59,9 @@
engine_old: 'sqlite' engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-mx-puppet-groupme.service'] systemd_services_to_stop: ['matrix-mx-puppet-groupme.service']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_mx_puppet_groupme_requires_restart: true matrix_mx_puppet_groupme_requires_restart: true

View file

@ -28,7 +28,9 @@
engine_old: 'sqlite' engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-mx-puppet-instagram.service'] systemd_services_to_stop: ['matrix-mx-puppet-instagram.service']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_mx_puppet_instagram_requires_restart: true matrix_mx_puppet_instagram_requires_restart: true

View file

@ -55,7 +55,9 @@
engine_old: 'sqlite' engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-mx-puppet-slack.service'] systemd_services_to_stop: ['matrix-mx-puppet-slack.service']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_mx_puppet_slack_requires_restart: true matrix_mx_puppet_slack_requires_restart: true

View file

@ -59,7 +59,9 @@
engine_old: 'sqlite' engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-mx-puppet-steam.service'] systemd_services_to_stop: ['matrix-mx-puppet-steam.service']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_mx_puppet_steam_requires_restart: true matrix_mx_puppet_steam_requires_restart: true

View file

@ -59,7 +59,9 @@
engine_old: 'sqlite' engine_old: 'sqlite'
systemd_services_to_stop: ['matrix-mx-puppet-twitter.service'] systemd_services_to_stop: ['matrix-mx-puppet-twitter.service']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_mx_puppet_twitter_requires_restart: true matrix_mx_puppet_twitter_requires_restart: true

View file

@ -61,7 +61,9 @@
additional_psql_statements_list: "{{ matrix_dimension_pgloader_additional_psql_statements_list }}" additional_psql_statements_list: "{{ matrix_dimension_pgloader_additional_psql_statements_list }}"
additional_psql_statements_db_name: "{{ matrix_dimension_database_name }}" additional_psql_statements_db_name: "{{ matrix_dimension_database_name }}"
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_dimension_requires_restart: true matrix_dimension_requires_restart: true

View file

@ -38,7 +38,9 @@
systemd_services_to_stop: ['matrix-ma1sd.service'] systemd_services_to_stop: ['matrix-ma1sd.service']
pgloader_options: ['--with "quote identifiers"'] pgloader_options: ['--with "quote identifiers"']
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_ma1sd_requires_restart: true matrix_ma1sd_requires_restart: true

View file

@ -1,9 +1,11 @@
--- ---
# #
# Tasks related to setting up an internal postgres server # Tasks related to setting up postgres backup
# #
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: detect_existing_postgres_version
when: 'matrix_postgres_backup_enabled | bool and matrix_postgres_backup_postgres_data_path != ""' when: 'matrix_postgres_backup_enabled | bool and matrix_postgres_backup_postgres_data_path != ""'
# If we have found an existing version (installed from before), we use its corresponding Docker image. # If we have found an existing version (installed from before), we use its corresponding Docker image.
@ -62,7 +64,7 @@
when: "matrix_postgres_backup_enabled | bool and matrix_postgres_backup_systemd_service_result.changed" when: "matrix_postgres_backup_enabled | bool and matrix_postgres_backup_systemd_service_result.changed"
# #
# Tasks related to getting rid of the internal postgres backup server (if it was previously enabled) # Tasks related to getting rid of postgres backup (if it was previously enabled)
# #
- name: Check existence of matrix-postgres-backup service - name: Check existence of matrix-postgres-backup service

View file

@ -2,6 +2,9 @@
# This utility aims to determine if there is some existing Postgres version in use or not. # This utility aims to determine if there is some existing Postgres version in use or not.
# If there is, it also tries to detect the Docker image that corresponds to that version. # If there is, it also tries to detect the Docker image that corresponds to that version.
#
# This utility is intentionally not in `tasks/util`, because if it were, it wouldn't be possible
# to include it in other roles via the import_role module: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_role_module.html
- name: Initialize Postgres version determination variables (default to empty) - name: Initialize Postgres version determination variables (default to empty)
ansible.builtin.set_fact: ansible.builtin.set_fact:

View file

@ -56,7 +56,7 @@
delegate_to: 127.0.0.1 delegate_to: 127.0.0.1
become: false become: false
- ansible.builtin.import_tasks: tasks/util/detect_existing_postgres_version.yml - ansible.builtin.import_tasks: tasks/detect_existing_postgres_version.yml
- name: Abort, if no existing Postgres version detected - name: Abort, if no existing Postgres version detected
ansible.builtin.fail: ansible.builtin.fail:

View file

@ -135,9 +135,9 @@
changed_when: matrix_postgres_migrate_db_to_postgres_import_result.rc == 0 changed_when: matrix_postgres_migrate_db_to_postgres_import_result.rc == 0
- block: - block:
# We can't use `{{ role_path }}` here, neither with `import_tasks`, nor with `include_tasks`, - ansible.builtin.import_role:
# because it refers to the role that included this util, and not to the role this file belongs to. name: matrix-postgres
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/detect_existing_postgres_version.yml" tasks_from: detect_existing_postgres_version
- ansible.builtin.set_fact: - 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 }}" 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 }}"

View file

@ -9,6 +9,9 @@
# #
# For this reason, we store the Postgres data in `/matrix/postgres/data` and need to relocate any installations # For this reason, we store the Postgres data in `/matrix/postgres/data` and need to relocate any installations
# which still store it in the parent directory (`/matrix/postgres`). # which still store it in the parent directory (`/matrix/postgres`).
#
# This utility is intentionally not in `tasks/util`, because if it were, it wouldn't be possible
# to include it in other roles via the import_role module: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/import_role_module.html
- name: Check if old Postgres data directory is used - name: Check if old Postgres data directory is used
ansible.builtin.stat: ansible.builtin.stat:

View file

@ -35,7 +35,7 @@
delegate_to: 127.0.0.1 delegate_to: 127.0.0.1
become: false become: false
- ansible.builtin.import_tasks: tasks/util/detect_existing_postgres_version.yml - ansible.builtin.import_tasks: tasks/detect_existing_postgres_version.yml
- name: Abort, if no existing Postgres version detected - name: Abort, if no existing Postgres version detected
ansible.builtin.fail: ansible.builtin.fail:

View file

@ -7,7 +7,7 @@
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/migrate_postgres_data_directory.yml" - ansible.builtin.import_tasks: "{{ role_path }}/tasks/migrate_postgres_data_directory.yml"
when: matrix_postgres_enabled | bool when: matrix_postgres_enabled | bool
- ansible.builtin.import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml" - ansible.builtin.import_tasks: "{{ role_path }}/tasks/detect_existing_postgres_version.yml"
when: matrix_postgres_enabled | bool when: matrix_postgres_enabled | bool
# If we have found an existing version (installed from before), we use its corresponding Docker image. # If we have found an existing version (installed from before), we use its corresponding Docker image.

View file

@ -40,7 +40,7 @@
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." 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" when: "result_auto_upgrade_path.stat.exists"
- ansible.builtin.import_tasks: tasks/util/detect_existing_postgres_version.yml - ansible.builtin.import_tasks: tasks/detect_existing_postgres_version.yml
- name: Abort, if no existing Postgres version detected - name: Abort, if no existing Postgres version detected
ansible.builtin.fail: ansible.builtin.fail:

View file

@ -24,7 +24,9 @@
- ALTER TABLE tokens ALTER COLUMN ex_date TYPE TIMESTAMP WITHOUT TIME ZONE; - ALTER TABLE tokens ALTER COLUMN ex_date TYPE TIMESTAMP WITHOUT TIME ZONE;
additional_psql_statements_db_name: "{{ matrix_registration_database_name }}" additional_psql_statements_db_name: "{{ matrix_registration_database_name }}"
- ansible.builtin.import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" - ansible.builtin.import_role:
name: matrix-postgres
tasks_from: migrate_db_to_postgres
- ansible.builtin.set_fact: - ansible.builtin.set_fact:
matrix_registration_requires_restart: true matrix_registration_requires_restart: true