From aced3188b28cbc7b43eed75a1de008b568b3f751 Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Sun, 19 Nov 2023 00:36:00 +0530 Subject: [PATCH] feat: write custom redis config using inline mod --- ansible/artifacts/cache/cache.service | 18 ------------------ ansible/artifacts/cache/redis.conf | 2 -- ansible/cache.yml | 2 +- ansible/roles/cache/handlers/main.yml | 1 + ansible/roles/cache/tasks/main.yml | 24 ++++++++++++++++++------ 5 files changed, 20 insertions(+), 27 deletions(-) delete mode 100644 ansible/artifacts/cache/cache.service delete mode 100644 ansible/artifacts/cache/redis.conf diff --git a/ansible/artifacts/cache/cache.service b/ansible/artifacts/cache/cache.service deleted file mode 100644 index 1f7e25b..0000000 --- a/ansible/artifacts/cache/cache.service +++ /dev/null @@ -1,18 +0,0 @@ -[Unit] -Description=Redis instance with mCaptcha cache module -After=network.target -Documentation=https://github.com/mCaptcha/cache - -[Service] -Type=notify -ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --supervised systemd --daemonize no -PIDFile=/run/redis/redis-server.pid -TimeoutStopSec=0 -Restart=always -User=redis -Group=redis -RuntimeDirectory=redis -RuntimeDirectoryMode=2755 - -UMask=007 -PrivateTmp=true diff --git a/ansible/artifacts/cache/redis.conf b/ansible/artifacts/cache/redis.conf deleted file mode 100644 index 7c7ddc3..0000000 --- a/ansible/artifacts/cache/redis.conf +++ /dev/null @@ -1,2 +0,0 @@ -loadmodule /usr/lib/redis/modules/libcache.so -bind 0.0.0.0 diff --git a/ansible/cache.yml b/ansible/cache.yml index 5942443..04231df 100644 --- a/ansible/cache.yml +++ b/ansible/cache.yml @@ -6,7 +6,7 @@ ansible.builtin.import_playbook: base.yml - name: Install redis cache - hosts: mcaptcha_demo_server + hosts: mcaptcha_hosts remote_user: atm pre_tasks: - name: Ensure all VMs are reachable diff --git a/ansible/roles/cache/handlers/main.yml b/ansible/roles/cache/handlers/main.yml index 7d2fadb..64fd538 100644 --- a/ansible/roles/cache/handlers/main.yml +++ b/ansible/roles/cache/handlers/main.yml @@ -1,5 +1,6 @@ - name: Restart redis listen: restart redis + become: true ansible.builtin.service: name: redis enabled: true diff --git a/ansible/roles/cache/tasks/main.yml b/ansible/roles/cache/tasks/main.yml index 85d08ad..b0f83a6 100644 --- a/ansible/roles/cache/tasks/main.yml +++ b/ansible/roles/cache/tasks/main.yml @@ -6,11 +6,13 @@ become: true ansible.builtin.apt: update_cache: true + cache_valid_time: 3600 pkg: - redis-server - name: Create Redis plugins dir become: true + notify: restart redis ansible.builtin.file: path: /usr/lib/redis/modules owner: redis @@ -18,15 +20,27 @@ state: directory mode: "0755" +- name: Load mCaptcha module + become: true + notify: restart redis + ansible.builtin.lineinfile: + dest: /etc/redis/redis.conf + line: "{{ item }}" + loop: + - "loadmodule /usr/lib/redis/modules/libcache.so" + - "bind 0.0.0.0" + - name: Copy custom Redis configuration become: true - ansible.builtin.copy: - src: ./artifacts/cache/redis.conf - dest: /etc/redis/ + notify: restart redis + ansible.builtin.file: + path: "{{ item }}" owner: redis group: redis force: true - mode: "0640" + loop: + - /etc/redis/redis.conf + - /etc/redis/ - name: Create download dir ansible.builtin.file: @@ -70,5 +84,3 @@ rule: allow proto: tcp port: "6379" - -