1
0
mirror of https://github.com/spantaleev/matrix-docker-ansible-deploy.git synced 2024-12-12 08:43:55 +02:00
matrix-docker-ansible-deploy/roles/matrix-redis/tasks/setup_redis.yml
2022-07-18 13:01:17 +03:00

105 lines
3.9 KiB
YAML

---
#
# 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
register: result
retries: "{{ matrix_container_retries_count }}"
delay: "{{ matrix_container_retries_delay }}"
until: result is not failed
- name: Ensure redis paths exist
ansible.builtin.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
ansible.builtin.file:
path: "{{ matrix_redis_data_path }}"
state: directory
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_username }}"
recurse: true
when: matrix_redis_enabled | bool
- name: Ensure redis environment variables file created
ansible.builtin.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
ansible.builtin.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
ansible.builtin.service:
daemon_reload: true
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
ansible.builtin.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
ansible.builtin.service:
name: matrix-redis
state: stopped
enabled: false
daemon_reload: true
when: "not matrix_redis_enabled | bool and matrix_redis_service_stat.stat.exists"
- name: Ensure matrix-redis.service doesn't exist
ansible.builtin.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
ansible.builtin.service:
daemon_reload: true
when: "not matrix_redis_enabled | bool and matrix_redis_service_stat.stat.exists"
- name: Check existence of matrix-redis local data path
ansible.builtin.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
ansible.builtin.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"