Matrix Docker Ansible eploy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

63 line
2.5 KiB

  1. # SPDX-FileCopyrightText: 2019 Dan Arnfield
  2. # SPDX-FileCopyrightText: 2019 Lyubomir Popov
  3. # SPDX-FileCopyrightText: 2020 - 2024 Slavi Pantaleev
  4. # SPDX-FileCopyrightText: 2020 Chris van Dijk
  5. # SPDX-FileCopyrightText: 2020 Christian Wolf
  6. # SPDX-FileCopyrightText: 2020 MDAD project contributors
  7. # SPDX-FileCopyrightText: 2022 Marko Weltzer
  8. #
  9. # SPDX-License-Identifier: AGPL-3.0-or-later
  10. ---
  11. - name: Fail if playbook called incorrectly
  12. ansible.builtin.fail:
  13. msg: "The `username` variable needs to be provided to this playbook, via --extra-vars"
  14. when: "username is not defined or username == '<your-username>'"
  15. - name: Fail if playbook called incorrectly
  16. ansible.builtin.fail:
  17. msg: "The `password` variable needs to be provided to this playbook, via --extra-vars"
  18. when: "password is not defined or password == '<your-password>'"
  19. - name: Fail if not using integrated Postgres database
  20. ansible.builtin.fail:
  21. msg: "This command is working only when Postgres is installed via the the integrated ansible-role-postgres role"
  22. when: "not postgres_enabled | bool"
  23. - name: Ensure Postgres is started
  24. ansible.builtin.service:
  25. name: "{{ postgres_identifier }}"
  26. state: started
  27. daemon_reload: true
  28. register: postgres_start_result
  29. - name: Ensure Synapse is started
  30. ansible.builtin.service:
  31. name: matrix-synapse
  32. state: started
  33. daemon_reload: true
  34. register: synapse_start_result
  35. - name: Wait a while, so that Synapse and/or Postgres can manage to start
  36. ansible.builtin.pause:
  37. seconds: 7
  38. when: "synapse_start_result.changed or postgres_start_result.changed"
  39. - name: Generate user password hash
  40. ansible.builtin.shell: "{{ devture_systemd_docker_base_host_command_docker }} exec matrix-synapse /usr/local/bin/hash_password -c /data/homeserver.yaml -p {{ password | quote }}"
  41. register: password_hash
  42. changed_when: false
  43. - name: Generate user password-change SQL command
  44. ansible.builtin.set_fact:
  45. matrix_synapse_user_password_change_command: >-
  46. {{ postgres_bin_path }}/cli-non-interactive --dbname={{ matrix_synapse_database_database | quote }} -c "UPDATE users SET password_hash='{{ password_hash.stdout }}' WHERE name = '@{{ username }}:{{ matrix_domain }}'"
  47. - name: Update user password hash
  48. ansible.builtin.command:
  49. cmd: "{{ matrix_synapse_user_password_change_command }}"
  50. register: matrix_synapse_update_user_password_result
  51. changed_when: matrix_synapse_update_user_password_result.rc == 0
  52. failed_when: "matrix_synapse_update_user_password_result.rc != 0 or matrix_synapse_update_user_password_result.stdout != 'UPDATE 1'"