-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.yml
137 lines (122 loc) · 3.58 KB
/
server.yml
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
---
- name: create redis working directory
file:
path: "{{ redis_dir }}"
state: directory
recurse: yes
owner: "{{ redis_user }}"
- name: create redis init script
template:
src: "{{ item }}"
dest: /etc/init.d/{{ redis_service_name }}
mode: 0755
# Choose the distro-specific template. We must specify the templates
# path here because with_first_found tries to find files in files/
with_first_found:
- files:
- "{{ ansible_os_family }}/redis.init.j2"
- default/redis.init.j2
paths:
- ../templates
when: redis_as_service and ansible_service_mgr|default() != "systemd"
- name: create redis systemd service
template:
src: "{{ item }}"
dest: /etc/systemd/system/{{ redis_service_name }}.service
mode: 0644
with_first_found:
- files:
- "{{ ansible_os_family }}/redis.service.j2"
- default/redis.service.j2
paths:
- ../templates
register: redis_unit_file
when: redis_as_service and ansible_service_mgr|default() == "systemd"
- name: create systemd tmpfiles configuration
template:
src: etc/tmpfiles.d/redis.conf.j2
dest: /etc/tmpfiles.d/redis.conf
mode: 0644
when:
- redis_as_service
- ansible_service_mgr|default() == 'systemd'
- (redis_pidfile|dirname).startswith('/var/run') or (redis_pidfile|dirname).startswith('/run')
- name: reload systemd daemon
command: systemctl daemon-reload
when:
- redis_as_service
- ansible_service_mgr|default() == "systemd"
- redis_unit_file|changed
- name: set redis to start at boot
service:
name: "{{ redis_service_name }}"
enabled: yes
when: redis_as_service
# Check then create log dir to prevent aggressively overwriting permissions
- name: check if log directory exists
stat:
path: "{{ redis_logfile|dirname }}"
register: logdir
changed_when: false
when: redis_logfile != '""'
- name: create log directory if it does not exist
file:
state: directory
path: "{{ redis_logfile|dirname }}"
owner: "{{ redis_user }}"
group: "{{ redis_group }}"
when:
- redis_logfile != '""'
- not logdir.stat.exists
- name: touch the log file
file:
state: touch
path: "{{ redis_logfile }}"
owner: "{{ redis_user }}"
group: "{{ redis_group }}"
when: redis_logfile != '""'
- name: check if pid directory exists
stat:
path: "{{ redis_pidfile|dirname }}"
register: piddir
changed_when: false
when: redis_pidfile != '""'
- name: create pid directory if it does not exist
file:
state: directory
path: "{{ redis_pidfile|dirname }}"
owner: "{{ redis_user }}"
group: "{{ redis_group }}"
when:
- redis_pidfile != '""'
- not piddir.stat.exists
- name: create redis config file
template:
src: redis.conf.j2
dest: /etc/redis/{{ redis_port }}.conf
owner: "{{ redis_user }}"
mode: 0640
notify: "restart redis {{ redis_port }}"
- name: add redis init config file
template:
dest: /etc/sysconfig/{{ redis_service_name }}
src: redis.init.conf.j2
mode: 0600
when: ansible_os_family == "RedHat"
notify: "restart redis {{ redis_port }}"
- name: add redis init config file
template:
dest: /etc/default/{{ redis_service_name }}
src: redis.init.conf.j2
mode: 0600
when: ansible_os_family == "Debian"
notify: "restart redis {{ redis_port }}"
# Flush handlers before ensuring the service is started to prevent
# a start and then restart
- name: flush handlers to apply config changes
meta: flush_handlers
- name: ensure redis is running
service:
name: "{{ redis_service_name }}"
state: started
when: redis_as_service