Refactor Ansible tasks to use fully qualified module names and improve code consistency

- Updated all tasks to use fully qualified module names (e.g., ansible.builtin.shell, ansible.builtin.copy) for clarity and to avoid ambiguity.
- Replaced deprecated 'yum' module with 'dnf' for package management on RedHat-based systems.
- Improved formatting and consistency in task definitions, including the use of double quotes for strings and consistent indentation.
- Removed unnecessary comments and whitespace to enhance readability.
- Ensured that conditions and loops are consistently formatted across all tasks.
This commit is contained in:
2026-07-20 23:09:30 +02:00
parent bc330beebf
commit 81398e847e
33 changed files with 745 additions and 844 deletions
+26 -29
View File
@@ -1,12 +1,11 @@
---
- name: (redis-server.yml) Set var '_redis_conf'
set_fact:
_redis_conf: "{{ '/etc/redis.conf' if ansible_facts['distribution'] == 'CentOS' else '/etc/redis/redis.conf' }}"
ansible.builtin.set_fact:
_redis_conf: "{{ '/etc/redis.conf' if ansible_facts['distribution'] == 'CentOS' else '/etc/redis/redis.conf' }}"
- name: (redis-server.yml) update
apt:
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 }}"
when:
@@ -26,9 +25,8 @@
tags:
- redis-server
- name: (redis-server.yml) upgrade
apt:
ansible.builtin.apt:
upgrade: "{{ apt_upgrade_type }}"
update_cache: true
dpkg_options: "{{ apt_upgrade_dpkg_options | join(',') }}"
@@ -38,9 +36,8 @@
tags:
- redis-server
- name: (redis-server.yml) Install redis-server packages (debian system)
apt:
ansible.builtin.apt:
name: redis-server
state: present
when:
@@ -49,10 +46,10 @@
- redis-server
- name: (redis-server.yml) Install redis packages (centos / fedora system)
yum:
ansible.builtin.dnf:
name: redis
state: latest
update_cache: yes
update_cache: true
when:
- ansible_facts["os_family"] == "RedHat"
- ansible_distribution == "CentOS" or ansible_distribution == "Fedora"
@@ -60,72 +57,72 @@
- redis-server
- name: (redis-server.yml) Determine available users
getent:
ansible.builtin.getent:
database: passwd
tags:
- redis-server
- name: (redis-server.yml) Determine available groups
getent:
ansible.builtin.getent:
database: group
tags:
- redis-server
- name: (redis-server.yml) Add user 'www-data' to group 'redis'
user:
ansible.builtin.user:
name: www-data
groups: redis
append: yes
append: true
when:
- "'www-data' in my_users"
- "'redis' in my_groups"
vars:
my_users: "{{ ansible_facts.getent_passwd.keys()|list }}"
my_groups: "{{ ansible_facts.getent_group.keys()|list }}"
my_users: "{{ ansible_facts.getent_passwd.keys() | list }}"
my_groups: "{{ ansible_facts.getent_group.keys() | list }}"
tags:
- redis-server
- name: (redis-server.yml) Add user 'webadmin' to group 'redis'
user:
ansible.builtin.user:
name: webadmin
groups: redis
append: yes
append: true
when:
- "'webadmin' in my_users"
- "'redis' in my_groups"
vars:
my_users: "{{ ansible_facts.getent_passwd.keys()|list }}"
my_groups: "{{ ansible_facts.getent_group.keys()|list }}"
my_users: "{{ ansible_facts.getent_passwd.keys() | list }}"
my_groups: "{{ ansible_facts.getent_group.keys() | list }}"
tags:
- redis-server
- name: (redis-server.yml) Check if redis configuration file exists
stat:
ansible.builtin.stat:
path: "{{ _redis_conf }}.ORIG"
register: redis_conf_exists
tags:
- redis-server
- name: (redis-server.yml) Backup existing redis configuration file.
command: cp -a "{{ _redis_conf }}" "{{ _redis_conf }}".ORIG
ansible.builtin.command: cp -a "{{ _redis_conf }}" "{{ _redis_conf }}".ORIG
when:
- redis_conf_exists.stat.exists == False
tags:
- redis-server
- name: (redis-server.yml) adjust redis configuration
lineinfile:
- name: (redis-server.yml) adjust redis configuration
ansible.builtin.lineinfile:
dest: "{{ _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