ansible/roles/redis/tasks/main.yml

101 lines
2.7 KiB
YAML
Raw Permalink Normal View History

---
- name: Install redis
package:
name: redis
state: present
- name: 'Create /var/db/redis-{{ redis_instance }}'
file:
path: '/var/db/redis-{{ redis_instance }}'
state: directory
owner: redis
group: redis
mode: 0700
- name: 'Create /var/run/redis-{{ redis_instance }}'
file:
path: '/var/run/redis-{{ redis_instance }}'
state: directory
owner: redis
group: '{{ redis_client_group }}'
mode: 0750
- name: 'Add /var/log/redis-{{ redis_instance }} to fstab'
mount:
path: /var/log/redis-{{ redis_instance }}
src: tmpfs
fstype: tmpfs
opts: 'rw,size={{ redis_log_size }},mode={{ redis_log_mode }},uid={{ redis_log_uid }},gid={{ redis_log_gid }},late'
state: mounted
- name: 'Create redis-{{ redis_instance }} service directories'
file:
path: '{{ s6_etc_dir }}/service/redis-{{ redis_instance}}{{ item }}'
state: directory
owner: root
group: wheel
mode: 0755
with_items: '{{ redis_service_dirs }}'
notify:
- Reload s6-rc
- 'Restart redis-{{ redis_instance }} log'
- 'Restart redis-{{ redis_instance }}'
- name: 'Generate redis-{{ redis_instance }} service scripts'
template:
dest: '{{ s6_etc_dir }}/service/redis-{{ redis_instance }}{{ item }}'
src: 'redis{{ item }}.j2'
mode: 0555
owner: root
group: wheel
with_items: '{{ redis_service_scripts }}'
notify:
- Reload s6-rc
- 'Restart redis-{{ redis_instance }} log'
- 'Restart redis-{{ redis_instance }}'
- name: 'Generate redis-{{ redis_instance }} service configuration'
copy:
dest: '{{ s6_etc_dir }}/service/redis-{{ redis_instance}}{{ item.name }}'
content: '{{ item.content }}'
mode: 0444
owner: root
group: wheel
loop_control:
label: 'redis-{{ redis_instance }}{{ item.name }} = {{ item.content }}'
notify:
- Reload s6-rc
- 'Restart redis-{{ redis_instance }} log'
- 'Restart redis-{{ redis_instance }}'
with_items: '{{ redis_service_config }}'
- name: 'Configure redis-{{ redis_instance }}'
template:
dest: '/usr/local/etc/redis-{{ redis_instance }}.conf'
src: redis.conf.j2
mode: 0444
owner: root
group: wheel
notify:
- 'Restart redis-{{ redis_instance }}'
- name: Flush handlers
meta: flush_handlers
- name: 'Start redis-{{ redis_instance }}'
command: 'fdmove -c 2 1 s6-rc -l {{ s6_live_dir }} -u -v 2 -t 15000 change redis-{{ redis_instance }}'
register: change
changed_when: change.stdout | length > 0
- name: 'Enable redis-{{ redis_instance }}'
lineinfile:
path: '{{ s6_etc_dir }}/service/enabled/contents'
regexp: "^redis-{{ redis_instance }}$"
line: 'redis-{{ redis_instance }}'
state: present
notify:
- Reload s6-rc
- name: Flush handlers (again)
meta: flush_handlers