--- # Redis setup tasks - name: Install Redis ansible.builtin.apt: name: - redis-server - redis-tools state: present update_cache: yes become: yes - name: Configure Redis ansible.builtin.lineinfile: path: /etc/redis/redis.conf regexp: "{{ item.regexp }}" line: "{{ item.line }}" state: present become: yes loop: - { regexp: '^bind', line: 'bind 127.0.0.1 ::1' } - { regexp: '^protected-mode', line: 'protected-mode yes' } - { regexp: '^maxmemory', line: 'maxmemory 256mb' } - { regexp: '^maxmemory-policy', line: 'maxmemory-policy allkeys-lru' } - { regexp: '^save', line: 'save 900 1' } notify: Restart Redis - name: Ensure Redis is started and enabled ansible.builtin.systemd: name: redis-server state: started enabled: yes become: yes - name: Test Redis connection ansible.builtin.command: cmd: redis-cli ping register: redis_ping changed_when: false failed_when: redis_ping.stdout != "PONG"