Ensure the .bashrc exists, expand aliases after sudo and color grep in the common role aliases

This commit is contained in:
2026-10-09 14:37:23 +00:00
parent 23ed82b113
commit c7eceae087
+21
View File
@@ -1,3 +1,9 @@
- name: Ensure .bashrc exists
file:
path: "{{ ansible_facts.env.HOME }}/.bashrc"
state: touch
mode: "0644"
- name: General aliases - name: General aliases
blockinfile: blockinfile:
path: "{{ ansible_facts.env.HOME }}/.bashrc" path: "{{ ansible_facts.env.HOME }}/.bashrc"
@@ -8,11 +14,26 @@
alias syslog="tail -f --lines=100 /var/log/syslog" alias syslog="tail -f --lines=100 /var/log/syslog"
alias cp="rsync -hlAXEptgoDS --numeric-ids --info=progress2" alias cp="rsync -hlAXEptgoDS --numeric-ids --info=progress2"
# We can tell bash to check the next word after the alias (i.e sudo) by adding a space to the end of the alias value. https://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo
alias sudo='sudo '
- name: ls aliases and colors - name: ls aliases and colors
blockinfile: blockinfile:
path: "{{ ansible_facts.env.HOME }}/.bashrc" path: "{{ ansible_facts.env.HOME }}/.bashrc"
marker: "# {mark} ANSIBLE MANAGED BLOCK | ls aliases and colors" marker: "# {mark} ANSIBLE MANAGED BLOCK | ls aliases and colors"
block: | block: |
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
export LS_OPTIONS='--color=auto' export LS_OPTIONS='--color=auto'
eval "`dircolors`" eval "`dircolors`"
alias ls='ls $LS_OPTIONS' alias ls='ls $LS_OPTIONS'