feat(role): Initial commit
This commit is contained in:
20
tasks/add_bash_include_files.yml
Normal file
20
tasks/add_bash_include_files.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
- name: 'Copy non-templated bash include files'
|
||||
loop_control:
|
||||
label: 'Non-templated file ''{{ item | basename }}'''
|
||||
loop: '{{ 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 + ''_*'', wantlist=True) }}'
|
||||
ansible.builtin.copy:
|
||||
src: '{{ item }}'
|
||||
dest: '{% if local_account != ''root'' %}/home{% endif %}/{{ local_account }}/.config/bash/bashrc-includes.d/'
|
||||
owner: '{{ local_account }}'
|
||||
group: '{{ local_account }}'
|
||||
|
||||
- name: 'Copy templated bash include files'
|
||||
loop_control:
|
||||
label: 'Templated file ''{{ item | basename }}'' --> ''{{ item | basename | regex_search(''.+?(?=\.j2)'') }}'''
|
||||
loop: '{{ lookup(''ansible.builtin.fileglob'', ''../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) }}'
|
||||
ansible.builtin.template:
|
||||
src: '{{ item }}'
|
||||
dest: '{% if local_account != ''root'' %}/home{% endif %}/{{ local_account }}/.config/bash/bashrc-includes.d/{{ item | basename | regex_search(''.+?(?=\.j2)'') }}'
|
||||
owner: '{{ local_account }}'
|
||||
group: '{{ local_account }}'
|
15
tasks/delete_unneeded_bash_include_files.yml
Normal file
15
tasks/delete_unneeded_bash_include_files.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
- name: 'For local account ''{{ local_account }}'' get list of bash include files'
|
||||
changed_when: false
|
||||
register: 'bashcon_canonical_bashrc_includes_actual'
|
||||
ansible.builtin.shell: |
|
||||
ls -1 {% if local_account != 'root' %}/home{% endif %}/{{ local_account }}/.config/bash/bashrc-includes.d
|
||||
|
||||
- name: 'For local account ''{{ local_account }}'' delete unneeded bash include files'
|
||||
when: 'item not in bashcon_canonical_bashrc_includes_desired'
|
||||
loop_control:
|
||||
label: 'If unneeded delete bashrc include file ''{{ item }}'''
|
||||
loop: '{{ bashcon_canonical_bashrc_includes_actual.stdout_lines }}'
|
||||
ansible.builtin.file:
|
||||
path: '{% if local_account != ''root'' %}/home{% endif %}/{{ local_account }}/.config/bash/bashrc-includes.d/{{ item }}'
|
||||
state: 'absent'
|
77
tasks/main.yml
Normal file
77
tasks/main.yml
Normal file
@@ -0,0 +1,77 @@
|
||||
# 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'
|
Reference in New Issue
Block a user