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 -31
View File
@@ -1,5 +1,4 @@
---
# ---
# - default user/groups
# ---
@@ -7,13 +6,13 @@
# To be precise, samba groups are system groups.
#
- name: (samba-user.yml) Ensure samba groups exists
group:
name: '{{ item.name }}'
ansible.builtin.group:
name: "{{ item.name }}"
state: present
gid: '{{ item.group_id | default(omit) }}'
gid: "{{ item.group_id | default(omit) }}"
loop: "{{ samba_groups }}"
loop_control:
label: '{{ item.name }}'
label: "{{ item.name }}"
when: item.group_id is defined
tags:
- samba-server
@@ -26,21 +25,20 @@
# the result ist avalable in variable getent_passwd
#
- name: (samba_user.yml) Get database of (system) users
getent:
ansible.builtin.getent:
database: passwd
tags:
- samba-server
- samba-user
- system-user
# Samba users mut be also system users
#
- name: (samba_user.yml) Add (system) users if not yet exists..
shell: "/root/bin/admin-stuff/add_new_user.sh {{ item.name }} '{{ item.password }}'"
ansible.builtin.command: "/root/bin/admin-stuff/add_new_user.sh {{ item.name }} '{{ item.password }}'"
loop: "{{ samba_user }}"
loop_control:
label: '{{ item.name }}'
label: "{{ item.name }}"
when:
- ansible_facts.getent_passwd is defined
- item.name not in ansible_facts.getent_passwd
@@ -50,57 +48,54 @@
- system-user
- name: (samba_user.yml) Ensure samba users exists in system with given group membership
user:
name: '{{ item.name }}'
ansible.builtin.user:
name: "{{ item.name }}"
state: present
uid: '{{ item.user_id | default(omit) }}'
uid: "{{ item.user_id | default(omit) }}"
#group: '{{ item.0.name | default(omit) }}'
groups: "{{ item.groups|join(', ') }}"
groups: "{{ item.groups | join(', ') }}"
password: "{{ item.password | password_hash('sha512') }}"
update_password: on_create
append: yes
append: true
loop: "{{ samba_user }}"
loop_control:
label: '{{ item.name }}'
label: "{{ item.name }}"
tags:
- samba-server
- samba-user
- system-user
- name: (samba-user.yml) Check if samba user exists
shell: pdbedit -w -L | awk -F":" '{ print $1 }' | grep -e "^{{ item.name }}"
ansible.builtin.shell: pdbedit -w -L | awk -F":" '{ print $1 }' | grep -e "^{{ item.name }}"
register: samba_user_present
changed_when: "samba_user_present.rc == 1"
failed_when: "samba_user_present.rc > 1"
loop: "{{ samba_user }}"
loop_control:
label: '{{ item.name }}'
label: "{{ item.name }}"
tags:
- samba-server
- samba-user
- name: (samba-user.yml) Add user to samba (with system users password)
shell: >
(echo '{{ item.item.password }}'; echo '{{ item.item.password }}')
| smbpasswd -s -a {{ item.item.name }}
ansible.builtin.shell: >
(echo '{{ item.item.password }}'; echo '{{ item.item.password }}') | smbpasswd -s -a {{ item.item.name }}
loop: "{{ samba_user_present.results }}"
when: item.changed
loop_control:
label: '{{ item.item.name }}'
label: "{{ item.item.name }}"
tags:
- samba-server
- samba-user
# Only on fileservers:
# zapata.opp.netz
- name: (samba_user.yml) Check if folder '/data/backup' exists using file module
stat:
ansible.builtin.stat:
path: /data/backup
register: data_backup_dir
when:
when:
- inventory_hostname == 'zapata.opp.netz'
tags:
- samba-server
@@ -108,16 +103,16 @@
- system-user
- name: (samba_user.yml) Ensure folder /data/backup/<user-name> exists for all (samba) users on host zapata
file:
path: '/data/backup/{{ item.name }}'
ansible.builtin.file:
path: "/data/backup/{{ item.name }}"
state: directory
owner: '{{ item.name }}'
group: '{{ item.name }}'
owner: "{{ item.name }}"
group: "{{ item.name }}"
mode: "2770"
loop: "{{ samba_user }}"
loop_control:
label: '{{ item.name }}'
when:
label: "{{ item.name }}"
when:
- inventory_hostname == 'zapata.opp.netz'
- data_backup_dir.stat.isdir is defined and data_backup_dir.stat.isdir
tags: