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.
100 lines
3.5 KiB
100 lines
3.5 KiB
4 years ago
|
---
|
||
|
|
||
|
#
|
||
|
# Tasks related to setting up an internal redis server
|
||
|
#
|
||
|
|
||
|
- name: Ensure redis Docker image is pulled
|
||
|
docker_image:
|
||
|
name: "{{ matrix_redis_docker_image_to_use }}"
|
||
|
source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}"
|
||
|
force_source: "{{ matrix_redis_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}"
|
||
|
force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_redis_docker_image_force_pull }}"
|
||
|
when: matrix_redis_enabled|bool
|
||
|
|
||
|
- name: Ensure redis paths exist
|
||
|
file:
|
||
|
path: "{{ item }}"
|
||
|
state: directory
|
||
|
mode: 0700
|
||
|
owner: "{{ matrix_user_username }}"
|
||
|
group: "{{ matrix_user_username }}"
|
||
|
with_items:
|
||
|
- "{{ matrix_redis_base_path }}"
|
||
|
- "{{ matrix_redis_data_path }}"
|
||
|
when: matrix_redis_enabled|bool
|
||
|
|
||
|
# We do this as a separate task, because:
|
||
|
# - we'd like to do it for the data path only, not for the base path (which contains root-owned environment variable files we'd like to leave as-is)
|
||
|
# - we need to do it without `mode`, or we risk making certain `.conf` and other files's executable bit to flip to true
|
||
|
- name: Ensure redis data path ownership is correct
|
||
|
file:
|
||
|
path: "{{ matrix_redis_data_path }}"
|
||
|
state: directory
|
||
|
owner: "{{ matrix_user_username }}"
|
||
|
group: "{{ matrix_user_username }}"
|
||
|
recurse: yes
|
||
|
when: matrix_redis_enabled|bool
|
||
|
|
||
|
- name: Ensure redis environment variables file created
|
||
|
template:
|
||
|
src: "{{ role_path }}/templates/{{ item }}.j2"
|
||
|
dest: "{{ matrix_redis_base_path }}/{{ item }}"
|
||
|
mode: 0644
|
||
|
with_items:
|
||
|
- "redis.conf"
|
||
|
when: matrix_redis_enabled|bool
|
||
|
|
||
|
- name: Ensure matrix-redis.service installed
|
||
|
template:
|
||
|
src: "{{ role_path }}/templates/systemd/matrix-redis.service.j2"
|
||
|
dest: "{{ matrix_systemd_path }}/matrix-redis.service"
|
||
|
mode: 0644
|
||
|
register: matrix_redis_systemd_service_result
|
||
|
when: matrix_redis_enabled|bool
|
||
|
|
||
|
- name: Ensure systemd reloaded after matrix-redis.service installation
|
||
|
service:
|
||
|
daemon_reload: yes
|
||
|
when: "matrix_redis_enabled|bool and matrix_redis_systemd_service_result.changed"
|
||
|
|
||
|
#
|
||
|
# Tasks related to getting rid of the internal redis server (if it was previously enabled)
|
||
|
#
|
||
|
|
||
|
- name: Check existence of matrix-redis service
|
||
|
stat:
|
||
|
path: "{{ matrix_systemd_path }}/matrix-redis.service"
|
||
|
register: matrix_redis_service_stat
|
||
|
when: "not matrix_redis_enabled|bool"
|
||
|
|
||
|
- name: Ensure matrix-redis is stopped
|
||
|
service:
|
||
|
name: matrix-redis
|
||
|
state: stopped
|
||
|
daemon_reload: yes
|
||
|
when: "not matrix_redis_enabled|bool and matrix_redis_service_stat.stat.exists"
|
||
|
|
||
|
- name: Ensure matrix-redis.service doesn't exist
|
||
|
file:
|
||
|
path: "{{ matrix_systemd_path }}/matrix-redis.service"
|
||
|
state: absent
|
||
|
when: "not matrix_redis_enabled|bool and matrix_redis_service_stat.stat.exists"
|
||
|
|
||
|
- name: Ensure systemd reloaded after matrix-redis.service removal
|
||
|
service:
|
||
|
daemon_reload: yes
|
||
|
when: "not matrix_redis_enabled|bool and matrix_redis_service_stat.stat.exists"
|
||
|
|
||
|
- name: Check existence of matrix-redis local data path
|
||
|
stat:
|
||
|
path: "{{ matrix_redis_data_path }}"
|
||
|
register: matrix_redis_data_path_stat
|
||
|
when: "not matrix_redis_enabled|bool"
|
||
|
|
||
|
# We just want to notify the user. Deleting data is too destructive.
|
||
|
- name: Notify if matrix-redis local data remains
|
||
|
debug:
|
||
|
msg: "Note: You are not using a local redis instance, but some old data remains from before in `{{ matrix_redis_data_path }}`. Feel free to delete it."
|
||
|
when: "not matrix_redis_enabled|bool and matrix_redis_data_path_stat.stat.exists"
|