From 58c5ea932185f34d9d9ab4e0f2aa66cadc20319e Mon Sep 17 00:00:00 2001 From: transcaffeine Date: Wed, 30 Oct 2024 12:21:51 +0100 Subject: [PATCH] feat(redis): add ansible role --- roles/redis/defaults/main/container.yml | 38 +++++++++++++++++++++++++ roles/redis/defaults/main/main.yml | 13 +++++++++ roles/redis/handlers/main.yml | 0 roles/redis/meta/main.yml | 0 roles/redis/tasks/main.yml | 7 +++++ roles/redis/vars/main.yml | 4 +++ 6 files changed, 62 insertions(+) create mode 100644 roles/redis/defaults/main/container.yml create mode 100644 roles/redis/defaults/main/main.yml create mode 100644 roles/redis/handlers/main.yml create mode 100644 roles/redis/meta/main.yml create mode 100644 roles/redis/tasks/main.yml create mode 100644 roles/redis/vars/main.yml diff --git a/roles/redis/defaults/main/container.yml b/roles/redis/defaults/main/container.yml new file mode 100644 index 0000000..c9d762a --- /dev/null +++ b/roles/redis/defaults/main/container.yml @@ -0,0 +1,38 @@ +--- +redis_container_image_registry: docker.io +redis_container_image_namespace: ~ +redis_container_image_name: redis +redis_container_image_tag: ~ +redis_container_image_flavour: alpine +redis_container_image_source: pull +redis_container_image_force_source: >-2 + {{ redis_container_image_tag | default(false, true) | bool }} +redis_container_image: >-2 + {{ + ([ + redis_container_image_registry | default([], true), + redis_container_image_namespace | default([], true), + redis_container_image_name, + ] | flatten | join('/')) + + ':' + + (redis_container_image_tag | default( + redis_version + ( + (redis_container_image_flavour | default(false, true) | bool) + | ternary('-' + (redis_container_image_flavour | default('')), '') + ), + true, + )) + }} + +redis_container_name: "redis{{ redis_instance_suffix }}" +redis_container_env: ~ +redis_container_user: #TODO +redis_container_ports: ~ +redis_container_labels: ~ +redis_container_volumes: # TODO +redis_container_networks: ~ +redis_container_etc_hosts: ~ +redis_container_dns_servers: ~ +redis_container_restart_policy: "unless-stopped" +redis_container_state: >-2 + {{ (redis_state == 'present') | default('started', 'absent') }} diff --git a/roles/redis/defaults/main/main.yml b/roles/redis/defaults/main/main.yml new file mode 100644 index 0000000..858edd5 --- /dev/null +++ b/roles/redis/defaults/main/main.yml @@ -0,0 +1,13 @@ +--- +redis_version: "7.2.4" +redis_instance: ~ +redis_instance_suffix: >-2 + {{ (redis_instance | default(false, true) | bool) + | ternary('-' + (redis_instance | default('')), '') }} +redis_user: >-2 + redis{{ redis_instance_suffix }} + +redis_config_path: "/etc/redis" +redis_config_file: >-2 + {{ redis_config_path }}/redis{{ redis_instance_suffix }}.conf +redis_data_path: "/var/lib/redis{{ redis_instance_suffix }}" diff --git a/roles/redis/handlers/main.yml b/roles/redis/handlers/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/roles/redis/meta/main.yml b/roles/redis/meta/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/roles/redis/tasks/main.yml b/roles/redis/tasks/main.yml new file mode 100644 index 0000000..ecc76b0 --- /dev/null +++ b/roles/redis/tasks/main.yml @@ -0,0 +1,7 @@ +--- +- name: Ensure state is valid + ansible.builtin.fail: + msg: >-2 + Unsupported state '{{ redis_state }}'. + Supported states are {{ redis_states | join(', ') }} + when: redis_state not in redis_states diff --git a/roles/redis/vars/main.yml b/roles/redis/vars/main.yml new file mode 100644 index 0000000..3dc7536 --- /dev/null +++ b/roles/redis/vars/main.yml @@ -0,0 +1,4 @@ +--- +redis_states: + - present + - absent