# SPDX-License-Identifier: MIT - name: 'Create dir to store bash include files' loop_control: loop_var: 'local_account' label: 'For local account ''{{ local_account }}'' create ~/''.config/bash/bashrc-includes.d'' dir' loop: '{{ local_accounts_that_need_bash_settings }}' ansible.builtin.file: path: '{% if local_account != ''root'' %}/home{% endif %}/{{ local_account }}/.config/bash/bashrc-includes.d' state: 'directory' owner: '{{ local_account }}' group: '{{ local_account }}' - name: 'If OS is Arch Linux flavor install rsync' when: 'ansible_facts[''system''] | lower == ''linux'' and ansible_facts[''os_family''] | lower == ''archlinux''' ansible.builtin.package: name: - 'rsync' state: 'present' - include_tasks: 'add_bash_include_files.yml' loop: '{{ local_accounts_that_need_bash_settings }}' loop_control: loop_var: 'local_account' - name: 'Store canonical list of bashrc includes in a variable' ansible.builtin.set_fact: bashcon_canonical_bashrc_includes_desired: '{{ lookup(''ansible.builtin.fileglob'', ''root/.config/bash/bashrc-includes.d/system_'' + ansible_facts[''system''] | lower + ''_*'', ''root/.config/bash/bashrc-includes.d/os_family_'' + ansible_facts[''os_family''] | lower + ''_*'', ''../templates/root/.config/bash/bashrc-includes.d/system_'' + ansible_facts[''system''] | lower + ''_*.j2'', ''../templates/root/.config/bash/bashrc-includes.d/os_family_'' + ansible_facts[''os_family''] | lower + ''_*.j2'', wantlist=True) | map(''regex_replace'', ''(.*/)([^/]+?)(\.j2)?$'', ''\2'') | list }}' - include_tasks: 'delete_unneeded_bash_include_files.yml' loop: '{{ local_accounts_that_need_bash_settings }}' loop_control: loop_var: 'local_account' - name: 'Ensure that ''.bashrc'' exists' loop: '{{ local_accounts_that_need_bash_settings }}' loop_control: loop_var: 'local_account' label: 'For local account ''{{ local_account }}'' ensure that ''.bashrc'' exists' ansible.builtin.file: path: '{% if local_account != ''root'' %}/home{% endif %}/{{ local_account }}/.bashrc' state: 'touch' access_time: 'preserve' modification_time: 'preserve' owner: '{{ local_account }}' group: '{{ local_account }}' - name: 'Source ''.bashrc'' file from within ''.bash_profile'' file' loop: '{{ local_accounts_that_need_bash_settings }}' loop_control: loop_var: 'local_account' label: 'For local account ''{{ local_account }}'' source ''.bashrc'' file' ansible.builtin.blockinfile: path: '{% if local_account != ''root'' %}/home{% endif %}/{{ local_account }}/.bash_profile' create: true append_newline: true prepend_newline: true block: | [[ -f ~/.bashrc ]] && . ~/.bashrc - name: 'Source bash include files' loop: '{{ local_accounts_that_need_bash_settings }}' loop_control: loop_var: 'local_account' label: 'For local account ''{{ local_account }}'' source ''.bashrc'' file' ansible.builtin.blockinfile: path: '{% if local_account != ''root'' %}/home{% endif %}/{{ local_account }}/.bashrc' append_newline: true prepend_newline: true block: | for bashrc_include_file in ~/.config/bash/bashrc-includes.d/*; do source "${bashrc_include_file}" done - name: 'Install exa for sane directory listings' ansible.builtin.package: name: 'exa' state: 'present'