Fix CONDITIONAL_BARE_VARS deprecation warning in ansible 2.8

This commit is contained in:
Dan Arnfield
2019-05-21 10:25:59 -05:00
parent affb99003c
commit 3982f114af
61 changed files with 224 additions and 226 deletions

View File

@ -5,7 +5,7 @@
- name: Fail if Postgres not enabled
fail:
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import."
when: "not matrix_postgres_enabled"
when: "not matrix_postgres_enabled|bool"
- name: Fail if playbook called incorrectly
fail:
@ -20,7 +20,7 @@
- name: Fail if provided Postgres dump file doesn't exists
fail:
msg: "File cannot be found on the server at {{ server_path_postgres_dump }}"
when: not result_server_path_postgres_dump_stat.stat.exists
when: "not result_server_path_postgres_dump_stat.stat.exists"
# Defaults
@ -54,7 +54,7 @@
- name: Abort, if no existing Postgres version detected
fail:
msg: "Could not find existing Postgres installation"
when: "not matrix_postgres_detected_existing"
when: "not matrix_postgres_detected_existing|bool"
- name: Generate Postgres database import command
set_fact:

View File

@ -5,7 +5,7 @@
- name: Fail if Postgres not enabled
fail:
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import."
when: "not matrix_postgres_enabled"
when: "not matrix_postgres_enabled|bool"
- name: Fail if playbook called incorrectly
fail:
@ -20,7 +20,7 @@
- name: Fail if provided SQLite homeserver.db file doesn't exist
fail:
msg: "File cannot be found on the server at {{ server_path_homeserver_db }}"
when: not result_server_path_homeserver_db_stat.stat.exists
when: "not result_server_path_homeserver_db_stat.stat.exists"
# Defaults

View File

@ -1,3 +1,3 @@
- set_fact:
matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-postgres'] }}"
when: matrix_postgres_enabled
when: matrix_postgres_enabled|bool

View File

@ -3,28 +3,28 @@
- always
- import_tasks: "{{ role_path }}/tasks/validate_config.yml"
when: "run_setup and matrix_postgres_enabled"
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
when: run_setup|bool
tags:
- setup-all
- setup-postgres
- import_tasks: "{{ role_path }}/tasks/import_postgres.yml"
when: run_import_postgres
when: run_import_postgres|bool
tags:
- import-postgres
- import_tasks: "{{ role_path }}/tasks/import_sqlite_db.yml"
when: run_import_sqlite_db
when: run_import_sqlite_db|bool
tags:
- import-sqlite-db
- import_tasks: "{{ role_path }}/tasks/upgrade_postgres.yml"
when: run_upgrade_postgres
when: run_upgrade_postgres|bool
tags:
- upgrade-postgres

View File

@ -5,10 +5,10 @@
#
- import_tasks: "{{ role_path }}/tasks/migrate_postgres_data_directory.yml"
when: matrix_postgres_enabled
when: matrix_postgres_enabled|bool
- import_tasks: "{{ role_path }}/tasks/util/detect_existing_postgres_version.yml"
when: matrix_postgres_enabled
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,18 +16,18 @@
# Upgrading is supposed to be performed separately and explicitly (see `upgrade_postgres.yml`).
- 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
when: matrix_postgres_enabled|bool
- name: Warn if on an old version of Postgres
debug:
msg: "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 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
docker_image:
name: "{{ matrix_postgres_docker_image_to_use }}"
when: matrix_postgres_enabled
when: matrix_postgres_enabled|bool
# We always create these directories, even if an external Postgres is used,
# because we store environment variable files there.
@ -41,7 +41,7 @@
with_items:
- "{{ matrix_postgres_base_path }}"
- "{{ matrix_postgres_data_path }}"
when: matrix_postgres_enabled
when: matrix_postgres_enabled|bool
- name: Ensure Postgres environment variables file created
template:
@ -51,21 +51,21 @@
with_items:
- "env-postgres-psql"
- "env-postgres-server"
when: matrix_postgres_enabled
when: matrix_postgres_enabled|bool
- name: Ensure matrix-postgres-cli script created
template:
src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-cli.j2"
dest: "/usr/local/bin/matrix-postgres-cli"
mode: 0750
when: matrix_postgres_enabled
when: matrix_postgres_enabled|bool
- name: Ensure matrix-make-user-admin script created
template:
src: "{{ role_path }}/templates/usr-local-bin/matrix-make-user-admin.j2"
dest: "/usr/local/bin/matrix-make-user-admin"
mode: 0750
when: matrix_postgres_enabled
when: matrix_postgres_enabled|bool
#
# Tasks related to setting up an internal postgres server
@ -77,12 +77,12 @@
dest: "/etc/systemd/system/matrix-postgres.service"
mode: 0644
register: matrix_postgres_systemd_service_result
when: matrix_postgres_enabled
when: matrix_postgres_enabled|bool
- name: Ensure systemd reloaded after matrix-postgres.service installation
service:
daemon_reload: yes
when: "matrix_postgres_enabled and matrix_postgres_systemd_service_result.changed"
when: "matrix_postgres_enabled|bool and matrix_postgres_systemd_service_result.changed"
#
# Tasks related to getting rid of the internal postgres server (if it was previously enabled)
@ -92,41 +92,41 @@
stat:
path: "/etc/systemd/system/matrix-postgres.service"
register: matrix_postgres_service_stat
when: "not matrix_postgres_enabled"
when: "not matrix_postgres_enabled|bool"
- name: Ensure matrix-postgres is stopped
service:
name: matrix-postgres
state: stopped
daemon_reload: yes
when: "not matrix_postgres_enabled 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
file:
path: "/etc/systemd/system/matrix-postgres.service"
state: absent
when: "not matrix_postgres_enabled 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
service:
daemon_reload: yes
when: "not matrix_postgres_enabled 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:
path: "{{ matrix_postgres_data_path }}"
register: matrix_postgres_data_path_stat
when: "not matrix_postgres_enabled"
when: "not matrix_postgres_enabled|bool"
# We just want to notify the user. Deleting data is too destructive.
- name: Notify if matrix-postgres local data remains
debug:
msg: "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 and matrix_postgres_data_path_stat.stat.exists"
when: "not matrix_postgres_enabled|bool and matrix_postgres_data_path_stat.stat.exists"
- name: Ensure matrix-postgres-update-user-password-hash script created
template:
src: "{{ role_path }}/templates/usr-local-bin/matrix-postgres-update-user-password-hash.j2"
dest: "/usr/local/bin/matrix-postgres-update-user-password-hash"
mode: 0750
when: matrix_postgres_enabled
when: matrix_postgres_enabled|bool

View File

@ -23,7 +23,7 @@
- name: Fail, if trying to upgrade external Postgres database
fail:
msg: "Your configuration indicates that you're not using Postgres from this role. There is nothing to upgrade."
when: "not matrix_postgres_enabled"
when: "not matrix_postgres_enabled|bool"
- name: Check Postgres auto-upgrade backup data directory
stat:
@ -40,7 +40,7 @@
- name: Abort, if no existing Postgres version detected
fail:
msg: "Could not find existing Postgres installation"
when: "not matrix_postgres_detected_existing"
when: "not matrix_postgres_detected_existing|bool"
- name: Abort, if already at latest Postgres version
fail:

View File

@ -23,12 +23,12 @@
slurp:
src: "{{ matrix_postgres_detection_pg_version_path }}"
register: result_pg_version
when: "matrix_postgres_detected_existing"
when: matrix_postgres_detected_existing|bool
- name: Determine existing Postgres version (make sense of PG_VERSION file)
set_fact:
matrix_postgres_detected_version: "{{ result_pg_version['content']|b64decode|replace('\n', '') }}"
when: "matrix_postgres_detected_existing"
when: matrix_postgres_detected_existing|bool
- name: Determine corresponding Docker image to detected version (assume default of latest)
set_fact:
@ -43,4 +43,4 @@
- name: Determine corresponding Docker image to detected version (use 10.x, if detected)
set_fact:
matrix_postgres_detected_version_corresponding_docker_image: "{{ matrix_postgres_docker_image_v10 }}"
when: "matrix_postgres_detected_version == '10' or matrix_postgres_detected_version.startswith('10.')"
when: "matrix_postgres_detected_version == '10' or matrix_postgres_detected_version.startswith('10.')"