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
+46 -52
View File
@@ -1,42 +1,42 @@
---
# ---
# Check if local template directories exists
# ---
# default_users
- name: (users-systemfiles.yml) Check if local template directory exists for default users
local_action: stat path={{ inventory_dir }}/files/homedirs/{{ item.name }}
ansible.builtin.stat: path={{ inventory_dir }}/files/homedirs/{{ item.name }}
delegate_to: localhost
with_items: "{{ default_user }}"
loop_control:
label: '{{ item.name }}'
label: "{{ item.name }}"
register: local_template_dir_default_user
# root
- name: (users-systemfiles.yml) Check if local template directory exists for root
local_action: stat path={{ inventory_dir }}/files/homedirs/root
ansible.builtin.stat: path={{ inventory_dir }}/files/homedirs/root
delegate_to: localhost
register: local_template_dir_root
# --
# Copy .bashrc
# ---
- name: (users-systemfiles.yml) Check if users file '.bashrc.ORIG' exists
stat:
ansible.builtin.stat:
path: "~{{ item.name }}/.bashrc.ORIG"
register: bashrc_user_orig_exists
loop: "{{ default_user }}"
loop_control:
label: '{{ item.name }}'
label: "{{ item.name }}"
tags:
- bash
- name: (users-systemfiles.yml) Backup existing users .bashrc file
command: cp -a ~{{ item.item.name }}/.bashrc ~{{ item.item.name }}/.bashrc.ORIG
ansible.builtin.command: cp -a ~{{ item.item.name }}/.bashrc ~{{ item.item.name }}/.bashrc.ORIG
loop: "{{ bashrc_user_orig_exists.results }}"
loop_control:
label: '{{ item.item.name }}'
label: "{{ item.item.name }}"
when: item.stat.exists == False
tags:
- bash
@@ -50,7 +50,7 @@
loop: "{{ default_user }}"
register: bashrc_stats
loop_control:
label: '{{ item.name }}'
label: "{{ item.name }}"
# 2. Falls vorhanden, Datei kopieren
- name: (users-systemfiles.yml) copy .bashrc if it exists
@@ -59,7 +59,7 @@
dest: "~{{ user.name }}/.bashrc"
owner: "{{ user.name }}"
group: "{{ user.name }}"
mode: '0644'
mode: "0644"
loop: "{{ default_user | zip(bashrc_stats.results) | list }}"
loop_control:
label: "{{ user.name }}"
@@ -76,20 +76,20 @@
# --
- name: (users-systemfiles.yml) Check if file '/root/.bashrc.ORIG' exists
stat:
ansible.builtin.stat:
path: /root/.bashrc.ORIG
register: bashrc_root_orig_exists
tags:
- bash
- name: (users-systemfiles.yml) Backup /root/.bashrc file
command: cp /root/.bashrc /root/.bashrc.ORIG
when: bashrc_root_orig_exists.stat.exists == False
ansible.builtin.command: cp /root/.bashrc /root/.bashrc.ORIG
when: bashrc_root_orig_exists.stat.exists == False
tags:
- bash
# 1) Prüfen ob die _bashrc für root auf dem Control-Node existiert
- name: stat root _bashrc on control node
- name: Stat root _bashrc on control node
ansible.builtin.stat:
path: "{{ inventory_dir }}/files/homedirs/root/_bashrc"
delegate_to: localhost
@@ -97,47 +97,45 @@
register: bashrc_root_stat
# 2) Wenn vorhanden, kopieren wir sie nach /root/.bashrc auf dem Zielhost
- name: copy root .bashrc if it exists
- name: Copy root .bashrc if it exists
ansible.builtin.copy:
src: "{{ inventory_dir }}/files/homedirs/root/_bashrc"
dest: /root/.bashrc
owner: root
group: root
mode: '0644'
mode: "0644"
become: true
when: bashrc_root_stat.stat.exists
tags:
- bash
# --
# Copy .profile (Debian System)
# ---
- name: (users-systemfiles.yml) Check if users file '.profile.ORIG' exists
stat:
ansible.builtin.stat:
path: "~{{ item.name }}/.profile.ORIG"
register: profile_user_orig_exists
loop: "{{ default_user }}"
loop_control:
label: '{{ item.name }}'
label: "{{ item.name }}"
when:
- ansible_facts['distribution'] == "Debian"
tags:
- profile
- name: (users-systemfiles.yml) Backup existing users .profile file
command: cp -a ~{{ item.item.name }}/.profile ~{{ item.item.name }}/.profile.ORIG
ansible.builtin.command: cp -a ~{{ item.item.name }}/.profile ~{{ item.item.name }}/.profile.ORIG
loop: "{{ profile_user_orig_exists.results }}"
loop_control:
label: '{{ item.item.name }}'
label: "{{ item.item.name }}"
when:
- ansible_facts['distribution'] == "Debian"
- item.stat.exists == False
tags:
- profile
# 1. Prüfen, ob für jeden User ein lokales _profile existiert
- name: (users-systemfiles.yml) stat user _profile
ansible.builtin.stat:
@@ -147,7 +145,7 @@
loop: "{{ default_user }}"
register: profile_stats
loop_control:
label: '{{ item.name }}'
label: "{{ item.name }}"
# 2. Falls vorhanden, Datei kopieren
- name: (users-systemfiles.yml) copy .profile if it exists
@@ -156,7 +154,7 @@
dest: "~{{ user.name }}/.profile"
owner: "{{ user.name }}"
group: "{{ user.name }}"
mode: '0644'
mode: "0644"
loop: "{{ default_user | zip(profile_stats.results) | list }}"
loop_control:
label: "{{ user.name }}"
@@ -173,7 +171,7 @@
# --
- name: (users-systemfiles.yml) Check if file '/root/.profile.ORIG' exists
stat:
ansible.builtin.stat:
path: /root/.profile.ORIG
register: profile_root_orig_exists
when:
@@ -182,16 +180,15 @@
- profile
- name: (users-systemfiles.yml) Backup existing users .profile file
command: cp -a /root/.profile /root/.profile.ORIG
ansible.builtin.command: cp -a /root/.profile /root/.profile.ORIG
when:
- ansible_facts['distribution'] == "Debian"
- profile_root_orig_exists.stat.exists == False
tags:
- profile
# 1) Prüfen ob die _profile für root auf dem Control-Node existiert
- name: stat root _profile on control node
- name: Stat root _profile on control node
ansible.builtin.stat:
path: "{{ inventory_dir }}/files/homedirs/root/_profile"
delegate_to: localhost
@@ -199,13 +196,13 @@
register: profile_root_stat
# 2) Wenn vorhanden, kopieren wir sie nach /root/.profile auf dem Zielhost
- name: copy root .profile if it exists
- name: Copy root .profile if it exists
ansible.builtin.copy:
src: "{{ inventory_dir }}/files/homedirs/root/_profile"
dest: /root/.profile
owner: root
group: root
mode: '0644'
mode: "0644"
become: true
when: profile_root_stat.stat.exists
tags:
@@ -216,28 +213,27 @@
# ---
- name: (users-systemfiles.yml) Check if users file '.bash_profile.ORIG' exists
stat:
ansible.builtin.stat:
path: "~{{ item.name }}/.bash_profile.ORIG"
register: bash_profile_user_orig_exists
loop: "{{ default_user }}"
loop_control:
label: '{{ item.name }}'
label: "{{ item.name }}"
when:
- ansible_facts['distribution'] == "CentOS"
tags:
- profile
- name: (users-systemfiles.yml) Backup existing users .bash_profile file
command: cp -a ~{{ item.item.name }}/.bash_profile ~{{ item.item.name }}/.bash_profile.ORIG
ansible.builtin.command: cp -a ~{{ item.item.name }}/.bash_profile ~{{ item.item.name }}/.bash_profile.ORIG
loop: "{{ bash_profile_user_orig_exists.results }}"
loop_control:
label: '{{ item.item.name }}'
label: "{{ item.item.name }}"
when:
- ansible_facts['distribution'] == "CentOS"
- item.stat.exists == False
tags:
- profile
# 1. Prüfen, ob für jeden User ein lokales _bash_profile existiert
- name: (users-systemfiles.yml) stat user _bash_profile
@@ -248,7 +244,7 @@
loop: "{{ default_user }}"
register: bash_profile_stats
loop_control:
label: '{{ item.name }}'
label: "{{ item.name }}"
when:
- ansible_facts['distribution'] == "CentOS"
@@ -259,7 +255,7 @@
dest: "~{{ user.name }}/.bash_profile"
owner: "{{ user.name }}"
group: "{{ user.name }}"
mode: '0644'
mode: "0644"
loop: "{{ default_user | zip(bash_profile_stats.results) | list }}"
loop_control:
label: "{{ user.name }}"
@@ -277,7 +273,7 @@
# --
- name: (users-systemfiles.yml) Check if file '/root/.bash_profile.ORIG' exists
stat:
ansible.builtin.stat:
path: /root/.bash_profile.ORIG
register: profile_root_orig_exists
when:
@@ -286,16 +282,15 @@
- profile
- name: (users-systemfiles.yml) Backup existing users .bash_profile file
command: cp -a /root/.bash_profile /root/.bash_profile.ORIG
ansible.builtin.command: cp -a /root/.bash_profile /root/.bash_profile.ORIG
when:
- ansible_facts['distribution'] == "CentOS"
- profile_root_orig_exists.stat.exists == False
tags:
- profile
# 1) Prüfen ob die _bash_profile für root auf dem Control-Node existiert
- name: stat root _bash_profile on control node
- name: Stat root _bash_profile on control node
ansible.builtin.stat:
path: "{{ inventory_dir }}/files/homedirs/root/_bash_profile"
delegate_to: localhost
@@ -305,20 +300,19 @@
- ansible_facts['distribution'] == "CentOS"
# 2) Wenn vorhanden, kopieren wir sie nach /root/.bash_profile auf dem Zielhost
- name: copy root .bash_profile if it exists
- name: Copy root .bash_profile if it exists
ansible.builtin.copy:
src: "{{ inventory_dir }}/files/homedirs/root/_bash_profile"
dest: /root/.bash_profile
owner: root
group: root
mode: '0644'
mode: "0644"
become: true
when:
- ansible_facts['distribution'] == "CentOS"
- bash_profile_root_stat.stat.exists
tags:
- bash
# --
# Copy .vimrc
@@ -333,7 +327,7 @@
loop: "{{ default_user }}"
register: vimrc_stats
loop_control:
label: '{{ item.name }}'
label: "{{ item.name }}"
# 2. Falls vorhanden, Datei kopieren
- name: (users-systemfiles.yml) copy .vimrc if it exists
@@ -342,7 +336,7 @@
dest: "~{{ user.name }}/.vimrc"
owner: "{{ user.name }}"
group: "{{ user.name }}"
mode: '0644'
mode: "0644"
loop: "{{ default_user | zip(vimrc_stats.results) | list }}"
loop_control:
label: "{{ user.name }}"
@@ -371,7 +365,7 @@
# Wichtig: KEINE verschachtelten {{ ... }} im String
src: "{{ inventory_dir }}/files/homedirs/{{ user.name }}/.vim"
dest: "~{{ user.name }}/"
mode: preserve # oder weglassen; 0644 wäre für Verzeichnisse falsch
mode: preserve # oder weglassen; 0644 wäre für Verzeichnisse falsch
become: true
loop: "{{ default_user | zip(dotvim_stats.results) | list }}"
loop_control:
@@ -408,7 +402,7 @@
# --
# 1) Prüfen ob die _vimrc für root auf dem Control-Node existiert
- name: stat root _vimrc on control node
- name: Stat root _vimrc on control node
ansible.builtin.stat:
path: "{{ inventory_dir }}/files/homedirs/root/_vimrc"
delegate_to: localhost
@@ -416,13 +410,13 @@
register: vimrc_root_stat
# 2) Wenn vorhanden, kopieren wir sie nach /root/.vimrc auf dem Zielhost
- name: copy root .vimrc if it exists
- name: Copy root .vimrc if it exists
ansible.builtin.copy:
src: "{{ inventory_dir }}/files/homedirs/root/_vimrc"
dest: /root/.vimrc
owner: root
group: root
mode: '0644'
mode: "0644"
become: true
when:
- vimrc_root_stat.stat.exists
@@ -443,7 +437,7 @@
ansible.builtin.copy:
src: "{{ inventory_dir }}/files/homedirs/root/.vim"
dest: "/root/"
mode: preserve # oder weglassen; nicht 0644 bei Verzeichnissen
mode: preserve # oder weglassen; nicht 0644 bei Verzeichnissen
become: true
when:
- root_dotvim_stat.stat.exists | bool