An Ansible role to deploy a Redis service to a Docker Swarm cluster.
- Docker installed on the target machine
- Docker Swarm initialized on the target machine
- An overlay network for the swarm services
You can install this role directly from Ansible Galaxy:
ansible-galaxy install brpaz.swarm_redisFor version-controlled, repeatable role installations, add to your requirements.yml:
---
roles:
- name: brpaz.swarm_redis
version: v1.0.0 # Specify the version you want
collections:
- name: community.dockerThen install with:
ansible-galaxy install -r requirements.ymlAlternatively, you can clone the repository directly:
# Create a roles directory if it doesn't exist
mkdir -p ~/.ansible/roles
# Clone the repository
git clone https://github.com/brpaz/ansible-role-swarm-redis.git ~/.ansible/roles/brpaz.swarm_redisThis role includes the following variables for configuration:
| Variable | Default Value | Description |
|---|---|---|
redis_version |
7.0.11 |
Redis version to use |
redis_image |
redis:{{ redis_version }} |
Redis Docker image |
redis_port |
6379 |
Port Redis will listen on |
redis_port_mode |
ingress |
Docker service publish mode (ingress or host) |
redis_password |
"" |
Password for Redis authentication (empty by default) |
redis_conf |
See below | Redis configuration settings |
redis_networks |
[{name: "swarm_network"}] |
Docker swarm network configuration |
redis_conf_dir |
/etc/redis |
Local directory for configs |
redis_service_name |
redis |
Name of the Redis service |
redis_cpu_requests |
0.1 |
CPU resource requests |
redis_cpu_limits |
0.5 |
CPU resource limits |
redis_memory_requests |
32M |
Memory resource requests |
redis_memory_limits |
1G |
Memory resource limits |
Default Redis configuration:
redis_conf:
port: "{{ redis_port }}"
bind: "0.0.0.0"
requirepass: "{{ redis_password }}"- community.docker collection
- hosts: redis_servers
vars:
redis_version: "7.0.11"
redis_password: "securepassword"
redis_networks:
- name: "app_network"
redis_conf:
port: "6379"
bind: "0.0.0.0"
maxmemory: "256mb"
maxmemory-policy: "allkeys-lru"
redis_cpu_requests: 0.1
redis_cpu_limits: 0.5
redis_memory_requests: "32M"
redis_memory_limits: "1G"
roles:
- brpaz.swarm_redisThe redis_conf dictionary allows for setting any Redis configuration directives. To add configuration while keeping defaults, you can use the combine filter:
- hosts: redis_servers
vars:
custom_redis_conf:
maxmemory: "2gb"
maxmemory-policy: "allkeys-lru"
redis_conf: "{{ lookup('ansible.builtin.vars', 'redis_conf') | default({}) | combine(custom_redis_conf) }}"
roles:
- brpaz.swarm_redisCheck CONTRIBUTING.md for details.
If you find this project helpful and would like to support its development, there are a few ways you can contribute:
Distributed under the MIT License. See LICENSE file for details.
✉️ Email - [email protected]
🖇️ Source code: https://github.com/brpaz/ansible-role-swarm