Refactor Ansible tasks and templates for improved consistency and clarity
This commit is contained in:
@@ -5,36 +5,36 @@
|
||||
# ---
|
||||
|
||||
# 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 }}
|
||||
# - 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
|
||||
# register: common_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 }}"
|
||||
ansible.builtin.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
|
||||
register: common_local_template_dir_nis_user
|
||||
|
||||
#- name: Print variable local_template_dir_nis_user
|
||||
# debug: var=local_template_dir_nis_user.results
|
||||
# - name: Print variable common_local_template_dir_nis_user
|
||||
# debug: var=common_local_template_dir_nis_user.results
|
||||
|
||||
#- meta: end_play
|
||||
# - meta: end_play
|
||||
|
||||
|
||||
# --
|
||||
# Copy .profile
|
||||
# ---
|
||||
# --
|
||||
# Copy .profile
|
||||
# ---
|
||||
|
||||
- name: (nis-user-systemfiles.yml) Check if users file '.profile.ORIG' exists
|
||||
stat:
|
||||
ansible.builtin.stat:
|
||||
path: "~{{ item.name }}/.profile.ORIG"
|
||||
register: profile_user_orig_exists
|
||||
register: common_profile_user_orig_exists
|
||||
loop: "{{ nis_user }}"
|
||||
loop_control:
|
||||
label: '{{ item.name }}'
|
||||
@@ -42,12 +42,19 @@
|
||||
- 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 }}"
|
||||
ansible.builtin.copy:
|
||||
src: "~{{ item.item.name }}/.profile"
|
||||
dest: "~{{ item.item.name }}/.profile.ORIG"
|
||||
remote_src: true
|
||||
force: false
|
||||
owner: "{{ item.item.name }}"
|
||||
group: "{{ item.item.name }}"
|
||||
mode: "0644"
|
||||
loop: "{{ common_profile_user_orig_exists.results }}"
|
||||
loop_control:
|
||||
label: '{{ item.item.name }}'
|
||||
when:
|
||||
- item.stat.exists == False
|
||||
- not item.stat.exists
|
||||
tags:
|
||||
- profile
|
||||
|
||||
@@ -59,7 +66,7 @@
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
loop: "{{ nis_user }}"
|
||||
register: profile_template_stats
|
||||
register: common_profile_template_stats
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
@@ -72,7 +79,7 @@
|
||||
group: "{{ user.name }}"
|
||||
mode: "0644"
|
||||
become: true
|
||||
loop: "{{ nis_user | zip(profile_template_stats.results) | list }}"
|
||||
loop: "{{ nis_user | zip(common_profile_template_stats.results) | list }}"
|
||||
loop_control:
|
||||
label: "{{ user.name }}"
|
||||
when:
|
||||
@@ -83,16 +90,14 @@
|
||||
tags: [bash]
|
||||
|
||||
|
||||
|
||||
|
||||
# --
|
||||
# Copy .bashrc
|
||||
# ---
|
||||
|
||||
- name: (nis-user-systemfiles.yml) Check if users file '.bashrc.ORIG' exists
|
||||
stat:
|
||||
ansible.builtin.stat:
|
||||
path: "~{{ item.name }}/.bashrc.ORIG"
|
||||
register: bashrc_user_orig_exists
|
||||
register: common_bashrc_user_orig_exists
|
||||
loop: "{{ nis_user }}"
|
||||
loop_control:
|
||||
label: '{{ item.name }}'
|
||||
@@ -100,11 +105,18 @@
|
||||
- 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 }}"
|
||||
ansible.builtin.copy:
|
||||
src: "~{{ item.item.name }}/.bashrc"
|
||||
dest: "~{{ item.item.name }}/.bashrc.ORIG"
|
||||
remote_src: true
|
||||
force: false
|
||||
owner: "{{ item.item.name }}"
|
||||
group: "{{ item.item.name }}"
|
||||
mode: "0644"
|
||||
loop: "{{ common_bashrc_user_orig_exists.results }}"
|
||||
loop_control:
|
||||
label: '{{ item.item.name }}'
|
||||
when: item.stat.exists == False
|
||||
when: not item.stat.exists
|
||||
tags:
|
||||
- bashrc
|
||||
|
||||
@@ -115,7 +127,7 @@
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
loop: "{{ nis_user }}"
|
||||
register: bashrc_stats
|
||||
register: common_bashrc_stats
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
@@ -128,7 +140,7 @@
|
||||
group: "{{ user.name }}"
|
||||
mode: "0644"
|
||||
become: true
|
||||
loop: "{{ nis_user | zip(bashrc_stats.results) | list }}"
|
||||
loop: "{{ nis_user | zip(common_bashrc_stats.results) | list }}"
|
||||
loop_control:
|
||||
label: "{{ user.name }}"
|
||||
when:
|
||||
@@ -150,7 +162,7 @@
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
loop: "{{ nis_user }}"
|
||||
register: vimrc_stats
|
||||
register: common_vimrc_stats
|
||||
loop_control:
|
||||
label: '{{ item.name }}'
|
||||
|
||||
@@ -162,7 +174,7 @@
|
||||
owner: "{{ user.name }}"
|
||||
group: "{{ user.name }}"
|
||||
mode: '0644'
|
||||
loop: "{{ nis_user | zip(vimrc_stats.results) | list }}"
|
||||
loop: "{{ nis_user | zip(common_vimrc_stats.results) | list }}"
|
||||
loop_control:
|
||||
label: "{{ user.name }}"
|
||||
when:
|
||||
@@ -181,7 +193,7 @@
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
loop: "{{ nis_user }}"
|
||||
register: dotvim_stats
|
||||
register: common_dotvim_stats
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
@@ -193,7 +205,7 @@
|
||||
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: "{{ nis_user | zip(common_dotvim_stats.results) | list }}"
|
||||
loop_control:
|
||||
label: "{{ user.name }}"
|
||||
when:
|
||||
@@ -213,7 +225,7 @@
|
||||
recurse: true
|
||||
state: directory
|
||||
become: true
|
||||
loop: "{{ nis_user | zip(dotvim_stats.results) | list }}"
|
||||
loop: "{{ nis_user | zip(common_dotvim_stats.results) | list }}"
|
||||
loop_control:
|
||||
label: "{{ user.name }}"
|
||||
when:
|
||||
@@ -222,4 +234,3 @@
|
||||
user: "{{ item.0 }}"
|
||||
stat_result: "{{ item.1 }}"
|
||||
tags: [vim]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user