Skip to content

Commit 0504b21

Browse files
Consolidate Redis roles (#99)
* Consolidate Redis roles * Use handlers in redis role Separate out basic configuration tasks in redis role Fix issue with determining the Redis version when installing from source * Update Redis readme * Remove redis_replication and redis_auth references --------- Co-authored-by: Steven Schattenberg <[email protected]>
1 parent 5389081 commit 0504b21

File tree

18 files changed

+250
-421
lines changed

18 files changed

+250
-421
lines changed

docs/redis_guide.md

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
# Overview
22

3-
The playbook and roles in this section install and configure Redis for the Itential Automation Platform. There are currently three Redis-related roles:
3+
The playbook and role in this section install and configure Redis for the Itential Automation Platform. There is one Redis-related role:
44

5-
* `redis` – Installs Redis and performs a base configuration.
6-
* `redis_auth` – Configures Redis authentication.
7-
* `redis_replication` – Configures Redis replication.
5+
* `redis` – Installs Redis and performs a base configuration. Optionally configures authentication and replication.
86

9-
# Roles
7+
# Redis Role
108

11-
## Redis Role
9+
## Base Install
1210

13-
The `redis` role performs a base install of Redis including any OS packages required. It will compile and install any custom SELinux profiles. It creates the appropriate Linux users, directories, log files, and systemd services. It uses a template to generate a configuration file with some potential features available in other roles commented out. It will start the redis service when complete.
11+
The `redis` role performs a base install of Redis including any OS packages required. It will compile and install any custom SELinux profiles. It creates the appropriate Linux users, directories, log files, and systemd services. It uses a template to generate a configuration file with some potential features available in other roles commented out. It will start the Redis service when complete.
1412

15-
## Redis Auth Role
13+
## Authentication
1614

17-
The `redis_auth` role performs tasks to require authentication (username and password) when communicating with the Redis server. It adjusts the Redis config file and adds each of the required users and applies appropriate ACLs (see table). The "default" Redis user is disabled. It modifies the Redis config file to use the appropriate user while doing replication. It adjusts the Sentinel config file to enable the correct Sentinel user to monitor the redis cluster, if required. It disables the default user in both Redis and Redis Sentinel. It will restart the redis service and the Sentinel service (if required) when complete.
15+
Optionally, the `redis` role performs tasks to require authentication (username and password) when communicating with the Redis server. It adjusts the Redis config file and adds each of the required users and applies appropriate ACLs (see table). The "default" Redis user is disabled. It modifies the Redis config file to use the appropriate user while doing replication. It adjusts the Sentinel config file to enable the correct Sentinel user to monitor the redis cluster, if required. It disables the default user in both Redis and Redis Sentinel.
1816

1917
More info on Redis authorization: https://redis.io/docs/manual/security/
2018

@@ -24,12 +22,13 @@ More info on Redis authorization: https://redis.io/docs/manual/security/
2422
| itential | itential | Has access to all keys, all channels, and all commands except: -asking -cluster -readonly -readwrite -bgrewriteaof -bgsave -failover -flushall -flushdb -psync -replconf -replicaof -save -shutdown -sync
2523
| repluser | repluser | Has access to the minimum set of commands to perform replication.
2624
| sentineluser | sentineluser | Has access to the minimum set of commands to perform sentinel monitoring.
25+
| prometheus | prometheus | Has access to the minimum set of commands to perform Redis and Sentinel monitoring with Prometheus. Required by the optional redis_exporter service.
2726

2827
:::(Warning) (⚠ Warning: ) It is assumed that these default passwords will be changed to meet more rigorous standards. These are intended to be defaults strictly used just for ease of the installation. It is highly recommended that sensitive data be encrypted using Ansible Vault.
2928

30-
## Redis Replication Role
29+
## Replication
3130

32-
The `redis_replication` role performs the steps required to create a Redis replica set. It uses a template to generate a Redis Sentinel config file. It modifies the Redis config file to turn off protected-mode. It assumes that the first host defined in the inventory file is the initial primary. It will update the config file for the non-primary Redis servers to replicate from the primary using hostname. It will restart Redis and Redis Sentinel when complete.
31+
Optionally, the `redis` role performs the steps required to create a Redis replica set. It uses a template to generate a Redis Sentinel config file. It modifies the Redis config file to turn off protected-mode. It assumes that the first host defined in the inventory file is the initial primary. It will update the config file for the non-primary Redis servers to replicate from the primary using hostname. It will start Redis Sentinel when complete.
3332

3433
For more information on Redis replication: https://redis.io/docs/manual/replication/
3534

@@ -57,15 +56,15 @@ The following table lists the default variables that are shared between the Redi
5756

5857
| Variable | Group | Type | Description | Default Value
5958
| :------- | :---- | :--- | :---------- | :------------
60-
| `redis_auth` | `all` | Boolean | Flag to enable Redis authentication. When set to to `true`, the `redis_auth` role will be executed. | `false`
61-
| `redis_replication` | `all` | Boolean | Flag to enable Redis replication. When set to `true`, the `redis_replication` role will be executed. | `false`
59+
| `redis_auth` | `all` | Boolean | Flag to enable Redis authentication. When set to to `true`, Redis authentication will be configured. | `false`
60+
| `redis_replication` | `all` | Boolean | Flag to enable Redis replication. When set to `true`, Redis replication will be configured and the Redis Sentinel service started. | `false`
6261
| `redis_tls` | `all` | Boolean | Flag to enable TLS connections. | `false`
6362

6463
## Redis Role Variables
6564

6665
The variables in this section may be overridden in the inventory in the `redis` group vars.
6766

68-
The following table lists the default variables located in `roles/redis/defaults/main.yml`.
67+
The following table lists the default variables located in `roles/redis/defaults/main/redis.yml` and `roles/redis/defaults/main/sentinel.yml`.
6968

7069
| Variable | Group | Type | Description | Default Value
7170
| :------- | :---- | :--- | :---------- | :------------
@@ -82,23 +81,8 @@ The following table lists the default variables located in `roles/redis/defaults
8281
| `redis_bind_ipv6` | `redis` | Boolean | Flag to enable IPv6. | `true`
8382
| `redis_bind_addr_source` | `redis` | String | The bind address source. Will default to the Ansible `inventory_hostname` unless explicitly set to `default_ipv4_address`. | `inventory_hostname`
8483
| `redis_bind_addrs` | `redis` | String | A space-separated list of hostnames/IP addresses on which Redis listeners will be created. If `redis_bind_ipv6` is set to `true`, `::1` will be added to the addresses. The `redis_bind_addr_source` will also be added to the addresses. | `127.0.0.1`
85-
| `iap_redis_packages` | `redis` | List of Strings | The Linux packages to install. | `redis`<br>`jemalloc`
8684
| `redis_install_method` | `redis` | String | The method to use to install Redis.<br>Set to `remi_repo` to use the Remi repo.<br>Set to `source` to install from source. | `remi_repo`
87-
| `epel_repo_url` | `redis` | String | The URL of the EPEL repo RPM.<br>Note: this is only used when the `redis_install_method` is set to `remi_repo`. | `https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm`
88-
89-
90-
## Redis Auth Role Variables
91-
92-
There are no default variables for the Redis Auth role other than the Redis common default variables.
93-
94-
## Redis Replication Role Variables
95-
96-
The variables in this section may be overridden in the inventory in the `redis` group vars.
97-
98-
The following table lists the default variables located in `roles/redis_replication/defaults/main.yml`.
99-
100-
| Variable | Group | Type | Description | Default Value
101-
| :------- | :---- | :--- | :---------- | :------------
85+
| `redis_epel_repo_url` | `redis` | String | The URL of the EPEL repo RPM.<br>Note: this is only used when the `redis_install_method` is set to `remi_repo`. | `https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm`
10286
| `redis_sentinel_conf_file` | `redis` | String | The location of the Redis Sentinel configuration file. | `{{ redis_conf_path }}/sentinel.conf`
10387
| `redis_sentinel_port` | `redis` | Integer | The Redis Sentinel listen port | `26379`
10488

@@ -165,32 +149,8 @@ all:
165149

166150
# Running the Playbook
167151

168-
To execute all Redis roles, run the `redis` playbook:
152+
To execute the Redis role, run the `redis` playbook:
169153

170154
```
171155
ansible-playbook itential.deployer.redis -i <inventory>
172156
```
173-
174-
You can also run select Redis roles by using the following tags:
175-
176-
* `redis_install`
177-
* `redis_auth`
178-
* `redis_replication`
179-
180-
To execute only the `redis` role (skipping the `redis_auth` and `redis_replication` roles), run the `itential.deployer.redis` playbook with the `redis_install` tag:
181-
182-
```
183-
ansible-playbook itential.deployer.redis -i <inventory> --tags redis_install
184-
```
185-
186-
To execute only the Redis Auth role (skipping the Redis and Redis Replication roles), run the `itential.deployer.redis` playbook with the `redis_auth` tag:
187-
188-
```
189-
ansible-playbook itential.deployer.redis -i <inventory> --tags redis_auth
190-
```
191-
192-
To execute only the Redis Replication role (skipping the Redis and Redis Auth roles), run the `itential.deployer.redis` playbook with the `redis_replication` tag:
193-
194-
```
195-
ansible-playbook itential.deployer.redis -i <inventory> --tags redis_replication
196-
```

playbooks/install_active_standby.yml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,10 @@
66
become: true
77
roles:
88
### REDIS
9-
# Perform a base installation of Redis
9+
# Perform a base installation of Redis and optionally configure authorization and replication
1010
- role: itential.deployer.redis
1111
tags:
1212
- redis
13-
- redis_install
14-
15-
# Perform installation of Redis Sentinel for Redis HA and replication
16-
# https://redis.io/docs/manual/sentinel/
17-
- role: itential.deployer.redis_replication
18-
when: redis_replication | bool
19-
tags:
20-
- redis
21-
- redis_replication
22-
23-
# Configure Redis to require a username & password (authorization)
24-
# https://redis.io/docs/manual/security/acl/
25-
- role: itential.deployer.redis_auth
26-
when: redis_auth | bool
27-
tags:
28-
- redis
29-
- redis_auth
3013

3114
- name: Install RabbitMQ
3215
hosts: rabbitmq, rabbitmq_secondary

playbooks/redis.yml

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,6 @@
88
roles:
99
# Pull in the common vars
1010
- role: itential.deployer.common_vars
11-
tags:
12-
- always
1311

14-
# Perform a base installation of Redis
12+
# Perform a base installation of Redis and optionally configure authorization and replication
1513
- role: itential.deployer.redis
16-
tags:
17-
- redis
18-
- redis_install
19-
20-
# Perform installation of Redis Sentinel for Redis HA and replication
21-
# https://redis.io/docs/manual/sentinel/
22-
- role: itential.deployer.redis_replication
23-
when: redis_replication | bool
24-
tags:
25-
- redis
26-
- redis_replication
27-
28-
# Configure Redis to require a username & password (authorization)
29-
# https://redis.io/docs/manual/security/acl/
30-
- role: itential.deployer.redis_auth
31-
when: redis_auth | bool
32-
tags:
33-
- redis
34-
- redis_auth

roles/redis/defaults/main.yml renamed to roles/redis/defaults/main/redis.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ redis_bind_addr_source: inventory_hostname
3939
# to the redis_bind_addrs depending on the redis_bind_addr_source.
4040
redis_bind_addrs: 127.0.0.1
4141

42-
iap_redis_packages:
43-
- redis
44-
- jemalloc
45-
4642
# Offline install settings
4743
# Refer to the offline variables in common_vars for additional settings
4844
packages_path: "{{ itential_packages_path }}/{{ iap_release }}/redis"
@@ -52,4 +48,4 @@ packages_path: "{{ itential_packages_path }}/{{ iap_release }}/redis"
5248
redis_install_method: source
5349

5450
# The EPEL repo is only required when the redis_install_method is set to 'remi_repo'
55-
epel_repo_url: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm"
51+
redis_epel_repo_url: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm"
File renamed without changes.

roles/redis/handlers/main.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# Copyright (c) 2024, Itential, Inc
22
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
33
---
4-
- name: Restart Redis
4+
- name: Enable and Start Redis
5+
throttle: 1
56
ansible.builtin.systemd:
67
name: redis
78
enabled: true
89
state: restarted
10+
daemon_reload: true
911

10-
- name: Restart Sentinel
12+
- name: Enable and Start Redis Sentinel
13+
throttle: 1
1114
ansible.builtin.systemd:
1215
name: redis-sentinel
1316
enabled: true
1417
state: restarted
18+
daemon_reload: true
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Copyright (c) 2024, Itential, Inc
2+
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
3+
---
4+
# Kernel Adjust
5+
# Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition.
6+
# Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328
7+
- name: Adjust Memory Overcommit
8+
ansible.posix.sysctl:
9+
name: vm.overcommit_memory
10+
value: 1
11+
12+
- name: Install custom SELinux profiles
13+
ansible.builtin.include_role:
14+
name: selinux
15+
tags: configure_selinux
16+
17+
# Check if firewalld is running, if it is then open the appropriate ports
18+
- name: Gather service facts
19+
ansible.builtin.service_facts:
20+
21+
- name: Open Ports on FirewallD Public Zone
22+
ansible.posix.firewalld:
23+
port: "{{ item }}"
24+
permanent: true
25+
state: enabled
26+
zone: public
27+
immediate: true
28+
loop:
29+
- "{{ redis_port }}/tcp"
30+
- "{{ redis_replication | bool | ternary(rabbitmq_mgt_console_port ~ '/tcp', omit) }}"
31+
when:
32+
- ansible_facts.services["firewalld.service"] is defined
33+
- ansible_facts.services["firewalld.service"].state == "running"
34+
- ansible_facts.services["firewalld.service"].status == "enabled"
35+
36+
- name: Create Redis group
37+
ansible.builtin.group:
38+
name: "{{ redis_group }}"
39+
40+
- name: Create Redis user
41+
ansible.builtin.user:
42+
name: "{{ redis_owner }}"
43+
group: "{{ redis_group }}"
44+
state: present
45+
46+
- name: Create Redis data directory
47+
ansible.builtin.file:
48+
state: directory
49+
path: "{{ redis_data_dir }}"
50+
owner: "{{ redis_owner }}"
51+
group: "{{ redis_group }}"
52+
mode: "0755"
53+
when: redis_data_dir != "/var/lib/redis" or redis_install_method == "source"
54+
55+
- name: Create Redis log directory
56+
ansible.builtin.file:
57+
state: directory
58+
path: "{{ redis_log_dir }}"
59+
owner: "{{ redis_owner }}"
60+
group: "{{ redis_group }}"
61+
mode: "0755"
62+
when: redis_log_dir != "/var/log/redis" or redis_install_method == "source"
63+
64+
- name: Create Redis pid directory
65+
ansible.builtin.file:
66+
state: directory
67+
path: "{{ redis_pid_dir }}"
68+
owner: "{{ redis_owner }}"
69+
group: "{{ redis_group }}"
70+
mode: "0755"
71+
when: redis_pid_dir != "/var/run" or redis_install_method == "source"
72+
73+
- name: Create Redis configuration directory
74+
ansible.builtin.file:
75+
path: "{{ redis_conf_path }}"
76+
state: directory
77+
owner: "{{ redis_owner }}"
78+
group: "{{ redis_group }}"
79+
mode: "0760"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2024, Itential, Inc
2+
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
3+
---
4+
- name: Configure Sentinel
5+
notify: Enable and Start Redis Sentinel
6+
block:
7+
- name: Create Redis Sentinel systemd file
8+
ansible.builtin.template:
9+
src: redis-sentinel.service.j2
10+
dest: /usr/lib/systemd/system/redis-sentinel.service
11+
owner: root
12+
group: root
13+
mode: "0644"
14+
15+
- name: Use template to generate sentinel.conf
16+
ansible.builtin.template:
17+
src: sentinel.conf.j2
18+
dest: "{{ redis_sentinel_conf_file }}"
19+
owner: "{{ redis_owner }}"
20+
group: "{{ redis_group }}"
21+
mode: "0640"
22+
backup: true
23+
when:
24+
- groups['redis'] is defined
25+
- inventory_hostname in groups['redis']
26+
vars:
27+
master_name: "{{ hostvars[groups['redis'][0]].inventory_hostname }}"
28+
29+
- name: Use template to generate sentinel.conf for secondary DR
30+
ansible.builtin.template:
31+
src: sentinel.conf.j2
32+
dest: "{{ redis_sentinel_conf_file }}"
33+
owner: "{{ redis_owner }}"
34+
group: "{{ redis_group }}"
35+
mode: "0640"
36+
backup: true
37+
when:
38+
- groups['redis_secondary'] is defined
39+
- inventory_hostname in groups['redis_secondary']
40+
vars:
41+
master_name: "{{ hostvars[groups['redis_secondary'][0]].inventory_hostname }}"

roles/redis/tasks/download-packages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
block:
3131
- name: Install EPEL repo
3232
ansible.builtin.dnf:
33-
name: "{{ epel_repo_url }}"
33+
name: "{{ redis_epel_repo_url }}"
3434
state: present
3535
update_cache: true
3636
disable_gpg_check: true

0 commit comments

Comments
 (0)