Fix no-changed-when ansible-lint errors

Reference: https://ansible-lint.readthedocs.io/en/latest/default_rules/#no-changed-when
This commit is contained in:
Slavi Pantaleev
2022-07-18 15:08:10 +03:00
parent 0ab2001ce7
commit 1693c4ca1d
15 changed files with 116 additions and 56 deletions

View File

@ -80,10 +80,14 @@
{{ matrix_postgres_pgloader_docker_image }}
-c
'pgloader /in.db {{ postgres_db_connection_string }}'
register: matrix_postgres_import_generic_sqlite_db_import_result
changed_when: matrix_postgres_import_generic_sqlite_db_import_result.rc == 0
- name: Archive SQLite database ({{ sqlite_database_path }} -> {{ sqlite_database_path }}.backup)
ansible.builtin.command:
cmd: "mv {{ sqlite_database_path }} {{ sqlite_database_path }}.backup"
register: matrix_postgres_import_generic_sqlite_db_move_result
changed_when: matrix_postgres_import_generic_sqlite_db_move_result.rc == 0
- name: Inject result
ansible.builtin.set_fact:

View File

@ -101,6 +101,9 @@
and manually run the above import command directly on the server.
- name: Perform Postgres database import
ansible.builtin.command: "{{ matrix_postgres_import_command }}"
ansible.builtin.command:
cmd: "{{ matrix_postgres_import_command }}"
async: "{{ postgres_import_wait_time }}"
poll: 10
register: matrix_postgres_import_postgres_command_result
changed_when: matrix_postgres_import_postgres_command_result.rc == 0

View File

@ -70,17 +70,20 @@
# Also, some old `docker_container` versions were buggy and would leave containers behind
# on failure, which we had to work around to allow retries (by re-running the playbook).
- name: Import SQLite database into Postgres
ansible.builtin.command: |
docker run
--rm
--name=matrix-synapse-migrate
--log-driver=none
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
--cap-drop=ALL
--network={{ matrix_docker_network }}
--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 }}
{{ matrix_synapse_docker_image }}
/usr/local/bin/synapse_port_db --sqlite-database /{{ server_path_homeserver_db | basename }} --postgres-config /data/homeserver.yaml
ansible.builtin.command:
cmd: |
docker run
--rm
--name=matrix-synapse-migrate
--log-driver=none
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
--cap-drop=ALL
--network={{ matrix_docker_network }}
--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 }}
{{ matrix_synapse_docker_image }}
/usr/local/bin/synapse_port_db --sqlite-database /{{ server_path_homeserver_db | basename }} --postgres-config /data/homeserver.yaml
register: matrix_postgres_import_synapse_sqlite_db_result
changed_when: matrix_postgres_import_synapse_sqlite_db_result.rc == 0

View File

@ -51,8 +51,11 @@
- 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:
cmd: "mv {{ item.path }} {{ matrix_postgres_data_path }}/{{ item.path | basename }}"
with_items: "{{ result_pg_old_data_dir_find.files }}"
register: matrix_postgres_migrate_postgres_data_directory_move_result
changed_when: matrix_postgres_migrate_postgres_data_directory_move_result.rc == 0
when: "result_pg_old_data_dir_stat.stat.exists"
# Intentionally not starting matrix-postgres here.

View File

@ -65,7 +65,7 @@
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' }}"
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' }}"
- name: Ensure matrix-synapse is stopped
ansible.builtin.service:
@ -78,6 +78,7 @@
async: "{{ postgres_vacuum_wait_time }}"
poll: 10
register: matrix_postgres_synapse_vacuum_result
changed_when: matrix_postgres_synapse_vacuum_result.rc == 0
# Intentionally show the results
- ansible.builtin.debug: var="matrix_postgres_synapse_vacuum_result"

View File

@ -78,18 +78,21 @@
# role (`matrix_postgres_connection_username`) and database (`matrix_postgres_db_name`) by itself on startup,
# we need to remove these from the dump, or we'll get errors saying these already exist.
- name: Perform Postgres database dump
ansible.builtin.command: >-
{{ matrix_host_command_docker }} run --rm --name matrix-postgres-dump
--log-driver=none
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
--network={{ matrix_docker_network }}
--env-file={{ matrix_postgres_base_path }}/env-postgres-psql
--entrypoint=/bin/sh
--mount type=bind,src={{ postgres_dump_dir }},dst=/out
{{ matrix_postgres_detected_version_corresponding_docker_image }}
-c "pg_dumpall -h matrix-postgres
{{ '| gzip -c ' if postgres_dump_name.endswith('.gz') else '' }}
> /out/{{ postgres_dump_name }}"
ansible.builtin.command:
cmd: >-
{{ matrix_host_command_docker }} run --rm --name matrix-postgres-dump
--log-driver=none
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
--network={{ matrix_docker_network }}
--env-file={{ matrix_postgres_base_path }}/env-postgres-psql
--entrypoint=/bin/sh
--mount type=bind,src={{ postgres_dump_dir }},dst=/out
{{ matrix_postgres_detected_version_corresponding_docker_image }}
-c "pg_dumpall -h matrix-postgres
{{ '| gzip -c ' if postgres_dump_name.endswith('.gz') else '' }}
> /out/{{ postgres_dump_name }}"
register: matrix_postgres_upgrade_postgres_dump_command_result
changed_when: matrix_postgres_upgrade_postgres_dump_command_result.rc == 0
- name: Ensure matrix-postgres is stopped
ansible.builtin.service:
@ -97,7 +100,10 @@
state: stopped
- name: Rename existing Postgres data directory
ansible.builtin.command: "mv {{ matrix_postgres_data_path }} {{ postgres_auto_upgrade_backup_data_path }}"
ansible.builtin.command:
cmd: "mv {{ matrix_postgres_data_path }} {{ postgres_auto_upgrade_backup_data_path }}"
register: matrix_postgres_upgrade_postgres_move_command_result
changed_when: matrix_postgres_upgrade_postgres_move_command_result.rc == 0
- 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."
@ -155,7 +161,10 @@
and restore the automatically-made backup (`mv {{ postgres_auto_upgrade_backup_data_path }} {{ matrix_postgres_data_path }}`).
- name: Perform Postgres database import
ansible.builtin.command: "{{ matrix_postgres_import_command }}"
ansible.builtin.command:
cmd: "{{ matrix_postgres_import_command }}"
register: matrix_postgres_upgrade_postgres_import_command_result
changed_when: matrix_postgres_upgrade_postgres_import_command_result.rc == 0
- name: Delete Postgres database dump file
ansible.builtin.file: