224 lines
6.3 KiB
YAML
224 lines
6.3 KiB
YAML
---
|
|
|
|
# ---
|
|
# Check if local template directories exists
|
|
# ---
|
|
|
|
# nis_users
|
|
#- name: (nis-user-systemfiles.yml) Check if local template directory exists for default users
|
|
# local_action: stat path={{ inventory_dir }}/files/{{ nis_domain}}/homedirs/{{ item.name }}
|
|
# with_items: "{{ nis_user }}"
|
|
# loop_control:
|
|
# label: '{{ item.name }}'
|
|
# register: local_template_dir_nis_user
|
|
|
|
- name: (nis-user-systemfiles.yml) Check if local template directory exists for default users
|
|
delegate_to: localhost
|
|
stat:
|
|
path: "{{ inventory_dir }}/files/{{ nis_domain}}/homedirs/{{ item.name }}"
|
|
with_items: "{{ nis_user }}"
|
|
loop_control:
|
|
label: '{{ item.name }}'
|
|
register: local_template_dir_nis_user
|
|
|
|
#- name: Print variable local_template_dir_nis_user
|
|
# debug: var=local_template_dir_nis_user.results
|
|
|
|
#- meta: end_play
|
|
|
|
|
|
# --
|
|
# Copy .profile
|
|
# ---
|
|
|
|
- name: (nis-user-systemfiles.yml) Check if users file '.profile.ORIG' exists
|
|
stat:
|
|
path: "~{{ item.name }}/.profile.ORIG"
|
|
register: profile_user_orig_exists
|
|
loop: "{{ nis_user }}"
|
|
loop_control:
|
|
label: '{{ item.name }}'
|
|
tags:
|
|
- profile
|
|
|
|
- name: (nis-user-systemfiles.yml) Backup existing users .profile file
|
|
command: cp -a ~{{ item.item.name }}/.profile ~{{ item.item.name }}/.profile.ORIG
|
|
loop: "{{ profile_user_orig_exists.results }}"
|
|
loop_control:
|
|
label: '{{ item.item.name }}'
|
|
when:
|
|
- item.stat.exists == False
|
|
tags:
|
|
- profile
|
|
|
|
|
|
# 1) Für jeden NIS-User prüfen, ob eine lokale _profile existiert
|
|
- name: (nis-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: "{{ nis_user }}"
|
|
register: profile_stats
|
|
loop_control:
|
|
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:
|
|
- stat_result.stat.exists | bool
|
|
vars:
|
|
user: "{{ item.0 }}"
|
|
stat_result: "{{ item.1 }}"
|
|
tags: [bash]
|
|
|
|
|
|
# --
|
|
# Copy .bashrc
|
|
# ---
|
|
|
|
- name: (nis-user-systemfiles.yml) Check if users file '.bashrc.ORIG' exists
|
|
stat:
|
|
path: "~{{ item.name }}/.bashrc.ORIG"
|
|
register: bashrc_user_orig_exists
|
|
loop: "{{ nis_user }}"
|
|
loop_control:
|
|
label: '{{ item.name }}'
|
|
tags:
|
|
- bashrc
|
|
|
|
- name: (nis-user-systemfiles.yml) Backup existing users .bashrc file
|
|
command: cp -a ~{{ item.item.name }}/.bashrc ~{{ item.item.name }}/.bashrc.ORIG
|
|
loop: "{{ bashrc_user_orig_exists.results }}"
|
|
loop_control:
|
|
label: '{{ item.item.name }}'
|
|
when: item.stat.exists == False
|
|
tags:
|
|
- bashrc
|
|
|
|
# 1) Für jeden NIS-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: "{{ nis_user }}"
|
|
register: bashrc_stats
|
|
loop_control:
|
|
label: "{{ item.name }}"
|
|
|
|
# 2) Falls User _bashrc vorhanden, kopieren
|
|
- name: (system-user-systemfiles.yml) copy .bashrc if it exists
|
|
ansible.builtin.copy:
|
|
src: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ user.name }}/_bashrc"
|
|
dest: "~{{ user.name }}/.bashrc"
|
|
owner: "{{ user.name }}"
|
|
group: "{{ user.name }}"
|
|
mode: "0644"
|
|
become: true
|
|
loop: "{{ nis_user | zip(bashrc_stats.results) | list }}"
|
|
loop_control:
|
|
label: "{{ user.name }}"
|
|
when:
|
|
- stat_result.stat.exists | bool
|
|
vars:
|
|
user: "{{ item.0 }}"
|
|
stat_result: "{{ item.1 }}"
|
|
tags: [bash]
|
|
|
|
|
|
# --
|
|
# Copy .vimrc
|
|
# ---
|
|
|
|
# 1. Prüfen, ob für jeden User ein lokales _vimrc existiert
|
|
- name: (system-user-systemfiles.yml) stat user _vimrc
|
|
ansible.builtin.stat:
|
|
path: "{{ inventory_dir }}/files/{{ nis_domain }}/homedirs/{{ item.name }}/_vimrc"
|
|
delegate_to: localhost
|
|
become: false
|
|
loop: "{{ nis_user }}"
|
|
register: vimrc_stats
|
|
loop_control:
|
|
label: '{{ item.name }}'
|
|
|
|
# 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: "{{ nis_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: "{{ nis_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
|
|
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]
|
|
|