fix(users-systemfiles.yml): standardize variable names and improve clarity in user file checks and backups
This commit is contained in:
@@ -5,18 +5,20 @@
|
||||
|
||||
# default_users
|
||||
- name: (users-systemfiles.yml) Check if local template directory exists for default users
|
||||
ansible.builtin.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 }}"
|
||||
register: local_template_dir_default_user
|
||||
register: common_local_template_dir_default_user
|
||||
|
||||
# root
|
||||
- name: (users-systemfiles.yml) Check if local template directory exists for root
|
||||
ansible.builtin.stat: path={{ inventory_dir }}/files/homedirs/root
|
||||
ansible.builtin.stat:
|
||||
path: "{{ inventory_dir }}/files/homedirs/root"
|
||||
delegate_to: localhost
|
||||
register: local_template_dir_root
|
||||
register: common_local_template_dir_root
|
||||
|
||||
# --
|
||||
# Copy .bashrc
|
||||
@@ -25,7 +27,7 @@
|
||||
- name: (users-systemfiles.yml) Check if users file '.bashrc.ORIG' exists
|
||||
ansible.builtin.stat:
|
||||
path: "~{{ item.name }}/.bashrc.ORIG"
|
||||
register: bashrc_user_orig_exists
|
||||
register: common_bashrc_user_orig_exists
|
||||
loop: "{{ default_user }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
@@ -33,11 +35,12 @@
|
||||
- bash
|
||||
|
||||
- name: (users-systemfiles.yml) Backup existing users .bashrc file
|
||||
ansible.builtin.command: cp -a ~{{ item.item.name }}/.bashrc ~{{ item.item.name }}/.bashrc.ORIG
|
||||
loop: "{{ bashrc_user_orig_exists.results }}"
|
||||
ansible.builtin.command:
|
||||
cmd: cp -a ~{{ item.item.name }}/.bashrc ~{{ item.item.name }}/.bashrc.ORIG
|
||||
creates: "~{{ item.item.name }}/.bashrc.ORIG"
|
||||
loop: "{{ common_bashrc_user_orig_exists.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item.name }}"
|
||||
when: item.stat.exists == False
|
||||
tags:
|
||||
- bash
|
||||
|
||||
@@ -48,7 +51,7 @@
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
loop: "{{ default_user }}"
|
||||
register: bashrc_stats
|
||||
register: common_bashrc_stats
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
@@ -60,7 +63,7 @@
|
||||
owner: "{{ user.name }}"
|
||||
group: "{{ user.name }}"
|
||||
mode: "0644"
|
||||
loop: "{{ default_user | zip(bashrc_stats.results) | list }}"
|
||||
loop: "{{ default_user | zip(common_bashrc_stats.results) | list }}"
|
||||
loop_control:
|
||||
label: "{{ user.name }}"
|
||||
when:
|
||||
@@ -78,13 +81,14 @@
|
||||
- name: (users-systemfiles.yml) Check if file '/root/.bashrc.ORIG' exists
|
||||
ansible.builtin.stat:
|
||||
path: /root/.bashrc.ORIG
|
||||
register: bashrc_root_orig_exists
|
||||
register: common_bashrc_root_orig_exists
|
||||
tags:
|
||||
- bash
|
||||
|
||||
- name: (users-systemfiles.yml) Backup /root/.bashrc file
|
||||
ansible.builtin.command: cp /root/.bashrc /root/.bashrc.ORIG
|
||||
when: bashrc_root_orig_exists.stat.exists == False
|
||||
ansible.builtin.command:
|
||||
cmd: cp /root/.bashrc /root/.bashrc.ORIG
|
||||
creates: /root/.bashrc.ORIG
|
||||
tags:
|
||||
- bash
|
||||
|
||||
@@ -94,7 +98,7 @@
|
||||
path: "{{ inventory_dir }}/files/homedirs/root/_bashrc"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
register: bashrc_root_stat
|
||||
register: common_bashrc_root_stat
|
||||
|
||||
# 2) Wenn vorhanden, kopieren wir sie nach /root/.bashrc auf dem Zielhost
|
||||
- name: Copy root .bashrc if it exists
|
||||
@@ -105,7 +109,7 @@
|
||||
group: root
|
||||
mode: "0644"
|
||||
become: true
|
||||
when: bashrc_root_stat.stat.exists
|
||||
when: common_bashrc_root_stat.stat.exists
|
||||
tags:
|
||||
- bash
|
||||
|
||||
@@ -116,7 +120,7 @@
|
||||
- name: (users-systemfiles.yml) Check if users file '.profile.ORIG' exists
|
||||
ansible.builtin.stat:
|
||||
path: "~{{ item.name }}/.profile.ORIG"
|
||||
register: profile_user_orig_exists
|
||||
register: common_profile_user_orig_exists
|
||||
loop: "{{ default_user }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
@@ -126,13 +130,14 @@
|
||||
- profile
|
||||
|
||||
- name: (users-systemfiles.yml) Backup existing users .profile file
|
||||
ansible.builtin.command: cp -a ~{{ item.item.name }}/.profile ~{{ item.item.name }}/.profile.ORIG
|
||||
loop: "{{ profile_user_orig_exists.results }}"
|
||||
ansible.builtin.command:
|
||||
cmd: cp -a ~{{ item.item.name }}/.profile ~{{ item.item.name }}/.profile.ORIG
|
||||
creates: "~{{ item.item.name }}/.profile.ORIG"
|
||||
loop: "{{ common_profile_user_orig_exists.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item.name }}"
|
||||
when:
|
||||
- ansible_facts['distribution'] == "Debian"
|
||||
- item.stat.exists == False
|
||||
tags:
|
||||
- profile
|
||||
|
||||
@@ -143,7 +148,7 @@
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
loop: "{{ default_user }}"
|
||||
register: profile_stats
|
||||
register: common_profile_stats
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
@@ -155,7 +160,7 @@
|
||||
owner: "{{ user.name }}"
|
||||
group: "{{ user.name }}"
|
||||
mode: "0644"
|
||||
loop: "{{ default_user | zip(profile_stats.results) | list }}"
|
||||
loop: "{{ default_user | zip(common_profile_stats.results) | list }}"
|
||||
loop_control:
|
||||
label: "{{ user.name }}"
|
||||
when:
|
||||
@@ -173,17 +178,18 @@
|
||||
- name: (users-systemfiles.yml) Check if file '/root/.profile.ORIG' exists
|
||||
ansible.builtin.stat:
|
||||
path: /root/.profile.ORIG
|
||||
register: profile_root_orig_exists
|
||||
register: common_profile_root_orig_exists
|
||||
when:
|
||||
- ansible_facts['distribution'] == "Debian"
|
||||
tags:
|
||||
- profile
|
||||
|
||||
- name: (users-systemfiles.yml) Backup existing users .profile file
|
||||
ansible.builtin.command: cp -a /root/.profile /root/.profile.ORIG
|
||||
ansible.builtin.command:
|
||||
cmd: cp -a /root/.profile /root/.profile.ORIG
|
||||
creates: /root/.profile.ORIG
|
||||
when:
|
||||
- ansible_facts['distribution'] == "Debian"
|
||||
- profile_root_orig_exists.stat.exists == False
|
||||
tags:
|
||||
- profile
|
||||
|
||||
@@ -193,7 +199,7 @@
|
||||
path: "{{ inventory_dir }}/files/homedirs/root/_profile"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
register: profile_root_stat
|
||||
register: common_profile_root_stat
|
||||
|
||||
# 2) Wenn vorhanden, kopieren wir sie nach /root/.profile auf dem Zielhost
|
||||
- name: Copy root .profile if it exists
|
||||
@@ -204,7 +210,7 @@
|
||||
group: root
|
||||
mode: "0644"
|
||||
become: true
|
||||
when: profile_root_stat.stat.exists
|
||||
when: common_profile_root_stat.stat.exists
|
||||
tags:
|
||||
- bash
|
||||
|
||||
@@ -215,7 +221,7 @@
|
||||
- name: (users-systemfiles.yml) Check if users file '.bash_profile.ORIG' exists
|
||||
ansible.builtin.stat:
|
||||
path: "~{{ item.name }}/.bash_profile.ORIG"
|
||||
register: bash_profile_user_orig_exists
|
||||
register: common_bash_profile_user_orig_exists
|
||||
loop: "{{ default_user }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
@@ -225,13 +231,14 @@
|
||||
- profile
|
||||
|
||||
- name: (users-systemfiles.yml) Backup existing users .bash_profile file
|
||||
ansible.builtin.command: cp -a ~{{ item.item.name }}/.bash_profile ~{{ item.item.name }}/.bash_profile.ORIG
|
||||
loop: "{{ bash_profile_user_orig_exists.results }}"
|
||||
ansible.builtin.command:
|
||||
cmd: cp -a ~{{ item.item.name }}/.bash_profile ~{{ item.item.name }}/.bash_profile.ORIG
|
||||
creates: "~{{ item.item.name }}/.bash_profile.ORIG"
|
||||
loop: "{{ common_bash_profile_user_orig_exists.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item.name }}"
|
||||
when:
|
||||
- ansible_facts['distribution'] == "CentOS"
|
||||
- item.stat.exists == False
|
||||
tags:
|
||||
- profile
|
||||
|
||||
@@ -242,7 +249,7 @@
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
loop: "{{ default_user }}"
|
||||
register: bash_profile_stats
|
||||
register: common_bash_profile_stats
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
when:
|
||||
@@ -256,7 +263,7 @@
|
||||
owner: "{{ user.name }}"
|
||||
group: "{{ user.name }}"
|
||||
mode: "0644"
|
||||
loop: "{{ default_user | zip(bash_profile_stats.results) | list }}"
|
||||
loop: "{{ default_user | zip(common_bash_profile_stats.results) | list }}"
|
||||
loop_control:
|
||||
label: "{{ user.name }}"
|
||||
when:
|
||||
@@ -275,17 +282,18 @@
|
||||
- name: (users-systemfiles.yml) Check if file '/root/.bash_profile.ORIG' exists
|
||||
ansible.builtin.stat:
|
||||
path: /root/.bash_profile.ORIG
|
||||
register: profile_root_orig_exists
|
||||
register: common_bash_profile_root_orig_exists
|
||||
when:
|
||||
- ansible_facts['distribution'] == "CentOS"
|
||||
tags:
|
||||
- profile
|
||||
|
||||
- name: (users-systemfiles.yml) Backup existing users .bash_profile file
|
||||
ansible.builtin.command: cp -a /root/.bash_profile /root/.bash_profile.ORIG
|
||||
ansible.builtin.command:
|
||||
cmd: cp -a /root/.bash_profile /root/.bash_profile.ORIG
|
||||
creates: /root/.bash_profile.ORIG
|
||||
when:
|
||||
- ansible_facts['distribution'] == "CentOS"
|
||||
- profile_root_orig_exists.stat.exists == False
|
||||
tags:
|
||||
- profile
|
||||
|
||||
@@ -295,7 +303,7 @@
|
||||
path: "{{ inventory_dir }}/files/homedirs/root/_bash_profile"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
register: bash_profile_root_stat
|
||||
register: common_bash_profile_root_stat
|
||||
when:
|
||||
- ansible_facts['distribution'] == "CentOS"
|
||||
|
||||
@@ -310,7 +318,7 @@
|
||||
become: true
|
||||
when:
|
||||
- ansible_facts['distribution'] == "CentOS"
|
||||
- bash_profile_root_stat.stat.exists
|
||||
- common_bash_profile_root_stat.stat.exists
|
||||
tags:
|
||||
- bash
|
||||
|
||||
@@ -325,7 +333,7 @@
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
loop: "{{ default_user }}"
|
||||
register: vimrc_stats
|
||||
register: common_vimrc_stats
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
@@ -337,7 +345,7 @@
|
||||
owner: "{{ user.name }}"
|
||||
group: "{{ user.name }}"
|
||||
mode: "0644"
|
||||
loop: "{{ default_user | zip(vimrc_stats.results) | list }}"
|
||||
loop: "{{ default_user | zip(common_vimrc_stats.results) | list }}"
|
||||
loop_control:
|
||||
label: "{{ user.name }}"
|
||||
when:
|
||||
@@ -355,7 +363,7 @@
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
loop: "{{ default_user }}"
|
||||
register: dotvim_stats
|
||||
register: common_dotvim_stats
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
@@ -407,7 +415,7 @@
|
||||
path: "{{ inventory_dir }}/files/homedirs/root/_vimrc"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
register: vimrc_root_stat
|
||||
register: common_vimrc_root_stat
|
||||
|
||||
# 2) Wenn vorhanden, kopieren wir sie nach /root/.vimrc auf dem Zielhost
|
||||
- name: Copy root .vimrc if it exists
|
||||
@@ -419,7 +427,7 @@
|
||||
mode: "0644"
|
||||
become: true
|
||||
when:
|
||||
- vimrc_root_stat.stat.exists
|
||||
- common_vimrc_root_stat.stat.exists
|
||||
tags:
|
||||
- bash
|
||||
|
||||
@@ -429,7 +437,7 @@
|
||||
path: "{{ inventory_dir }}/files/homedirs/root/.vim"
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
register: root_dotvim_stat
|
||||
register: common_root_dotvim_stat
|
||||
tags: [vim]
|
||||
|
||||
# 2) Wenn vorhanden, nach /root/ kopieren
|
||||
|
||||
Reference in New Issue
Block a user