Ansible roles by Evolix
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
ansible-roles/redis/tasks/instance-server.yml

186 lines
4.8 KiB

---
- name: Verify Redis port
assert:
that:
- redis_port | int != 6379
msg: "If you want to use port 6379, use the default instance, not a named instance."
when: not (redis_force_instance_port | bool)
- name: "Instance '{{ redis_instance_name }}' group is present"
group:
name: "redis-{{ redis_instance_name }}"
state: present
system: True
tags:
- redis
- name: "Instance '{{ redis_instance_name }}' user is present"
user:
name: "redis-{{ redis_instance_name }}"
group: "redis-{{ redis_instance_name }}"
state: present
system: True
shell: '/bin/false'
tags:
- redis
- name: "Instance '{{ redis_instance_name }}' config directory is present"
file:
dest: "{{ redis_conf_dir }}"
mode: "0750"
owner: "redis-{{ redis_instance_name }}"
group: "redis-{{ redis_instance_name }}"
follow: yes
state: directory
tags:
- redis
- name: "Instance '{{ redis_instance_name }}' config hooks directories are present"
file:
dest: "{{ _dir }}"
mode: "0750"
owner: "redis-{{ redis_instance_name }}"
group: "redis-{{ redis_instance_name }}"
follow: yes
state: directory
loop:
- "{{ redis_conf_dir }}/redis-server.pre-up.d"
- "{{ redis_conf_dir }}/redis-server.post-up.d"
- "{{ redis_conf_dir }}/redis-server.pre-down.d"
- "{{ redis_conf_dir }}/redis-server.post-down.d"
loop_control:
loop_var: _dir
when:
- ansible_distribution == "Debian"
- ansible_distribution_major_version is version('9', '=')
tags:
- redis
- name: "Instance '{{ redis_instance_name }}' hooks examples are present"
command: "cp -a /etc/redis/{{ _dir }}/00_example {{ redis_conf_dir }}/{{ _dir }}"
args:
creates: "{{ redis_conf_dir }}/{{ _dir }}/00_example"
loop:
- "redis-server.pre-up.d"
- "redis-server.post-up.d"
- "redis-server.pre-down.d"
- "redis-server.post-down.d"
loop_control:
loop_var: _dir
when:
- ansible_distribution == "Debian"
- ansible_distribution_major_version is version('9', '=')
tags:
- redis
- name: "Instance '{{ redis_instance_name }}' socket/pid directories are present"
file:
dest: "{{ _dir }}"
mode: "0755"
owner: "redis-{{ redis_instance_name }}"
group: "redis-{{ redis_instance_name }}"
follow: yes
state: directory
loop:
- "{{ redis_pid_dir }}"
- "{{ redis_socket_dir }}"
loop_control:
loop_var: _dir
tags:
- redis
- name: "Instance '{{ redis_instance_name }}' data/log directories are present"
file:
dest: "{{ _dir }}"
mode: "0751"
owner: "redis-{{ redis_instance_name }}"
group: "redis-{{ redis_instance_name }}"
follow: yes
state: directory
loop:
- "{{ redis_data_dir }}"
- "{{ redis_log_dir }}"
loop_control:
loop_var: _dir
tags:
- redis
- name: "Instance '{{ redis_instance_name }}' log file are present"
file:
path: "{{ redis_log_dir }}/redis-server.log"
mode: "660"
owner: "redis-{{ redis_instance_name }}"
group: "adm"
state: touch
tags:
- redis
- name: "Instance '{{ redis_instance_name }}' configuration file is present"
template:
src: redis.conf.j2
dest: "{{ redis_conf_dir }}/redis.conf"
mode: "0640"
owner: redis-{{ redis_instance_name }}
group: redis-{{ redis_instance_name }}
notify: "{{ redis_restart_handler_name }}"
tags:
- redis
- name: Systemd template for redis instances is installed (Debian 8)
template:
src: 'redis-server@jessie.service.j2'
dest: '/etc/systemd/system/redis-server@.service'
mode: "0644"
owner: "root"
group: "root"
when:
- ansible_distribution == "Debian"
- ansible_distribution_major_version is version('9', '<')
tags:
- redis
- name: Systemd template for redis instances is installed (Debian 9)
template:
src: 'redis-server@stretch.service.j2'
dest: '/etc/systemd/system/redis-server@.service'
mode: "0644"
owner: "root"
group: "root"
when:
- ansible_distribution == "Debian"
- ansible_distribution_major_version is version('9', '=')
tags:
- redis
- name: Systemd template for redis instances is installed (Debian 10 or later)
template:
src: 'redis-server@buster.service.j2'
dest: '/etc/systemd/system/redis-server@.service'
mode: "0644"
owner: "root"
group: "root"
when:
- ansible_distribution == "Debian"
- ansible_distribution_major_version is version('10', '>=')
tags:
- redis
- name: "Instance '{{ redis_instance_name }}' systemd unit is enabled and started"
systemd:
name: "{{ redis_systemd_name }}"
enabled: yes
state: started
daemon_reload: yes
tags:
- redis
- name: Redis SysVinit script is stopped and disabled
service:
name: "redis-server"
enabled: no
state: stopped
when: redis_default_server_disabled | bool
tags:
- redis