Refactor user profile handling in system and NIS user tasks for improved clarity and efficiency
This commit is contained in:
@@ -59,19 +59,91 @@
|
||||
- profile
|
||||
|
||||
|
||||
# 1) Für jeden NIS-User prüfen, ob eine lokale _profile.j2 existiert
|
||||
- name: (nis-user-systemfiles.yml) stat user _profile.j2
|
||||
# Priorität für .profile:
|
||||
# 1. Wenn für den konkreten NIS-User eine eigene _profile.j2 existiert, diese verwenden.
|
||||
# 2. Sonst, wenn es eine allgemeine DEFAULT/_profile.j2 gibt, daraus .profile erstellen.
|
||||
# 3. Sonst, wenn für den konkreten NIS-User eine eigene _profile-Datei existiert, diese als .profile kopieren.
|
||||
|
||||
- name: (nis-user-systemfiles.yml) stat user-specific _profile.j2
|
||||
ansible.builtin.stat:
|
||||
path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ item.name }}/_profile.j2"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
loop: "{{ nis_user }}"
|
||||
register: common_profile_user_template_stats
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
- name: (nis-user-systemfiles.yml) stat user-specific _profile
|
||||
ansible.builtin.stat:
|
||||
path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ item.name }}/_profile"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
loop: "{{ nis_user }}"
|
||||
register: common_profile_user_plain_stats
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
- name: (nis-user-systemfiles.yml) stat default _profile.j2
|
||||
ansible.builtin.stat:
|
||||
path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/DEFAULT/_profile.j2"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
loop: "{{ nis_user }}"
|
||||
register: common_profile_template_stats
|
||||
register: common_profile_default_template_stats
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
# 2) Falls _profile.j2 vorhanden, .profile aus Template rendern
|
||||
- name: (nis-user-systemfiles.yml) template .profile if _profile.j2 exists
|
||||
- name: (nis-user-systemfiles.yml) template .profile from user-specific _profile.j2 if it exists
|
||||
ansible.builtin.template:
|
||||
src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ user.name }}/_profile.j2"
|
||||
dest: "~{{ user.name }}/.profile"
|
||||
owner: "{{ user.name }}"
|
||||
group: "{{ user.name }}"
|
||||
mode: "0644"
|
||||
become: true
|
||||
loop: "{{ nis_user | zip(common_profile_user_template_stats.results) | list }}"
|
||||
loop_control:
|
||||
label: "{{ user.name }}"
|
||||
when:
|
||||
- user_template_stat.stat.exists | bool
|
||||
vars:
|
||||
user: "{{ item.0 }}"
|
||||
user_template_stat: "{{ item.1 }}"
|
||||
tags: [bash]
|
||||
|
||||
- name: (nis-user-systemfiles.yml) copy .profile from user-specific _profile as fallback
|
||||
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(
|
||||
common_profile_user_template_stats.results,
|
||||
common_profile_user_plain_stats.results,
|
||||
common_profile_default_template_stats.results
|
||||
)
|
||||
| list
|
||||
}}
|
||||
loop_control:
|
||||
label: "{{ user.name }}"
|
||||
when:
|
||||
- not user_template_stat.stat.exists | bool
|
||||
- not default_template_stat.stat.exists | bool
|
||||
- user_profile_stat.stat.exists | bool
|
||||
vars:
|
||||
user: "{{ item.0 }}"
|
||||
user_template_stat: "{{ item.1 }}"
|
||||
user_profile_stat: "{{ item.2 }}"
|
||||
default_template_stat: "{{ item.3 }}"
|
||||
tags: [bash]
|
||||
|
||||
- name: (nis-user-systemfiles.yml) template .profile from default _profile.j2 if no user-specific profile exists
|
||||
ansible.builtin.template:
|
||||
src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/DEFAULT/_profile.j2"
|
||||
dest: "~{{ user.name }}/.profile"
|
||||
@@ -79,14 +151,26 @@
|
||||
group: "{{ user.name }}"
|
||||
mode: "0644"
|
||||
become: true
|
||||
loop: "{{ nis_user | zip(common_profile_template_stats.results) | list }}"
|
||||
loop: >-
|
||||
{{
|
||||
nis_user
|
||||
| zip(
|
||||
common_profile_user_template_stats.results,
|
||||
common_profile_user_plain_stats.results,
|
||||
common_profile_default_template_stats.results
|
||||
)
|
||||
| list
|
||||
}}
|
||||
loop_control:
|
||||
label: "{{ user.name }}"
|
||||
when:
|
||||
- stat_result.stat.exists | bool
|
||||
- not user_template_stat.stat.exists | bool
|
||||
- default_template_stat.stat.exists | bool
|
||||
vars:
|
||||
user: "{{ item.0 }}"
|
||||
stat_result: "{{ item.1 }}"
|
||||
user_template_stat: "{{ item.1 }}"
|
||||
user_profile_stat: "{{ item.2 }}"
|
||||
default_template_stat: "{{ item.3 }}"
|
||||
tags: [bash]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user