mirror of
https://gitea.0xace.cc/ansible-galaxy/redis.git
synced 2025-07-03 04:53:07 +00:00
add redis role
This commit is contained in:
58
tasks/Debian/install.yaml
Normal file
58
tasks/Debian/install.yaml
Normal file
@ -0,0 +1,58 @@
|
||||
---
|
||||
- name: Add gpg keys for redis
|
||||
ansible.builtin.apt_key:
|
||||
url: "{{ item.url }}"
|
||||
keyring: "{{ item.keyring }}"
|
||||
loop: "{{ redis_debian_apt_key }}"
|
||||
|
||||
- name: Enable https transport for apt
|
||||
apt:
|
||||
name: apt-transport-https
|
||||
update_cache: yes
|
||||
|
||||
- name: Add redis.list to sources
|
||||
template:
|
||||
src: "redis.list.j2"
|
||||
dest: /etc/apt/sources.list.d/redis.list
|
||||
|
||||
#- name: Add redis repository from PPA
|
||||
# ansible.builtin.apt_repository:
|
||||
# repo: ppa:redislabs/redis
|
||||
|
||||
- name: Check if redis is installed
|
||||
ansible.builtin.shell: dpkg-query -l {{ redis_debian_package }} 2>&1 | grep {{ redis_debian_version }}
|
||||
ignore_errors: True
|
||||
register: is_redis
|
||||
changed_when: is_redis.rc != 0
|
||||
failed_when: False
|
||||
|
||||
- name: Mask redis before install
|
||||
ansible.builtin.systemd:
|
||||
name: "{{ redis_debian_package }}"
|
||||
masked: yes
|
||||
when: is_redis.rc != 0
|
||||
|
||||
- name: Install redis {{ redis_debian_version }}
|
||||
apt:
|
||||
name: "{{ redis_debian_package }}={{ redis_debian_version }}"
|
||||
update_cache: yes
|
||||
when: is_redis.rc != 0
|
||||
|
||||
- name: Check if redis-sentinel is installed
|
||||
ansible.builtin.shell: dpkg-query -W {{ redis_sentinel_debian_package }} 2>&1 | grep {{ redis_sentinel_debian_version }}
|
||||
ignore_errors: True
|
||||
register: is_redis_sentinel
|
||||
changed_when: is_redis_sentinel.rc != 0
|
||||
failed_when: False
|
||||
|
||||
- name: Mask redis-sentinel before install
|
||||
ansible.builtin.systemd:
|
||||
name: "{{ redis_sentinel_debian_package }}"
|
||||
masked: yes
|
||||
when: is_redis_sentinel.rc != 0
|
||||
|
||||
- name: Install redis-sentinel {{ redis_sentinel_debian_version }}
|
||||
apt:
|
||||
name: "{{ redis_sentinel_debian_package }}={{ redis_sentinel_debian_version }}"
|
||||
update_cache: yes
|
||||
when: is_redis_sentinel != 0
|
5
tasks/configure-sentinel.yaml
Normal file
5
tasks/configure-sentinel.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: Add redis-sentinel config
|
||||
template:
|
||||
src: sentinel.conf.j2
|
||||
dest: "/etc/redis/sentinel.conf"
|
5
tasks/configure.yaml
Normal file
5
tasks/configure.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: Add redis config
|
||||
template:
|
||||
src: redis.conf.j2
|
||||
dest: "/etc/redis/redis.conf"
|
5
tasks/main.yaml
Normal file
5
tasks/main.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
- include: redis.yaml
|
||||
tags:
|
||||
- redis
|
||||
|
50
tasks/redis.yaml
Normal file
50
tasks/redis.yaml
Normal file
@ -0,0 +1,50 @@
|
||||
---
|
||||
- name: Set fact about redis master
|
||||
set_fact:
|
||||
redis_master_ip: "{{ hostvars[inventory_hostname].ansible_default_ipv4.address }}"
|
||||
delegate_to: "{{ item }}"
|
||||
loop: "{{ play_hosts }}"
|
||||
run_once: yes
|
||||
when: hostvars[inventory_hostname].master is defined
|
||||
|
||||
- debug:
|
||||
msg: "{{ redis_master_ip }}"
|
||||
|
||||
- name: Include redis installation tasks
|
||||
include: "{{ ansible_os_family }}/install.yaml"
|
||||
|
||||
- name: Check if redis is running
|
||||
command: systemctl status redis-server
|
||||
ignore_errors: yes
|
||||
changed_when: False
|
||||
register: service_redis_status
|
||||
failed_when: False
|
||||
|
||||
- name: Configure redis
|
||||
include: configure.yaml
|
||||
when: service_redis_status.rc != 0
|
||||
|
||||
- name: Start redis server
|
||||
service:
|
||||
name: redis-server
|
||||
enabled: True
|
||||
state: started
|
||||
masked: no
|
||||
|
||||
- name: Check if redis-sentinel is running
|
||||
command: systemctl status redis-sentinel
|
||||
ignore_errors: yes
|
||||
changed_when: False
|
||||
register: service_redis_sentinel_status
|
||||
failed_when: False
|
||||
|
||||
- name: Configure redis-sentinel
|
||||
include: configure-sentinel.yaml
|
||||
when: service_redis_sentinel_status.rc != 0
|
||||
|
||||
- name: Start redis-sentinel
|
||||
service:
|
||||
name: redis-sentinel
|
||||
enabled: True
|
||||
state: started
|
||||
masked: no
|
Reference in New Issue
Block a user