1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# https://redis.io/docs/install/install-redis/install-redis-on-linux/#install-on-ubuntudebian
- name: Set up Redis
hosts: lotus-land-story
tasks:
- name: Add apt key
ansible.builtin.shell: >
curl -fsSL https://packages.redis.io/gpg |
sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
args:
creates: /usr/share/keyrings/redis-archive-keyring.gpg
# ansible.builtin.deb822_repository needs python-debian on the target.
- name: Install required packages
ansible.builtin.apt:
name: python3-debian
state: present
update_cache: true
# Left behind by ansible.builtin.apt_repository; apt reads both formats, so
# leaving it would configure the repository twice.
- name: Remove one-line Redis repository
ansible.builtin.file:
path: /etc/apt/sources.list.d/redis.list
state: absent
- name: Add apt repo
ansible.builtin.deb822_repository:
name: redis
types: deb
uris: https://packages.redis.io/deb
suites: "{{ ansible_facts.distribution_release }}"
components: main
signed_by: /usr/share/keyrings/redis-archive-keyring.gpg
state: present
- name: Install Redis
ansible.builtin.apt:
pkg: redis
state: present
update_cache: true
# TODO Figure out how to de-duplicate this
- name: Save docker_ip
block:
- name: Get docker0 IP address
ansible.builtin.shell: ip -4 -o addr show docker0 | awk '{print $4}' # noqa: risky-shell-pipe
vars:
executable: /usr/bin/bash
register: docker_ip
changed_when: docker_ip.rc != 0
- name: Save docker_ip fact
ansible.builtin.set_fact:
docker_ip:
cidr: "{{ docker_ip.stdout }}"
address: "{{ docker_ip.stdout | ansible.utils.ipaddr('address') }}"
- name: Listen on docker0 interface
ansible.builtin.lineinfile:
dest: /etc/redis/redis.conf
regexp: '^bind 127.0.0.1'
line: "bind 127.0.0.1 {{ docker_ip.address }} -::1"
state: present
notify: Restart redis
# Disable protected mode since we're only allowing access from localhost
# and docker
- name: Un-protect redis
ansible.builtin.lineinfile:
dest: /etc/redis/redis.conf
regexp: '^protected-mode '
line: "protected-mode no"
state: present
notify: Restart redis
handlers:
- name: Import restarts
ansible.builtin.import_tasks: restarts.yml
# vim: ft=yaml.ansible