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.
 
 

74 line
3.1 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: true
  8. - name: Ensure Matrix services are stopped
  9. service:
  10. name: "{{ item }}"
  11. state: stopped
  12. with_items: "{{ matrix_systemd_services_list }}"
  13. when: not ansible_check_mode
  14. - name: Ensure Matrix services are started
  15. service:
  16. name: "{{ item }}"
  17. enabled: "{{ matrix_services_autostart_enabled_bool }}"
  18. state: started
  19. with_items: "{{ matrix_systemd_services_list }}"
  20. when: not ansible_check_mode
  21. # If we check service state immediately, we may succeed,
  22. # because it takes some time for the service to attempt to start and actually fail.
  23. #
  24. # Waiting too long (30s) may not work for a similar reason,
  25. # as we may run into systemd's automatic restart logic retrying the service.
  26. - name: Wait a bit, so that services can start (or fail)
  27. wait_for:
  28. timeout: "{{ matrix_common_after_systemd_service_start_wait_for_timeout_seconds }}"
  29. delegate_to: 127.0.0.1
  30. become: false
  31. - block:
  32. - name: Populate service facts
  33. service_facts:
  34. - name: Fail if service isn't detected to be running
  35. fail:
  36. msg: >-
  37. {{ item }} was not detected to be running.
  38. It's possible that there's a configuration problem or another service on your server interferes with it (uses the same ports, etc.).
  39. Try running `systemctl status {{ item }}` and `journalctl -fu {{ item }}` on the server to investigate.
  40. If you're on a slow or overloaded server, it may be that services take a longer time to start and that this error is a false-positive.
  41. You can consider raising the value of the `matrix_common_after_systemd_service_start_wait_for_timeout_seconds` variable.
  42. See `roles/matrix-common-after/defaults/main.yml` for more details about that.
  43. with_items: "{{ matrix_systemd_services_list }}"
  44. when:
  45. - "item.endswith('.service') and (ansible_facts.services[item]|default(none) is none or ansible_facts.services[item].state != 'running')"
  46. when: " ansible_distribution != 'Archlinux'"
  47. - block:
  48. # Currently there is a bug in ansible that renders is incompatible with systemd.
  49. # service_facts is not collecting the data successfully.
  50. # Therefore iterating here manually
  51. - name: Fetch systemd information
  52. systemd:
  53. name: "{{ item }}"
  54. register: systemdstatus
  55. with_items: "{{ matrix_systemd_services_list }}"
  56. - name: Fail if service isn't detected to be running
  57. fail:
  58. msg: >-
  59. {{ item.item }} was not detected to be running.
  60. It's possible that there's a configuration problem or another service on your server interferes with it (uses the same ports, etc.).
  61. Try running `systemctl status {{ item.item }}` and `journalctl -fu {{ item.item }}` on the server to investigate.
  62. with_items: "{{ systemdstatus.results }}"
  63. when: "item.status['ActiveState'] != 'active'"
  64. when: "ansible_distribution == 'Archlinux'"