This commit is contained in:
2025-10-27 23:17:40 +01:00
parent cfcd9c84ff
commit 8a4da8c615
8 changed files with 483 additions and 293 deletions

View File

@@ -10,7 +10,17 @@
[defaults] [defaults]
ansible_managed = *** [ Ansible managed: DO NOT EDIT DIRECTLY ] *** # [DEPRECATION WARNING] 'ansible_managed' used in ansible.cfg
#
# The `ansible_managed` variable can be set just like any other variable, or a different
# variable can be used.
#
# Alternatives: Set the `ansible_managed` variable, or use any custom variable in templates.
#
# This feature will be removed from ansible-core version 2.23.
#
#ansible_managed = *** [ Ansible managed: DO NOT EDIT DIRECTLY ] ***
#gathering = smart #gathering = smart
#fact_caching = jsonfile #fact_caching = jsonfile
#fact_caching_connection = ~/.cache/ #fact_caching_connection = ~/.cache/

View File

@@ -1,5 +1,10 @@
--- ---
ansible_managed: >
*** ANSIBLE MANAGED FILE - DO NOT EDIT ***
This file was generated by {{ ansible_user_id }} on {{ ansible_date_time.iso8601 }}
ansible_python_interpreter: /usr/bin/python3 ansible_python_interpreter: /usr/bin/python3

View File

@@ -259,6 +259,15 @@ remove_nis_users: []
nis_user: nis_user:
- name: ckubu-test
groups:
- amif
- foerderung
- quali
- team
is_samba_user: true
password: '20/cku-bu.test_24%'
- name: chris - name: chris
groups: groups:
- team - team

View File

@@ -162,6 +162,13 @@ nis_user:
is_samba_user: true is_samba_user: true
password: 's2016bp' password: 's2016bp'
- name: buero2
groups:
- intern
- buero
is_samba_user: true
password: 's2025bp2'
- name: chema - name: chema
groups: groups:
- intern - intern

View File

@@ -30,13 +30,11 @@
- apt-webserver-pkgs - apt-webserver-pkgs
- name: (apt.yml) dpkg --configure - name: (apt.yml) Configure any half-installed packages 'dpkg --configure -a'
command: > ansible.builtin.command: dpkg --configure -a
dpkg --configure -a
#args:
# warn: false
changed_when: _dpkg_configure.stdout_lines
register: _dpkg_configure register: _dpkg_configure
changed_when: (_dpkg_configure.stdout | default('')) | length > 0
failed_when: _dpkg_configure.rc != 0
when: apt_dpkg_configure|bool when: apt_dpkg_configure|bool
tags: tags:
- apt-dpkg-configure - apt-dpkg-configure

View File

@@ -51,37 +51,36 @@
tags: tags:
- profile - profile
- name: (nis-user-systemfiles.yml) copy .profile if it exists
copy:
src: "{{ lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/' + item.item.name + '/_profile') }}"
dest: "~{{ item.item.name }}/.profile"
owner: "{{ item.item.name }}"
group: "{{ item.item.name }}"
mode: 0644
loop: "{{ local_template_dir_nis_user.results }}"
loop_control:
label: '{{ item.item.name }}'
when:
- item.stat.exists
- lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/' + item.item.name + '/_profile')
tags:
- profile
- name: (nis-user-systemfiles.yml) copy default .profile if it exists # 1) Für jeden NIS-User prüfen, ob eine lokale _profile existiert
template: - name: (nis-user-systemfiles.yml) stat user _profile
src: "{{ lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/DEFAULT/_profile.j2') }}" ansible.builtin.stat:
dest: "~{{ item.item.name }}/.profile" path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ item.name }}/_profile"
owner: "{{ item.item.name }}" delegate_to: localhost
group: "{{ item.item.name }}" become: false
mode: 0644 loop: "{{ nis_user }}"
loop: "{{ local_template_dir_nis_user.results }}" register: profile_stats
loop_control: loop_control:
label: '{{ item.item.name }}' label: "{{ item.name }}"
# 2) Falls NIS-User _profile vorhanden, kopieren
- name: (nis-user-systemfiles.yml) copy .profile if it exists
ansible.builtin.copy:
src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ user.name }}/_profile"
dest: "~{{ user.name }}/.profile"
owner: "{{ user.name }}"
group: "{{ user.name }}"
mode: "0644"
become: true
loop: "{{ nis_user | zip(profile_stats.results) | list }}"
loop_control:
label: "{{ user.name }}"
when: when:
- item.stat.exists == false - stat_result.stat.exists | bool
- lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/DEFAULT/_profile.j2') vars:
tags: user: "{{ item.0 }}"
- profile stat_result: "{{ item.1 }}"
tags: [bash]
# -- # --
@@ -107,92 +106,118 @@
tags: tags:
- bashrc - bashrc
- name: (nis-user-systemfiles.yml) copy .bashrc if it exists # 1) Für jeden NIS-User prüfen, ob eine lokale _bashrc existiert
copy: - name: (system-user-systemfiles.yml) stat user _bashrc
src: "{{ lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/' + item.item.name + '/_bashrc') }}" ansible.builtin.stat:
dest: "~{{ item.item.name }}/.bashrc" path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ item.name }}/_bashrc"
owner: "{{ item.item.name }}" delegate_to: localhost
group: "{{ item.item.name }}" become: false
mode: 0644 loop: "{{ nis_user }}"
loop: "{{ local_template_dir_nis_user.results }}" register: bashrc_stats
loop_control: loop_control:
label: '{{ item.item.name }}' label: "{{ item.name }}"
when:
- item.stat.exists
- lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/' + item.item.name + '/_bashrc')
tags:
- bashrc
- name: (nis-user-systemfiles.yml) copy default .bashrc if it exists # 2) Falls User _bashrc vorhanden, kopieren
copy: - name: (system-user-systemfiles.yml) copy .bashrc if it exists
src: "{{ 'files/' + nis_domain + '/homedirs/DEFAULT/_bashrc' }}" ansible.builtin.copy:
dest: "~{{ item.item.name }}/.bashrc" src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ user.name }}/_bashrc"
owner: "{{ item.item.name }}" dest: "~{{ user.name }}/.bashrc"
group: "{{ item.item.name }}" owner: "{{ user.name }}"
mode: 0644 group: "{{ user.name }}"
loop: "{{ local_template_dir_nis_user.results }}" mode: "0644"
become: true
loop: "{{ nis_user | zip(bashrc_stats.results) | list }}"
loop_control: loop_control:
label: '{{ item.item.name }}' label: "{{ user.name }}"
when: when:
- item.stat.exists == false - stat_result.stat.exists | bool
tags: vars:
- bashrc user: "{{ item.0 }}"
stat_result: "{{ item.1 }}"
tags: [bash]
# -- # --
# Copy .vimrc # Copy .vimrc
# --- # ---
- name: (nis-user-systemfiles.yml) copy .vimrc if it exists # 1. Prüfen, ob für jeden User ein lokales _vimrc existiert
copy: - name: (system-user-systemfiles.yml) stat user _vimrc
src: "{{ lookup('fileglob', inventory_dir + '/files/homedirs/' + item.item.name + '/_vimrc') }}" ansible.builtin.stat:
dest: "~{{ item.item.name }}/.vimrc" path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ item.name }}/_vimrc"
owner: "{{ item.item.name }}" delegate_to: localhost
group: "{{ item.item.name }}" become: false
mode: 0644 loop: "{{ nis_user }}"
loop: "{{ local_template_dir_nis_user.results }}" register: vimrc_stats
loop_control:
label: '{{ item.item.name }}'
when:
- item.stat.exists
- lookup('fileglob', inventory_dir + '/files/homedirs/' + item.item.name + '/_vimrc')
tags:
- vimrc
- name: (nis-user-systemfiles.yml) Check if .vim directory exists for default users
local_action: stat path={{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ item.name }}/.vim
with_items: "{{ nis_user }}"
loop_control: loop_control:
label: '{{ item.name }}' label: '{{ item.name }}'
register: local_template_dir_dotvim_default_user
- name: (nis-user-systemfiles.yml) copy .vim directory if it exists # 2. Falls vorhanden, Datei kopieren
copy: - name: (system-user-systemfiles.yml) copy .vimrc if it exists
src: "{{ inventory_dir + '/files/' + nis_domain + '/homedirs/' + item.item.name + '/.vim' }}" ansible.builtin.copy:
dest: "~{{ item.item.name }}" src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ user.name }}/_vimrc"
owner: "{{ item.item.name }}" dest: "~{{ user.name }}/.vimrc"
group: "{{ item.item.name }}" owner: "{{ user.name }}"
mode: 0644 group: "{{ user.name }}"
with_items: "{{ local_template_dir_dotvim_default_user.results }}" mode: '0644'
loop: "{{ nis_user | zip(vimrc_stats.results) | list }}"
loop_control: loop_control:
label: '{{ item.item.name }}' label: "{{ user.name }}"
when: when:
- item.stat.exists - stat_result.stat.exists
vars:
user: "{{ item.0 }}"
stat_result: "{{ item.1 }}"
tags: tags:
- vimrc - bash
- name: (nis-user-systemfiles.yml) copy default .vimrc if it exists
copy: # 1) Lokal prüfen, ob ~/.vim existiert
src: "{{ 'files/' + nis_domain + '/homedirs/DEFAULT/_vimrc' }}" - name: (system-user-systemfiles.yml) stat local .vim for each user
dest: "~{{ item.item.name }}/.vimrc" ansible.builtin.stat:
owner: "{{ item.item.name }}" path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ item.name }}/.vim"
group: "{{ item.item.name }}" delegate_to: localhost
mode: 0644 become: false
loop: "{{ local_template_dir_nis_user.results }}" loop: "{{ nis_user }}"
register: dotvim_stats
loop_control: loop_control:
label: '{{ item.item.name }}' label: "{{ item.name }}"
when:
- item.stat.exists == false # 2) Wenn vorhanden, .vim-Verzeichnis ins Home des Users kopieren
tags: - name: (system-user-systemfiles.yml) copy .vim directory if it exists
- vimrc ansible.builtin.copy:
# Wichtig: KEINE verschachtelten {{ ... }} im String
src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ user.name }}/.vim"
dest: "~{{ user.name }}/"
mode: preserve # oder weglassen; 0644 wäre für Verzeichnisse falsch
become: true
loop: "{{ nis_user | zip(dotvim_stats.results) | list }}"
loop_control:
label: "{{ user.name }}"
when:
- stat_result.stat.exists | bool
vars:
user: "{{ item.0 }}"
stat_result: "{{ item.1 }}"
tags: [vim]
# 3) Ownership/Gruppe rekursiv korrigieren (falls gewünscht/erforderlich)
- name: (system-user-systemfiles.yml) ensure ownership on ~/.vim recursively
ansible.builtin.file:
path: "~{{ user.name }}/.vim"
owner: "{{ user.name }}"
group: "{{ user.name }}"
recurse: true
state: directory
become: true
loop: "{{ nis_user | zip(dotvim_stats.results) | list }}"
loop_control:
label: "{{ user.name }}"
when:
- stat_result.stat.exists | bool
vars:
user: "{{ item.0 }}"
stat_result: "{{ item.1 }}"
tags: [vim]

View File

@@ -107,76 +107,73 @@
- samba-server - samba-server
- name: (samba-install.yml) Check if cleaning up trash dirs is configured - name: (samba-config-server.yml) Check if cleaning up trash dirs is configured
lineinfile: ansible.builtin.lineinfile:
path: /root/bin/samba/conf/clean_samba_trash.conf path: /root/bin/samba/conf/clean_samba_trash.conf
regexp: "^trash_dirs=*" regexp: '^trash_dirs=*'
state: absent state: absent
check_mode: yes check_mode: true
changed_when: false changed_when: false
register: clean_samba_trash_dirs register: clean_samba_trash_dirs
when: when:
- "groups['samba_server']|string is search(inventory_hostname)" - inventory_hostname in groups['samba_server']
tags: tags: [samba-server, samba-cron]
- samba-server
- name: (samba-install.yml) Creates a cron job for cleaning up samba trash dirs - name: (samba-config-server.yml) Creates a cron job for cleaning up samba trash dirs
cron: ansible.builtin.cron:
name: '{{ samba_cronjob_trash_dirs.name }}' name: "{{ samba_cronjob_trash_dirs.name }}"
minute: '{{ samba_cronjob_trash_dirs.minute }}' minute: "{{ samba_cronjob_trash_dirs.minute }}"
hour: "{{ samba_cronjob_trash_dirs.hour | default('*') }}" hour: "{{ samba_cronjob_trash_dirs.hour | default('*') }}"
day: "{{ samba_cronjob_trash_dirs.hour.day | default('*') }}" day: "{{ samba_cronjob_trash_dirs.day | default('*') }}"
month: "{{ samba_cronjob_trash_dirs.hour.month| default('*') }}" month: "{{ samba_cronjob_trash_dirs.month | default('*') }}"
weekday: "{{ samba_cronjob_trash_dirs.hour.weekday| default('*') }}" weekday: "{{ samba_cronjob_trash_dirs.weekday | default('*') }}"
user: "{{ samba_cronjob_trash_dirs.user | default('root') }}" user: "{{ samba_cronjob_trash_dirs.user | default('root') }}"
job: "{{ samba_cronjob_trash_dirs.job }}" job: "{{ samba_cronjob_trash_dirs.job }}"
when: when:
- "groups['samba_server']|string is search(inventory_hostname)" - inventory_hostname in groups['samba_server']
- clean_samba_trash_dirs.found - clean_samba_trash_exists.stat.exists | bool
tags: - (clean_samba_trash_dirs.found | int) > 0
- samba-server tags: [samba-server, samba-cron]
# --- # ---
# Cronjob for setting permissions on samba shares # Cronjob for setting permissions on samba shares
# --- # ---
- name: (samba-install.yml) Check if file '/root/bin/samba/set_permissions_samba_shares.sh' exists - name: (samba-config-server.yml) Check if file '/root/bin/samba/set_permissions_samba_shares.sh' exists
stat: ansible.builtin.stat:
path: /root/bin/samba/set_permissions_samba_shares.sh path: /root/bin/samba/set_permissions_samba_shares.sh
register: set_permissions_on_samba_shares_exists register: set_permissions_on_samba_shares_exists
when: when:
- "groups['samba_server']|string is search(inventory_hostname)" - inventory_hostname in groups['samba_server']
tags: tags: [samba-server, samba-cron]
- samba-server
- name: (samba-install.yml) Adjust configuration for script 'set_permissions_samba_shares.sh'
template: - name: (samba-config-server.yml) Adjust configuration for script 'set_permissions_samba_shares.sh'
ansible.builtin.template:
dest: /root/bin/samba/conf/set_permissions_samba_shares.conf dest: /root/bin/samba/conf/set_permissions_samba_shares.conf
src: root/bin/samba/conf/set_permissions_samba_shares.conf.j2 src: root/bin/samba/conf/set_permissions_samba_shares.conf.j2
when: when:
- "groups['samba_server']|string is search(inventory_hostname)" - inventory_hostname in groups['samba_server']
- set_permissions_on_samba_shares_exists.stat.exists|bool - set_permissions_on_samba_shares_exists.stat.exists | bool
tags: tags: [samba-server, samba-cron]
- samba-server
- name: (samba-install.yml) Creates a cron job for cleaning up samba trash dirs - name: (samba-config-server.yml) Creates a cron job for setting permissions to samba dirs
cron: ansible.builtin.cron:
name: '{{ samba_cronjob_permissions.name }}' name: "{{ samba_cronjob_permissions.name }}"
minute: '{{ samba_cronjob_permissions.minute }}' minute: "{{ samba_cronjob_permissions.minute }}"
hour: "{{ samba_cronjob_permissions.hour | default('*') }}" hour: "{{ samba_cronjob_permissions.hour | default('*') }}"
day: "{{ samba_cronjob_permissions.day | default('*') }}" day: "{{ samba_cronjob_permissions.day | default('*') }}"
month: "{{ samba_cronjob_permissions.month| default('*') }}" month: "{{ samba_cronjob_permissions.month | default('*') }}"
weekday: "{{ samba_cronjob_permissions.weekday| default('*') }}" weekday: "{{ samba_cronjob_permissions.weekday | default('*') }}"
user: "{{ samba_cronjob_permissions.user | default('root') }}" user: "{{ samba_cronjob_permissions.user | default('root') }}"
job: "{{ samba_cronjob_permissions.job }}" job: "{{ samba_cronjob_permissions.job }}"
when: when:
- "groups['samba_server']|string is search(inventory_hostname)" - inventory_hostname in groups['samba_server']
- clean_samba_trash_dirs.found - (clean_samba_trash_dirs.found | int) > 0 # << int -> bool
tags: tags: [samba-server, samba-cron]
- samba-server
# --- # ---

View File

@@ -42,64 +42,102 @@
tags: tags:
- profile - profile
# 1) Für jeden User prüfen, ob eine lokale _profile existiert
- name: (system-user-systemfiles.yml) stat user _profile
ansible.builtin.stat:
path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ item.name }}/_profile"
delegate_to: localhost
become: false
loop: "{{ default_user }}"
register: profile_stats
loop_control:
label: "{{ item.name }}"
# 2) Prüfe ob eine lokale default _baschrc existiert
- name: stat DEFAULT _profile
ansible.builtin.stat:
path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/DEFAULT/_profile"
delegate_to: localhost
become: false
register: default_profile_stat
# 2) Falls User _profile vorhanden, kopieren
- name: (system-user-systemfiles.yml) copy .profile if it exists - name: (system-user-systemfiles.yml) copy .profile if it exists
copy: ansible.builtin.copy:
src: "{{ lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/' + item.item.name + '/_profile') }}" src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ user.name }}/_profile"
dest: "~{{ item.item.name }}/.profile" dest: "~{{ user.name }}/.profile"
owner: "{{ item.item.name }}" owner: "{{ user.name }}"
group: "{{ item.item.name }}" group: "{{ user.name }}"
mode: 0644 mode: "0644"
loop: "{{ local_template_dir_system_users.results }}" become: true
loop: "{{ default_user | zip(profile_stats.results) | list }}"
loop_control: loop_control:
label: '{{ item.item.name }}' label: "{{ user.name }}"
when: when:
- item.stat.exists - stat_result.stat.exists | bool
- lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/' + item.item.name + '/_profile') vars:
tags: user: "{{ item.0 }}"
- profile stat_result: "{{ item.1 }}"
tags: [bash]
- name: (system-user-systemfiles.yml) copy default .profile if it exists # 3) Falls nicht vorhanden, DEFAULT nutzen
template: - name: (system-user-systemfiles.yml) copy default .profile
src: files/{{ nis_domain }}/homedirs/DEFAULT/_profile ansible.builtin.copy:
dest: "~{{ item.item.name }}/.profile" src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/DEFAULT/_profile"
owner: "{{ item.item.name }}" dest: "~{{ user.name }}/.profile"
group: "{{ item.item.name }}" owner: "{{ user.name }}"
mode: 0644 group: "{{ user.name }}"
loop: "{{ local_template_dir_system_users.results }}" mode: "0644"
become: true
loop: "{{ default_user | zip(profile_stats.results) | list }}"
loop_control: loop_control:
label: '{{ item.item.name }}' label: "{{ user.name }}"
when: when:
- item.stat.exists == false - not stat_result.stat.exists
- lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/DEFAULT/_profile') - default_profile_stat.stat.exists | bool
tags: vars:
- profile user: "{{ item.0 }}"
stat_result: "{{ item.1 }}"
tags: [bash]
# ---
# -- root user # -- root user
# ---
- name: (system-user-systemfiles.yml) Check if file '/root/.profile.ORIG' exists - name: (system-user-systemfiles.yml) Check if file '/root/.profile.ORIG' exists
stat: stat:
path: /root/.profile.ORIG path: /root/.profile.ORIG
register: profile_root_orig_exists register: profile_root_orig_exists
tags: tags:
- profile - bash
- name: (system-user-systemfiles.yml) Backup existing users .profile file - name: (system-user-systemfiles.yml) Backup /root/.profile file
command: cp -a /root/.profile /root/.profile.ORIG command: cp /root/.profile /root/.profile.ORIG
when: profile_root_orig_exists.stat.exists == False when: profile_root_orig_exists.stat.exists == False
tags: tags:
- profile - bash
- name: (system-user-systemfiles.yml) copy .profile for user root # 1) Prüfen ob die _profile für root auf dem Control-Node existiert
copy: - name: (system-user-systemfiles.yml) stat root _profile on control node
src: "{{ lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/root/_profile') }}" ansible.builtin.stat:
dest: "/root/.profile" path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/root/_profile"
delegate_to: localhost
become: false
register: profile_root_stat
# 2) Wenn vorhanden, kopieren wir sie nach /root/.profile auf dem Zielhost
- name: copy root .profile if it exists
ansible.builtin.copy:
src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/root/_profile"
dest: /root/.profile
owner: root owner: root
group: root group: root
mode: 0644 mode: '0644'
when: become: true
- local_template_dir_root.stat.exists when: profile_root_stat.stat.exists
- lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/root/_profile')
tags: tags:
- profile - bash
# -- # --
# Copy .bashrc # Copy .bashrc
@@ -124,38 +162,68 @@
tags: tags:
- bashrc - bashrc
# 1) Für jeden User prüfen, ob eine lokale _bashrc existiert
- name: (system-user-systemfiles.yml) stat user _bashrc
ansible.builtin.stat:
path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ item.name }}/_bashrc"
delegate_to: localhost
become: false
loop: "{{ default_user }}"
register: bashrc_stats
loop_control:
label: "{{ item.name }}"
# 2) Prüfe ob eine lokale default _baschrc existiert
- name: stat DEFAULT _bashrc
ansible.builtin.stat:
path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/DEFAULT/_bashrc"
delegate_to: localhost
become: false
register: default_bashrc_stat
# 2) Falls User _bashrc vorhanden, kopieren
- name: (system-user-systemfiles.yml) copy .bashrc if it exists - name: (system-user-systemfiles.yml) copy .bashrc if it exists
copy: ansible.builtin.copy:
src: "{{ lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/' + item.item.name + '/_bashrc') }}" src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ user.name }}/_bashrc"
dest: "~{{ item.item.name }}/.bashrc" dest: "~{{ user.name }}/.bashrc"
owner: "{{ item.item.name }}" owner: "{{ user.name }}"
group: "{{ item.item.name }}" group: "{{ user.name }}"
mode: 0644 mode: "0644"
loop: "{{ local_template_dir_system_users.results }}" become: true
loop: "{{ default_user | zip(bashrc_stats.results) | list }}"
loop_control: loop_control:
label: '{{ item.item.name }}' label: "{{ user.name }}"
when: when:
- item.stat.exists - stat_result.stat.exists | bool
- lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/' + item.item.name + '/_bashrc') vars:
tags: user: "{{ item.0 }}"
- bashrc stat_result: "{{ item.1 }}"
tags: [bash]
- name: (system-user-systemfiles.yml) copy default .bashrc if it exists # 3) Falls nicht vorhanden, DEFAULT nutzen
copy: - name: (system-user-systemfiles.yml) copy default .bashrc
src: files/homedirs/DEFAULT/_bashrc ansible.builtin.copy:
dest: "~{{ item.item.name }}/.bashrc" src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/DEFAULT/_bashrc"
owner: "{{ item.item.name }}" dest: "~{{ user.name }}/.bashrc"
group: "{{ item.item.name }}" owner: "{{ user.name }}"
mode: 0644 group: "{{ user.name }}"
loop: "{{ local_template_dir_system_users.results }}" mode: "0644"
become: true
loop: "{{ default_user | zip(bashrc_stats.results) | list }}"
loop_control: loop_control:
label: '{{ item.item.name }}' label: "{{ user.name }}"
when: when:
- item.stat.exists == false - not stat_result.stat.exists
tags: - default_bashrc_stat.stat.exists | bool
- bashrc vars:
user: "{{ item.0 }}"
stat_result: "{{ item.1 }}"
tags: [bash]
# ---
# -- root user # -- root user
# ---
- name: (system-user-systemfiles.yml) Check if file '/root/.bashrc.ORIG' exists - name: (system-user-systemfiles.yml) Check if file '/root/.bashrc.ORIG' exists
stat: stat:
path: /root/.bashrc.ORIG path: /root/.bashrc.ORIG
@@ -169,16 +237,24 @@
tags: tags:
- bash - bash
- name: (system-user-systemfiles.yml) copy .bashrc for user root # 1) Prüfen ob die _bashrc für root auf dem Control-Node existiert
copy: - name: stat root _bashrc on control node
src: "{{ lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/root/_bashrc') }}" ansible.builtin.stat:
dest: "/root/.bashrc" path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/root/_bashrc"
delegate_to: localhost
become: false
register: bashrc_root_stat
# 2) Wenn vorhanden, kopieren wir sie nach /root/.bashrc auf dem Zielhost
- name: copy root .bashrc if it exists
ansible.builtin.copy:
src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/root/_bashrc"
dest: /root/.bashrc
owner: root owner: root
group: root group: root
mode: 0644 mode: '0644'
when: become: true
- local_template_dir_root.stat.exists when: bashrc_root_stat.stat.exists
- lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/root/_bashrc')
tags: tags:
- bash - bash
@@ -186,93 +262,156 @@
# Copy .vimrc # Copy .vimrc
# --- # ---
- name: (system-user-systemfiles.yml) copy .vimrc if it exists # 1. Prüfen, ob für jeden User ein lokales _vimrc existiert
copy: - name: (system-user-systemfiles.yml) stat user _vimrc
src: "{{ lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/' + item.item.name + '/_vimrc') }}" ansible.builtin.stat:
dest: "~{{ item.item.name }}/.vimrc" path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ item.name }}/_vimrc"
owner: "{{ item.item.name }}" delegate_to: localhost
group: "{{ item.item.name }}" become: false
mode: 0644 loop: "{{ default_user }}"
loop: "{{ local_template_dir_system_users.results }}" register: vimrc_stats
loop_control:
label: '{{ item.item.name }}'
when:
- item.stat.exists
- lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/' + item.item.name + '/_vimrc')
tags:
- vimrc
- name: (system-user-systemfiles.yml) Check if .vim directory exists for default users
local_action: stat path={{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ item.name }}/.vim
with_items: "{{ system_users }}"
loop_control: loop_control:
label: '{{ item.name }}' label: '{{ item.name }}'
register: local_template_dir_dotvim_default_user
# 2. Falls vorhanden, Datei kopieren
- name: (system-user-systemfiles.yml) copy .vimrc if it exists
ansible.builtin.copy:
src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ user.name }}/_vimrc"
dest: "~{{ user.name }}/.vimrc"
owner: "{{ user.name }}"
group: "{{ user.name }}"
mode: '0644'
loop: "{{ default_user | zip(vimrc_stats.results) | list }}"
loop_control:
label: "{{ user.name }}"
when:
- stat_result.stat.exists
vars:
user: "{{ item.0 }}"
stat_result: "{{ item.1 }}"
tags:
- bash
# 1) Lokal prüfen, ob ~/.vim existiert
- name: (system-user-systemfiles.yml) stat local .vim for each user
ansible.builtin.stat:
path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ item.name }}/.vim"
delegate_to: localhost
become: false
loop: "{{ default_user }}"
register: dotvim_stats
loop_control:
label: "{{ item.name }}"
# 2) Wenn vorhanden, .vim-Verzeichnis ins Home des Users kopieren
- name: (system-user-systemfiles.yml) copy .vim directory if it exists - name: (system-user-systemfiles.yml) copy .vim directory if it exists
copy: ansible.builtin.copy:
src: "{{ inventory_dir + '/files/' + nis_domain + '/homedirs/' + item.item.name + '/.vim' }}" # Wichtig: KEINE verschachtelten {{ ... }} im String
dest: "~{{ item.item.name }}" src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ user.name }}/.vim"
owner: "{{ item.item.name }}" dest: "~{{ user.name }}/"
group: "{{ item.item.name }}" mode: preserve # oder weglassen; 0644 wäre für Verzeichnisse falsch
mode: 0644 become: true
with_items: "{{ local_template_dir_dotvim_default_user.results }}" loop: "{{ default_user | zip(dotvim_stats.results) | list }}"
loop_control: loop_control:
label: '{{ item.item.name }}' label: "{{ user.name }}"
when: when:
- item.stat.exists - stat_result.stat.exists | bool
tags: vars:
- vimrc user: "{{ item.0 }}"
stat_result: "{{ item.1 }}"
tags: [vim]
- name: (system-user-systemfiles.yml) copy default .vimrc if it exists
copy: # 3) Ownership/Gruppe rekursiv korrigieren (falls gewünscht/erforderlich)
src: files/homedirs/DEFAULT/_vimrc - name: (system-user-systemfiles.yml) ensure ownership on ~/.vim recursively
dest: "~{{ item.item.name }}/.vimrc" ansible.builtin.file:
owner: "{{ item.item.name }}" path: "~{{ user.name }}/.vim"
group: "{{ item.item.name }}" owner: "{{ user.name }}"
mode: 0644 group: "{{ user.name }}"
loop: "{{ local_template_dir_system_users.results }}" recurse: true
state: directory
become: true
loop: "{{ default_user | zip(dotvim_stats.results) | list }}"
loop_control: loop_control:
label: '{{ item.item.name }}' label: "{{ user.name }}"
when: when:
- item.stat.exists == false - stat_result.stat.exists | bool
tags: vars:
- vimrc user: "{{ item.0 }}"
stat_result: "{{ item.1 }}"
tags: [vim]
- name: (system-user-systemfiles.yml) copy .vimrc for user root # --
copy: # -- root user
src: "{{ lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/root/_vimrc') }}" # --
dest: "/root/.vimrc"
# 1) Prüfen ob die _vimrc für root auf dem Control-Node existiert
- name: (system-user-systemfiles.yml) stat root _vimrc on control node
ansible.builtin.stat:
path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/root/_vimrc"
delegate_to: localhost
become: false
register: vimrc_root_stat
# 2) Wenn vorhanden, kopieren wir sie nach /root/.vimrc auf dem Zielhost
- name: (system-user-systemfiles.yml)copy root .vimrc if it exists
ansible.builtin.copy:
src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/root/_vimrc"
dest: /root/.vimrc
owner: root owner: root
group: root group: root
mode: 0644 mode: '0644'
become: true
when: when:
- local_template_dir_root.stat.exists - vimrc_root_stat.stat.exists
- lookup('fileglob', inventory_dir + '/files/' + nis_domain + '/homedirs/root/_vimrc')
tags: tags:
- vimrc - bash
- name: (system-user-systemfiles.yml) Check if local template directory .vim exists for user root # 1) Lokal prüfen, ob ./files/{{ nis_domain }}/homedirs/root/.vim existiert
local_action: stat path={{ inventory_dir }}/files/homedirs/root/.vim - name: (system-user-systemfiles.yml) stat local .vim for root
register: local_template_dir_vim_root ansible.builtin.stat:
with_items: 'root' path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/root/.vim"
loop_control: delegate_to: localhost
label: 'root' become: false
register: root_dotvim_stat
tags: [vim]
- name: (system-user-systemfiles.yml) copy .vim directory for user root if it exists
copy: # 2) Wenn vorhanden, nach /root/ kopieren
src: "{{ inventory_dir + '/files/homedirs/root/.vim' }}" - name: (system-user-systemfiles.yml) copy root .vim directory if it exists
dest: "/root" ansible.builtin.copy:
src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/root/.vim"
dest: "/root/"
mode: preserve # oder weglassen; nicht 0644 bei Verzeichnissen
become: true
when:
- root_dotvim_stat.stat.exists | bool
tags: [vim]
# 2) Wenn vorhanden, nach /root/ kopieren
#- name: (system-user-systemfiles.yml) rsync root .vim if it exists
# ansible.posix.synchronize:
# src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/root/.vim/"
# dest: "/root/.vim/"
# archive: true
# delete: false
# rsync_path: "sudo -n rsync" # -n = kein Passwort-Prompt; erfordert NOPASSWD
# delegate_to: localhost
# when:
# - root_dotvim_stat.stat.exists | bool
# tags: [vim]
# 3) Ownership sicherstellen (rekursiv)
- name: (system-user-systemfiles.yml) ensure ownership on /root/.vim recursively
ansible.builtin.file:
path: "/root/.vim"
owner: "root" owner: "root"
group: "root" group: "root"
mode: 0644 recurse: true
with_items: "{{ local_template_dir_vim_root.results }}" state: directory
loop_control: become: true
label: 'root'
when: when:
- item.stat.exists - root_dotvim_stat.stat.exists | bool
tags: tags: [vim]
- vim