diff --git a/roles/redis/defaults/main.yml b/roles/redis/defaults/main.yml new file mode 100644 index 0000000..e7b6343 --- /dev/null +++ b/roles/redis/defaults/main.yml @@ -0,0 +1 @@ +redis_image: docker.io/redis:7 diff --git a/roles/redis/tasks/main.yaml b/roles/redis/tasks/main.yaml index af03253..5844019 100644 --- a/roles/redis/tasks/main.yaml +++ b/roles/redis/tasks/main.yaml @@ -1,14 +1,28 @@ --- -- name: Install redis - ansible.builtin.package: - name: "redis" +- name: Pull Redis container image + containers.podman.podman_image: + name: "{{ redis_image }}" state: present -- name: Start the Redis Service - ansible.builtin.systemd: +- name: Create directory for Redis data + ansible.builtin.file: + path: /var/lib/redis + state: directory + owner: 1001 + group: 1001 + mode: '0755' + +- name: Run Redis as a container + containers.podman.podman_container: name: redis - enabled: true + image: "{{ redis_image }}" state: started + volumes: + - /var/lib/redis:/data:Z + - /etc/redis/redis.conf:/usr/local/etc/redis/redis.conf:Z + ports: + - "6379:6379" + command: ["redis-server", "/usr/local/etc/redis/redis.conf"] - name: Wait for Redis service to be accessible ansible.builtin.wait_for: diff --git a/tests/redis_test.py b/tests/redis_test.py index 2e3e1bb..8cd48e0 100644 --- a/tests/redis_test.py +++ b/tests/redis_test.py @@ -1,16 +1,13 @@ import pytest - REDIS_HOST = 'localhost' REDIS_PORT = 6379 - def test_redis_service(server): redis = server.service("redis") assert redis.is_running assert redis.is_enabled - def test_redis_port(server): redis = server.addr(REDIS_HOST) assert redis.port(REDIS_PORT).is_reachable