fix(redis-server.yml): standardize variable names and improve configuration clarity
This commit is contained in:
@@ -1,24 +1,35 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
- name: (redis-server.yml) Set var '_redis_conf'
|
- name: (redis-server.yml) Set var 'common_redis_conf'
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
_redis_conf: "{{ '/etc/redis.conf' if ansible_facts['distribution'] == 'CentOS' else '/etc/redis/redis.conf' }}"
|
common_redis_conf: >-
|
||||||
|
{{
|
||||||
|
'/etc/redis.conf'
|
||||||
|
if ansible_facts['distribution'] == 'CentOS'
|
||||||
|
else '/etc/redis/redis.conf'
|
||||||
|
}}
|
||||||
|
|
||||||
- name: (redis-server.yml) update
|
- name: (redis-server.yml) update
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
update_cache: true
|
update_cache: true
|
||||||
cache_valid_time: "{{ 0 if apt_config_updated is defined and apt_config_updated.changed else apt_update_cache_valid_time }}"
|
cache_valid_time: >-
|
||||||
|
{{
|
||||||
|
0
|
||||||
|
if apt_config_updated is defined and apt_config_updated.changed
|
||||||
|
else apt_update_cache_valid_time
|
||||||
|
}}
|
||||||
when:
|
when:
|
||||||
- ansible_facts['distribution'] == "Debian"
|
- ansible_facts['distribution'] == "Debian"
|
||||||
- apt_update|bool
|
- apt_update|bool
|
||||||
tags:
|
tags:
|
||||||
- redis-server
|
- redis-server
|
||||||
|
|
||||||
- name: (redis-server.yml) Configure any half-installed packages 'dpkg --configure -a'
|
- name: >-
|
||||||
|
(redis-server.yml) Configure any half-installed packages
|
||||||
|
'dpkg --configure -a'
|
||||||
ansible.builtin.command: dpkg --configure -a
|
ansible.builtin.command: dpkg --configure -a
|
||||||
register: _dpkg_configure
|
register: common_dpkg_configure
|
||||||
changed_when: (_dpkg_configure.stdout | default('')) | length > 0
|
changed_when: (common_dpkg_configure.stdout | default('')) | length > 0
|
||||||
failed_when: _dpkg_configure.rc != 0
|
failed_when: common_dpkg_configure.rc != 0
|
||||||
when:
|
when:
|
||||||
- ansible_facts['distribution'] == "Debian"
|
- ansible_facts['distribution'] == "Debian"
|
||||||
- apt_dpkg_configure|bool
|
- apt_dpkg_configure|bool
|
||||||
@@ -48,7 +59,7 @@
|
|||||||
- name: (redis-server.yml) Install redis packages (centos / fedora system)
|
- name: (redis-server.yml) Install redis packages (centos / fedora system)
|
||||||
ansible.builtin.dnf:
|
ansible.builtin.dnf:
|
||||||
name: redis
|
name: redis
|
||||||
state: latest
|
state: present
|
||||||
update_cache: true
|
update_cache: true
|
||||||
when:
|
when:
|
||||||
- ansible_facts["os_family"] == "RedHat"
|
- ansible_facts["os_family"] == "RedHat"
|
||||||
@@ -98,31 +109,50 @@
|
|||||||
|
|
||||||
- name: (redis-server.yml) Check if redis configuration file exists
|
- name: (redis-server.yml) Check if redis configuration file exists
|
||||||
ansible.builtin.stat:
|
ansible.builtin.stat:
|
||||||
path: "{{ _redis_conf }}.ORIG"
|
path: "{{ common_redis_conf }}.ORIG"
|
||||||
register: redis_conf_exists
|
register: common_redis_conf_exists
|
||||||
tags:
|
tags:
|
||||||
- redis-server
|
- redis-server
|
||||||
|
|
||||||
- name: (redis-server.yml) Backup existing redis configuration file.
|
- name: (redis-server.yml) Backup existing redis configuration file.
|
||||||
ansible.builtin.command: cp -a "{{ _redis_conf }}" "{{ _redis_conf }}".ORIG
|
ansible.builtin.copy:
|
||||||
|
src: "{{ common_redis_conf }}"
|
||||||
|
dest: "{{ common_redis_conf }}.ORIG"
|
||||||
|
remote_src: true
|
||||||
|
mode: preserve
|
||||||
when:
|
when:
|
||||||
- redis_conf_exists.stat.exists == False
|
- not common_redis_conf_exists.stat.exists
|
||||||
tags:
|
tags:
|
||||||
- redis-server
|
- redis-server
|
||||||
|
|
||||||
- name: (redis-server.yml) adjust redis configuration
|
- name: (redis-server.yml) adjust redis configuration
|
||||||
ansible.builtin.lineinfile:
|
ansible.builtin.lineinfile:
|
||||||
dest: "{{ _redis_conf }}"
|
dest: "{{ common_redis_conf }}"
|
||||||
regexp: "{{ item.regexp }}"
|
regexp: "{{ item.regexp }}"
|
||||||
insertafter: "{{ item.insertafter }}"
|
insertafter: "{{ item.insertafter }}"
|
||||||
line: "{{ item.key }} {{ item.val }}"
|
line: "{{ item.key }} {{ item.val }}"
|
||||||
state: present
|
state: present
|
||||||
loop:
|
loop:
|
||||||
- { regexp: "^bind\\s+", key: "bind", val: "127.0.0.1 ::1", insertafter: "^#\\s*bind\\s+" }
|
- regexp: "^bind\\s+"
|
||||||
- { regexp: "^port\\s+", key: "port", val: "6379", insertafter: "^#\\s*port\\s+" }
|
key: "bind"
|
||||||
- { regexp: "^unixsocket\\s+", key: "unixsocket", val: "/run/redis/redis-server.sock", insertafter: "^#\\s*unixsocketperm" }
|
val: "127.0.0.1 ::1"
|
||||||
- { regexp: "^unixsocketperm", key: "unixsocketperm", val: "770", insertafter: "^unixsocket\\s+" }
|
insertafter: "^#\\s*bind\\s+"
|
||||||
- { regexp: "^logfile", key: "logfile", val: "/var/log/redis/redis-server.log", insertafter: "^#\\s+logfile\\s+" }
|
- regexp: "^port\\s+"
|
||||||
|
key: "port"
|
||||||
|
val: "6379"
|
||||||
|
insertafter: "^#\\s*port\\s+"
|
||||||
|
- regexp: "^unixsocket\\s+"
|
||||||
|
key: "unixsocket"
|
||||||
|
val: "/run/redis/redis-server.sock"
|
||||||
|
insertafter: "^#\\s*unixsocketperm"
|
||||||
|
- regexp: "^unixsocketperm"
|
||||||
|
key: "unixsocketperm"
|
||||||
|
val: "770"
|
||||||
|
insertafter: "^unixsocket\\s+"
|
||||||
|
- regexp: "^logfile"
|
||||||
|
key: "logfile"
|
||||||
|
val: "/var/log/redis/redis-server.log"
|
||||||
|
insertafter: "^#\\s+logfile\\s+"
|
||||||
notify: "Restart redis-server"
|
notify: "Restart redis-server"
|
||||||
tags:
|
tags:
|
||||||
- redis-server
|
- redis-server
|
||||||
|
|||||||
Reference in New Issue
Block a user