From c7eceae08738a76c3a1ba76322660bc69b5a8ef4 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Fri, 9 Oct 2026 14:37:23 +0000 Subject: [PATCH] Ensure the .bashrc exists, expand aliases after sudo and color grep in the common role aliases --- common/tasks/aliases.yml | 51 ++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/common/tasks/aliases.yml b/common/tasks/aliases.yml index 0cd19e3..14e0d4e 100644 --- a/common/tasks/aliases.yml +++ b/common/tasks/aliases.yml @@ -1,20 +1,41 @@ +- name: Ensure .bashrc exists + file: + path: "{{ ansible_facts.env.HOME }}/.bashrc" + state: touch + mode: "0644" + - name: General aliases blockinfile: - path: "{{ ansible_facts.env.HOME }}/.bashrc" - marker: "# {mark} ANSIBLE MANAGED BLOCK | General aliases" - block: | - alias clr="clear" - alias hgrep="history | grep" - alias syslog="tail -f --lines=100 /var/log/syslog" - alias cp="rsync -hlAXEptgoDS --numeric-ids --info=progress2" + path: "{{ ansible_facts.env.HOME }}/.bashrc" + marker: "# {mark} ANSIBLE MANAGED BLOCK | General aliases" + block: | + alias clr="clear" + alias hgrep="history | grep" + alias syslog="tail -f --lines=100 /var/log/syslog" + 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 blockinfile: - path: "{{ ansible_facts.env.HOME }}/.bashrc" - marker: "# {mark} ANSIBLE MANAGED BLOCK | ls aliases and colors" - block: | - export LS_OPTIONS='--color=auto' - eval "`dircolors`" - alias ls='ls $LS_OPTIONS' - alias ll='ls $LS_OPTIONS -l' - alias l='ls $LS_OPTIONS -la' + path: "{{ ansible_facts.env.HOME }}/.bashrc" + marker: "# {mark} ANSIBLE MANAGED BLOCK | ls aliases and colors" + 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' + eval "`dircolors`" + alias ls='ls $LS_OPTIONS' + alias ll='ls $LS_OPTIONS -l' + alias l='ls $LS_OPTIONS -la'