64 lines
1.9 KiB
YAML
64 lines
1.9 KiB
YAML
- name: Install unified HomeLab bash config
|
|
ansible.builtin.template:
|
|
src: homelab.sh.j2
|
|
dest: "{{ bash_config_file }}"
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
|
|
- name: Ensure system bashrc sources managed config
|
|
ansible.builtin.blockinfile:
|
|
path: "{{ bash_config_bashrc }}"
|
|
create: true
|
|
owner: root
|
|
group: root
|
|
mode: "0644"
|
|
marker: "# {mark} ANSIBLE MANAGED HOMELAB BASH CONFIG"
|
|
block: |
|
|
if [ -f /etc/profile.d/homelab.sh ]; then
|
|
. /etc/profile.d/homelab.sh
|
|
fi
|
|
|
|
- name: List bash users with local home directories
|
|
ansible.builtin.shell: >-
|
|
getent passwd | awk -F: '$7 ~ /\/bash$/ && $6 ~ /^\// { print $1 ":" $6 }'
|
|
register: bash_config_bash_users_raw
|
|
changed_when: false
|
|
|
|
- name: Ensure bash users source managed system config
|
|
ansible.builtin.blockinfile:
|
|
path: "{{ item.split(':')[1] }}/.bashrc"
|
|
create: true
|
|
owner: "{{ item.split(':')[0] }}"
|
|
group: "{{ item.split(':')[0] }}"
|
|
mode: "0644"
|
|
marker: "# {mark} ANSIBLE MANAGED HOMELAB SYSTEM BASH CONFIG"
|
|
block: |
|
|
if [ -f /etc/profile.d/homelab.sh ]; then
|
|
. /etc/profile.d/homelab.sh
|
|
fi
|
|
loop: "{{ bash_config_bash_users_raw.stdout_lines }}"
|
|
|
|
- name: Check legacy per-user bashrc
|
|
ansible.builtin.stat:
|
|
path: "{{ bash_config_legacy_home }}/.bashrc"
|
|
register: bash_config_legacy_bashrc
|
|
|
|
- name: Remove legacy per-user bashrc source block
|
|
ansible.builtin.blockinfile:
|
|
path: "{{ bash_config_legacy_home }}/.bashrc"
|
|
marker: "# {mark} ANSIBLE MANAGED HOMELAB BASH CONFIG"
|
|
state: absent
|
|
when: bash_config_legacy_bashrc.stat.exists
|
|
|
|
- name: Remove legacy per-user bash config file
|
|
ansible.builtin.file:
|
|
path: "{{ bash_config_legacy_home }}/.bashrc.d/homelab.sh"
|
|
state: absent
|
|
|
|
- name: Remove legacy profile scripts that conflict with unified config
|
|
ansible.builtin.file:
|
|
path: "{{ item }}"
|
|
state: absent
|
|
loop: "{{ bash_config_legacy_profile_files }}"
|