Attempt at customising the bashrc file.

This commit is contained in:
Andrea Dell'Amico 2024-04-03 11:58:29 +02:00
parent 6f86357582
commit e9f2898efb
Signed by: adellam
GPG Key ID: 147ABE6CEB9E20FF
6 changed files with 139 additions and 0 deletions

View File

@ -31,6 +31,18 @@ ubuntu_configure_additional_ints_list: []
disable_ipv6: false
ipv6_sysctl_value: 1
ipv6_sysctl_file: /etc/sysctl.d/10-ipv6-disable.conf
# Bash prompt and shell history settings
#
bash_customize_skel_bashrc: false
bash_etc_skel_file: /etc/skel/.bashrc
bash_custom_skel_bashrc_file: files/skel_bashrc.sh
bash_customize_root_bashrc: false
bash_custom_root_bashrc_file: files/root_bashrc.sh
bash_root_bashrc_file: /etc/.bashrc
bash_customize_root_history_settings: false
bash_custom_history_directory: /var/log/users_root_history
bash_custom_history_settings_file: files/root_bashrc_history.sh
#
# Define the following variables to manage additional disks and mount points, even static nfs ones
additional_disks: false

2
files/root_bashrc.sh Normal file
View File

@ -0,0 +1,2 @@
export _ROOT_COLOR=33 # yellow
PS1="\[\033[01;${_ROOT_COLOR}m\]${debian_chroot:+($debian_chroot)}ROOT\[\033[01;34m\]@$(hostname -f) \w \@ #\[\033[00m\] "

View File

@ -0,0 +1,3 @@
export HISTTIMEFORMAT="%Y%m%d %H:%M:%S "
export HISTSIZE=10000
export HISTFILE=/var/log/users_root_history/history-$(who am i | awk '{print $1}';exit)

7
files/skel_bashrc.sh Normal file
View File

@ -0,0 +1,7 @@
export _ROOT_COLOR=33 # yellow
export _USER_COLOR=36 # cyan
if [ "`id -u`" -eq 0 ]; then
PS1="\[\033[01;${_ROOT_COLOR}m\]${debian_chroot:+($debian_chroot)}ROOT\[\033[01;34m\]@$(hostname -f) \w \@ #\[\033[00m\] "
else
PS1="\[\033[01;${_USER_COLOR}m\]${debian_chroot:+($debian_chroot)}\u\[\033[01;34m\]@$(hostname -f) \w \@ $\[\033[00m\] "
fi

113
tasks/custom_bashrc.yml Normal file
View File

@ -0,0 +1,113 @@
---
- name: custom_bashrc | Manage the skel bashrc customizations
when: bash_customize_skel_bashrc
tags:
- bashrc
- etcskel
block:
- name: custom_bashrc | Manage the skel bashrc customizations
ansible.builtin.blockinfile:
path: "{{ bash_etc_skel_file }}"
marker_begin: 'bashrc_customizations_start'
marker_end: 'bashrc_customizations_end'
marker: "# {mark} Customization to bashrc installed via ansible"
block: "{{ item }}"
loop:
- "{{ lookup('ansible.builtin.file', '{{ bash_custom_skel_bashrc_file }}') }}"
state: present
- name: custom_bashrc | Remove the skel bashrc customizations
when: not bash_customize_skel_bashrc
tags:
- bashrc
- etcskel
block:
- name: custom_bashrc | Remove the skel bashrc customizations
ansible.builtin.blockinfile:
path: "{{ bash_etc_skel_file }}"
marker_begin: 'bashrc_customizations_start'
marker_end: 'bashrc_customizations_end'
marker: "# {mark} Customization to bashrc installed via ansible"
block: "{{ item }}"
loop:
- "{{ lookup('ansible.builtin.file', '{{ bash_custom_skel_bashrc_file }}') }}"
state: absent
- name: custom_bashrc | Manage the root user bashrc customization
when: bash_customize_root_bashrc
tags:
- bashrc
- root_bashrc
block:
- name: custom_bashrc | Manage the root user bashrc customization
ansible.builtin.blockinfile:
path: "{{ bash_root_bashrc_file }}"
marker_begin: 'bashrc_customizations_start'
marker_end: 'bashrc_customizations_end'
marker: "# {mark} Customization to bashrc installed via ansible"
block: "{{ item }}"
loop:
- "{{ lookup('ansible.builtin.file', '{{ bash_custom_root_bashrc_file }}') }}"
state: present
- name: custom_bashrc | Remove the root user bashrc customization
when: not bash_customize_root_bashrc
tags:
- bashrc
- root_bashrc
block:
- name: custom_bashrc | Remove the root user bashrc customization
ansible.builtin.blockinfile:
path: "{{ bash_root_bashrc_file }}"
marker_begin: 'bashrc_customizations_start'
marker_end: 'bashrc_customizations_end'
marker: "# {mark} Customization to bashrc installed via ansible"
block: "{{ item }}"
loop:
- "{{ lookup('ansible.builtin.file', '{{ bash_custom_root_bashrc_file }}') }}"
state: absent
- name: custom_bashrc | Manage the root user bashrc history settings
when: bash_customize_root_history_settings
tags:
- bashrc
- root_bashrc_history_settings
block:
- name: custom_bashrc | Create the bash history logs directory
ansible.builtin.file:
path: "{{ bash_custom_history_directory }}"
state: directory
owner: root
group: root
mode: "0700"
- name: custom_bashrc | Manage the root user bashrc history settings
ansible.builtin.blockinfile:
path: "{{ bash_root_bashrc_file }}"
marker_begin: 'history_customizations_start'
marker_end: 'history_customizations_end'
marker: "# {mark} Customization to the bash prompt installed via ansible"
block: "{{ item }}"
loop:
- "{{ lookup('ansible.builtin.file', '{{ bash_custom_history_settings_file }}') }}"
state: present
- name: custom_bashrc | Remove the root user bashrc history settings
when: not bash_customize_root_history_settings
tags:
- bashrc
- root_bashrc_history_settings
block:
- name: custom_bashrc | Remove the root user bashrc history settings
ansible.builtin.blockinfile:
path: "{{ bash_root_bashrc_file }}"
marker_begin: 'history_customizations_start'
marker_end: 'history_customizations_end'
marker: "# {mark} Customization to the bash prompt installed via ansible"
block: "{{ item }}"
loop:
- "{{ lookup('ansible.builtin.file', '{{ bash_custom_history_settings_file }}') }}"
state: absent
- name: custom_bashrc | Remove the bash history logs directory
ansible.builtin.file:
path: "{{ bash_custom_history_directory }}"
state: absent

View File

@ -41,3 +41,5 @@
when:
- nfs_server_enabled
- not nfs_server_ganesha_enabled
- name: Custom bashrc settings
ansible.builtin.import_tasks: custom_bashrc.yml