Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/redis compile #290

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ redis_install_dir: /opt/redis
redis_install_from_source: true
redis_dir: /var/lib/redis/{{ redis_port }}
redis_config_file_name: "{{ redis_port }}.conf"
redis_download_url: "http://download.redis.io/releases/redis-{{ redis_version }}.tar.gz"
redis_download_url: "https://download.redis.io/releases/redis-{{ redis_version }}.tar.gz"

redis_protected_mode: "yes"
# Set this to true to validate redis tarball checksum against vars/main.yml
Expand Down Expand Up @@ -118,10 +118,17 @@ redis_hz: 10
# io-threads-do-reads yes
redis_config_additional: ""

## Redis cluster configs
redis_cluster_enabled: false
redis_cluster_node_timeout: 15000
# Prevent slave to be promoted as a master in case of auto-failover
# only works in version 4.x and above
redis_cluster_slave_no_failover: "no"

## Redis sentinel configs
# Set this to true on a host to configure it as a Sentinel
redis_sentinel: false
redis_sentinel_protected_mode: "yes"
redis_sentinel_protected_mode: "no"
redis_sentinel_dir: /var/lib/redis/sentinel_{{ redis_sentinel_port }}
redis_sentinel_bind: 0.0.0.0
redis_sentinel_port: 26379
Expand All @@ -130,15 +137,20 @@ redis_sentinel_pidfile: /var/run/redis/sentinel_{{ redis_sentinel_port }}.pid
redis_sentinel_logfile: '""'
redis_sentinel_syslog_ident: sentinel_{{ redis_sentinel_port }}
redis_sentinel_oom_score_adjust: 0
redis_sentinel_monitors:
- name: master01
host: localhost
port: 6379
quorum: 2
auth_pass: ant1r3z
down_after_milliseconds: 30000
parallel_syncs: 1
failover_timeout: 180000
notification_script: false
client_reconfig_script: false
rename_commands: []
redis_sentinel_monitors: []
# Set this to true if you update the configuration via runtime
# e.g: registering master to monitor via command-line instead manually edit the config file
redis_sentinel_runtime_monitor_master: false
# Example:
# redis_sentinel_monitors:
# - name: master01
# host: localhost
# port: 6379
# quorum: 2
# auth_pass: ant1r3z
# down_after_milliseconds: 30000
# parallel_syncs: 1
# failover_timeout: 180000
# notification_script: false
# client_reconfig_script: false
# rename_commands: []
7 changes: 7 additions & 0 deletions tasks/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@
- "{{ 'libgcc_s1-32bit' if redis_make_32bit|bool else 'gcc' }}"
state: present
when: ansible_os_family == 'Suse'

- name: "Add patch for redis-5.0.5 in Ubuntu 22.04"
ansible.builtin.lineinfile:
path: /usr/local/src/redis-5.0.5/src/sds.h
regexp: '^const char \*SDS_NOINIT;'
line: 'extern const char *SDS_NOINIT;'
when: redis_version == '5.0.5'
75 changes: 75 additions & 0 deletions tasks/sentinel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,88 @@
- redis_sentinel_pidfile != '""'
- not sentinel_piddir.stat.exists

- name: check if sentinel is running
command:
cmd: systemctl status sentinel_{{ redis_sentinel_port }}
ignore_errors: true
changed_when: false
register: sentinel_service_status

- name: run flushconfig to rewrite config file from current configuration
command:
cmd: "redis-cli -p {{ redis_sentinel_port }} SENTINEL FLUSHCONFIG"
when: sentinel_service_status.rc == 0

- name: check if sentinel config file exists
stat:
path: /etc/redis/sentinel_{{ redis_sentinel_port }}.conf
register: _config_file

- name: backup existing config file
copy:
src: /etc/redis/sentinel_{{ redis_sentinel_port }}.conf
dest: /etc/redis/sentinel_{{ redis_sentinel_port }}.conf.{{ ansible_date_time['date'] }}
owner: "{{ redis_user }}"
mode: 0640
remote_src: true
when: _config_file.stat.exists

- name: create sentinel config file
template:
src: redis_sentinel.conf.j2
dest: /etc/redis/sentinel_{{ redis_sentinel_port }}.conf
owner: "{{ redis_user }}"
mode: 0640
notify: "restart sentinel"
when:
- not redis_sentinel_runtime_monitor_master or
not _config_file.stat.exists

- name: update static configuration in config file
blockinfile:
path: /etc/redis/sentinel_{{ redis_sentinel_port }}.conf
insertbefore: "### STATIC CONFIG STOP HERE ###"
owner: "{{ redis_user }}"
mode: 0640
backup: yes
block: |
# redis-sentinel {{ redis_version }} configuration file
# sentinel_{{ redis_sentinel_port }}.conf

daemonize {{ redis_daemonize }}
protected-mode {{ redis_sentinel_protected_mode }}
dir {{ redis_sentinel_dir }}
pidfile {{ redis_sentinel_pidfile }}
port {{ redis_sentinel_port }}
bind {{ redis_sentinel_bind }}
maxclients {{ redis_maxclients }}
timeout {{ redis_timeout }}

# Security
{% if redis_sentinel_password %}
requirepass {{ redis_sentinel_password }}
{% endif %}

{% for master in redis_sentinel_monitors -%}
sentinel monitor {{ master.name }} {{ master.host }} {{ master.port }} {{ master.quorum|d('2') }}
{% for option in ('auth_pass', 'down_after_milliseconds', 'parallel_syncs', 'failover_timeout', 'notification_script', 'client_reconfig_script') -%}
{% if master[option] is defined and master[option] -%}
sentinel {{ option|replace('_', '-') }} {{ master.name }} {{ master[option] }}
{% endif %}
{% endfor -%}
{% if master['rename_commands'] is defined -%}
{% for command in master['rename_commands'] -%}
sentinel rename-command {{ master.name }} {{ command }}
{% endfor -%}
{% endif -%}
{% endfor -%}

logfile {{ redis_sentinel_logfile }}
syslog-enabled {{ redis_syslog_enabled }}
syslog-ident {{ redis_sentinel_syslog_ident }}
syslog-facility {{ redis_syslog_facility }}
notify: "restart sentinel"
when: redis_sentinel_runtime_monitor_master == true

- name: add sentinel init config file
template:
Expand Down
12 changes: 11 additions & 1 deletion templates/redis.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ min-slaves-max-lag {{ redis_min_slaves_max_lag }}
masterauth {{ redis_password }}
{% endif -%}

{% if redis_cluster_enabled %}
# Cluster
cluster-enabled yes
cluster-config-file nodes-{{ redis_port }}.conf
cluster-node-timeout {{ redis_cluster_node_timeout }}
{% if redis_version.split('.') | first | int >= 4 -%}
cluster-slave-no-failover {{ redis_cluster_slave_no_failover }}
{% endif -%}
{% endif -%}

# Security
{% if redis_password -%}
requirepass {{ redis_password }}
Expand Down Expand Up @@ -104,4 +114,4 @@ aof-rewrite-incremental-fsync yes
{% if redis_config_additional|length -%}
# Additional
{{ redis_config_additional -}}
{% endif -%}
{% endif -%}
3 changes: 3 additions & 0 deletions templates/redis_sentinel.conf.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
### STATIC CONFIG START HERE ###
# redis-sentinel {{ redis_version }} configuration file
# sentinel_{{ redis_sentinel_port }}.conf

Expand Down Expand Up @@ -31,3 +32,5 @@ logfile {{ redis_sentinel_logfile }}
syslog-enabled {{ redis_syslog_enabled }}
syslog-ident {{ redis_sentinel_syslog_ident }}
syslog-facility {{ redis_syslog_facility }}

### STATIC CONFIG STOP HERE ###