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:
|
||||
_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
|
||||
ansible.builtin.apt:
|
||||
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:
|
||||
- ansible_facts['distribution'] == "Debian"
|
||||
- apt_update|bool
|
||||
tags:
|
||||
- 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
|
||||
register: _dpkg_configure
|
||||
changed_when: (_dpkg_configure.stdout | default('')) | length > 0
|
||||
failed_when: _dpkg_configure.rc != 0
|
||||
register: common_dpkg_configure
|
||||
changed_when: (common_dpkg_configure.stdout | default('')) | length > 0
|
||||
failed_when: common_dpkg_configure.rc != 0
|
||||
when:
|
||||
- ansible_facts['distribution'] == "Debian"
|
||||
- apt_dpkg_configure|bool
|
||||
@@ -48,7 +59,7 @@
|
||||
- name: (redis-server.yml) Install redis packages (centos / fedora system)
|
||||
ansible.builtin.dnf:
|
||||
name: redis
|
||||
state: latest
|
||||
state: present
|
||||
update_cache: true
|
||||
when:
|
||||
- ansible_facts["os_family"] == "RedHat"
|
||||
@@ -98,31 +109,50 @@
|
||||
|
||||
- name: (redis-server.yml) Check if redis configuration file exists
|
||||
ansible.builtin.stat:
|
||||
path: "{{ _redis_conf }}.ORIG"
|
||||
register: redis_conf_exists
|
||||
path: "{{ common_redis_conf }}.ORIG"
|
||||
register: common_redis_conf_exists
|
||||
tags:
|
||||
- redis-server
|
||||
|
||||
- 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:
|
||||
- redis_conf_exists.stat.exists == False
|
||||
- not common_redis_conf_exists.stat.exists
|
||||
tags:
|
||||
- redis-server
|
||||
|
||||
- name: (redis-server.yml) adjust redis configuration
|
||||
ansible.builtin.lineinfile:
|
||||
dest: "{{ _redis_conf }}"
|
||||
dest: "{{ common_redis_conf }}"
|
||||
regexp: "{{ item.regexp }}"
|
||||
insertafter: "{{ item.insertafter }}"
|
||||
line: "{{ item.key }} {{ item.val }}"
|
||||
state: present
|
||||
loop:
|
||||
- { regexp: "^bind\\s+", key: "bind", val: "127.0.0.1 ::1", insertafter: "^#\\s*bind\\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+" }
|
||||
- regexp: "^bind\\s+"
|
||||
key: "bind"
|
||||
val: "127.0.0.1 ::1"
|
||||
insertafter: "^#\\s*bind\\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"
|
||||
tags:
|
||||
- redis-server
|
||||
|
||||
@@ -23,14 +23,14 @@
|
||||
- shell-config
|
||||
- vim-config
|
||||
|
||||
#- name: (shell.yml) Set default ZSH configuration - file /etc/zsh/zshrc
|
||||
# copy:
|
||||
# src: "{{ item }}"
|
||||
# dest: /etc/zsh/zshrc
|
||||
# owner: root
|
||||
# group: root
|
||||
# mode: '0644'
|
||||
# with_fileglob: "etc/zsh/zshrc"
|
||||
# tags:
|
||||
# - shell-config
|
||||
# - zsh-config
|
||||
# - name: (shell.yml) Set default ZSH configuration - file /etc/zsh/zshrc
|
||||
# copy:
|
||||
# src: "{{ item }}"
|
||||
# dest: /etc/zsh/zshrc
|
||||
# owner: root
|
||||
# group: root
|
||||
# mode: '0644'
|
||||
# with_fileglob: "etc/zsh/zshrc"
|
||||
# tags:
|
||||
# - shell-config
|
||||
# - zsh-config
|
||||
|
||||
Reference in New Issue
Block a user