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.
 
 

81 lines
3.0 KiB

  1. ---
  2. - name: Determine whether we should make services autostart
  3. set_fact:
  4. matrix_services_autostart_enabled_bool: "{{ true if matrix_services_autostart_enabled|default('') == '' else matrix_services_autostart_enabled|bool }}"
  5. - name: Ensure systemd is reloaded
  6. service:
  7. daemon_reload: yes
  8. - name: Ensure Matrix services are stopped
  9. service:
  10. name: matrix.target
  11. state: stopped
  12. when: not ansible_check_mode
  13. - name: Ensure Matrix services are enabled
  14. service:
  15. name: "{{ item }}"
  16. enabled: true
  17. with_items: "{{ matrix_systemd_services_list }}"
  18. when: not ansible_check_mode
  19. - name: Ensure Matrix services are started
  20. service:
  21. name: "matrix.target"
  22. enabled: "{{ matrix_services_autostart_enabled_bool }}"
  23. state: started
  24. when: not ansible_check_mode
  25. # If we check service state immediately, we may not succeed,
  26. # because it takes some time for the service to attempt to start and actually fail.
  27. #
  28. # Waiting too long (30s) may not work for a similar reason,
  29. # as we may run into systemd's automatic restart logic retrying the service.
  30. #
  31. # Obviously this is a terrible way of doing things
  32. # Ideally, we would use Podman's PIDFiles, but then we lose support for most OSes.
  33. # Alternatively, we could use systemd-docker, but it hasn't been updated since 2015 and is incompatible with Podman.
  34. - name: Wait a bit, so that services can start (or fail)
  35. wait_for:
  36. timeout: 15
  37. delegate_to: 127.0.0.1
  38. become: false
  39. - block:
  40. - name: Populate service facts
  41. service_facts:
  42. - name: Fail if service isn't detected to be running
  43. fail:
  44. msg: >-
  45. {{ item }} was not detected to be running.
  46. It's possible that there's a configuration problem or another service on your server interferes with it (uses the same ports, etc.).
  47. Try running `systemctl status {{ item }}` and `journalctl -fu {{ item }}` on the server to investigate.
  48. with_items: "{{ matrix_systemd_services_list }}"
  49. when:
  50. - "item.endswith('.service') and (ansible_facts.services[item]|default(none) is none or ansible_facts.services[item].state != 'running')"
  51. when: " ansible_distribution != 'Archlinux'"
  52. - block:
  53. # Currently there is a bug in ansible that renders is incompatible with systemd.
  54. # service_facts is not collecting the data successfully.
  55. # Therefore iterating here manually
  56. - name: Fetch systemd information
  57. systemd:
  58. name: "{{ item }}"
  59. register: systemdstatus
  60. with_items: "{{ matrix_systemd_services_list }}"
  61. - name: Fail if service isn't detected to be running
  62. fail:
  63. msg: >-
  64. {{ item.item }} was not detected to be running.
  65. It's possible that there's a configuration problem or another service on your server interferes with it (uses the same ports, etc.).
  66. Try running `systemctl status {{ item.item }}` and `journalctl -fu {{ item.item }}` on the server to investigate.
  67. with_items: "{{ systemdstatus.results }}"
  68. when: "item.status['ActiveState'] != 'active'"
  69. when: "ansible_distribution == 'Archlinux'"