matrix-docker-ansible-deploy/roles/matrix-redis/tasks/setup_redis.yml

105 lines
3.9 KiB
YAML
Raw Normal View History

2020-09-10 11:39:00 +00:00
---
#
# Tasks related to setting up an internal redis server
#
- name: Ensure redis Docker image is pulled
community.docker.docker_image:
2020-09-10 11:39:00 +00:00
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 }}"
2022-07-18 08:22:05 +00:00
when: matrix_redis_enabled | bool
register: result
retries: "{{ matrix_container_retries_count }}"
delay: "{{ matrix_container_retries_delay }}"
until: result is not failed
2020-09-10 11:39:00 +00:00
- name: Ensure redis paths exist
ansible.builtin.file:
2020-09-10 11:39:00 +00:00
path: "{{ item }}"
state: directory
mode: 0700
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_username }}"
with_items:
- "{{ matrix_redis_base_path }}"
- "{{ matrix_redis_data_path }}"
2022-07-18 08:22:05 +00:00
when: matrix_redis_enabled | bool
2020-09-10 11:39:00 +00:00
# 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:
2020-09-10 11:39:00 +00:00
path: "{{ matrix_redis_data_path }}"
state: directory
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_username }}"
recurse: true
2022-07-18 08:22:05 +00:00
when: matrix_redis_enabled | bool
2020-09-10 11:39:00 +00:00
- name: Ensure redis environment variables file created
ansible.builtin.template:
2020-09-10 11:39:00 +00:00
src: "{{ role_path }}/templates/{{ item }}.j2"
dest: "{{ matrix_redis_base_path }}/{{ item }}"
mode: 0644
with_items:
- "redis.conf"
2022-07-18 08:22:05 +00:00
when: matrix_redis_enabled | bool
2020-09-10 11:39:00 +00:00
- name: Ensure matrix-redis.service installed
ansible.builtin.template:
2020-09-10 11:39:00 +00:00
src: "{{ role_path }}/templates/systemd/matrix-redis.service.j2"
dest: "{{ matrix_systemd_path }}/matrix-redis.service"
mode: 0644
register: matrix_redis_systemd_service_result
2022-07-18 08:22:05 +00:00
when: matrix_redis_enabled | bool
2020-09-10 11:39:00 +00:00
- name: Ensure systemd reloaded after matrix-redis.service installation
ansible.builtin.service:
daemon_reload: true
2022-07-18 08:22:05 +00:00
when: "matrix_redis_enabled | bool and matrix_redis_systemd_service_result.changed"
2020-09-10 11:39:00 +00:00
#
# Tasks related to getting rid of the internal redis server (if it was previously enabled)
#
- name: Check existence of matrix-redis service
2022-07-18 08:22:05 +00:00
ansible.builtin.stat:
2020-09-10 11:39:00 +00:00
path: "{{ matrix_systemd_path }}/matrix-redis.service"
register: matrix_redis_service_stat
2022-07-18 08:22:05 +00:00
when: "not matrix_redis_enabled | bool"
2020-09-10 11:39:00 +00:00
- name: Ensure matrix-redis is stopped
ansible.builtin.service:
2020-09-10 11:39:00 +00:00
name: matrix-redis
state: stopped
enabled: false
daemon_reload: true
2022-07-18 08:22:05 +00:00
when: "not matrix_redis_enabled | bool and matrix_redis_service_stat.stat.exists"
2020-09-10 11:39:00 +00:00
- name: Ensure matrix-redis.service doesn't exist
ansible.builtin.file:
2020-09-10 11:39:00 +00:00
path: "{{ matrix_systemd_path }}/matrix-redis.service"
state: absent
2022-07-18 08:22:05 +00:00
when: "not matrix_redis_enabled | bool and matrix_redis_service_stat.stat.exists"
2020-09-10 11:39:00 +00:00
- name: Ensure systemd reloaded after matrix-redis.service removal
ansible.builtin.service:
daemon_reload: true
2022-07-18 08:22:05 +00:00
when: "not matrix_redis_enabled | bool and matrix_redis_service_stat.stat.exists"
2020-09-10 11:39:00 +00:00
- name: Check existence of matrix-redis local data path
2022-07-18 08:22:05 +00:00
ansible.builtin.stat:
2020-09-10 11:39:00 +00:00
path: "{{ matrix_redis_data_path }}"
register: matrix_redis_data_path_stat
2022-07-18 08:22:05 +00:00
when: "not matrix_redis_enabled | bool"
2020-09-10 11:39:00 +00:00
# We just want to notify the user. Deleting data is too destructive.
- name: Notify if matrix-redis local data remains
ansible.builtin.debug:
2020-09-10 11:39:00 +00:00
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."
2022-07-18 08:22:05 +00:00
when: "not matrix_redis_enabled | bool and matrix_redis_data_path_stat.stat.exists"