Changeset - f4e9cd36dad4
[Not reviewed]
0 4 3
Branko Majic (branko) - 8 years ago 2016-06-08 23:12:00
branko@majic.rs
MAR-57: Implemented customisation of bash shell prompt as part of the common role.
7 files changed with 197 insertions and 1 deletions:
0 comments (0 inline, 0 general)
docs/rolereference.rst
Show inline comments
 
@@ -239,6 +239,8 @@ The role implements the following:
 
* Configures apt to use caching proxy (if any was specified).
 
* Sets-up umask for all logins to ``0027``.
 
* Installs sudo.
 
* Sets-up uniform bash prompt for all accounts (optionally coloured and with
 
  identifier). This is useful for distinguishing machines and/or environments.
 
* Installs additional base packages, as configured.
 
* Creates additional operating system groups, as configured.
 
* Creates additional operating system users, as configured.
 
@@ -341,6 +343,22 @@ Parameters
 
  higher than ``incoming_connection_limit``), even if it would go above the
 
  specified connection limit.
 

	
 
**prompt_colour** (string, optional, ``none``)
 
  Colour for showing the Bash prompt. Supported values are:
 

	
 
  ``black``, ``red``, ``green``, ``brown``, ``blue``, ``purple``, ``cyan``,
 
  ``light_gray``, ``dark_gray``, ``light_red``, ``light_green``, ``yellow``,
 
  ``light_blue``, ``light_purple``, ``light_cyan``, ``white``, ``none``.
 

	
 
  You should probably *not* use the ``black`` colour. Setting affects Bash
 
  shells *only*. Setting the value to ``none`` uses default terminal colour.
 

	
 
**prompt_id** (string, optional, ``NONE``)
 
  Optional identifier appended to regular Bash prompt, useful for visually
 
  identifying distinct environments. For example, if set to ``test``, resulting
 
  prompt will be similar to ``admin@web[test]:~$``. Setting affects Bash shells
 
  *only*.
 

	
 

	
 
Examples
 
~~~~~~~~
 
@@ -380,6 +398,10 @@ packages on all servers:
 

	
 
  incoming_connection_limit_burst: 6
 

	
 
  prompt_colour: light_green
 

	
 
  prompt_id: PROD
 

	
 
.. _ldap_client:
 

	
 
LDAP Client
roles/common/defaults/main.yml
Show inline comments
 
@@ -6,4 +6,26 @@ os_users: []
 
os_groups: []
 
ca_certificates: {}
 
incoming_connection_limit: 3/second
 
incoming_connection_limit_burst: 9
 
\ No newline at end of file
 
incoming_connection_limit_burst: 9
 
prompt_colour: none
 
prompt_id: null
 

	
 
# Internal use only.
 
prompt_colour_mapping:
 
  black: "0;30"
 
  red: "0;31"
 
  green: "0;32"
 
  brown: "0;33"
 
  blue: "0;34"
 
  purple: "0;35"
 
  cyan: "0;36"
 
  light_gray: "0;37"
 
  dark_gray: "1;30"
 
  light_red: "1;31"
 
  light_green: "1;32"
 
  yellow: "1;33"
 
  light_blue: "1;34"
 
  light_purple: "1;35"
 
  light_cyan: "1;36"
 
  white: "1;37"
 
  none: "0"
 
\ No newline at end of file
roles/common/files/bashrc
Show inline comments
 
new file 100644
 
# System-wide .bashrc file for interactive bash(1) shells.
 

	
 
# To enable the settings / commands in this file for login shells as well,
 
# this file has to be sourced in /etc/profile.
 

	
 
# If not running interactively, don't do anything
 
[ -z "$PS1" ] && return
 

	
 
# check the window size after each command and, if necessary,
 
# update the values of LINES and COLUMNS.
 
shopt -s checkwinsize
 

	
 
# set variable identifying the chroot you work in (used in the prompt below)
 
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
 
    debian_chroot=$(cat /etc/debian_chroot)
 
fi
 

	
 
# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
 
# If this is an xterm set the title to user@host:dir
 
#case "$TERM" in
 
#xterm*|rxvt*)
 
#    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
 
#    ;;
 
#*)
 
#    ;;
 
#esac
 

	
 
# enable bash completion in interactive shells
 
#if ! shopt -oq posix; then
 
#  if [ -f /usr/share/bash-completion/bash_completion ]; then
 
#    . /usr/share/bash-completion/bash_completion
 
#  elif [ -f /etc/bash_completion ]; then
 
#    . /etc/bash_completion
 
#  fi
 
#fi
 

	
 
# if the command-not-found package is installed, use it
 
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
 
	function command_not_found_handle {
 
	        # check because c-n-f could've been removed in the meantime
 
                if [ -x /usr/lib/command-not-found ]; then
 
		   /usr/lib/command-not-found -- "$1"
 
                   return $?
 
                elif [ -x /usr/share/command-not-found/command-not-found ]; then
 
		   /usr/share/command-not-found/command-not-found -- "$1"
 
                   return $?
 
		else
 
		   printf "%s: command not found\n" "$1" >&2
 
		   return 127
 
		fi
 
	}
 
fi
roles/common/files/skel_bashrc
Show inline comments
 
new file 100644
 
# ~/.bashrc: executed by bash(1) for non-login shells.
 
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
 
# for examples
 

	
 
# If not running interactively, don't do anything
 
case $- in
 
    *i*) ;;
 
      *) return;;
 
esac
 

	
 
# don't put duplicate lines or lines starting with space in the history.
 
# See bash(1) for more options
 
HISTCONTROL=ignoreboth
 

	
 
# append to the history file, don't overwrite it
 
shopt -s histappend
 

	
 
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
 
HISTSIZE=1000
 
HISTFILESIZE=2000
 

	
 
# check the window size after each command and, if necessary,
 
# update the values of LINES and COLUMNS.
 
shopt -s checkwinsize
 

	
 
# If set, the pattern "**" used in a pathname expansion context will
 
# match all files and zero or more directories and subdirectories.
 
#shopt -s globstar
 

	
 
# make less more friendly for non-text input files, see lesspipe(1)
 
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
 

	
 
# set variable identifying the chroot you work in (used in the prompt below)
 
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
 
    debian_chroot=$(cat /etc/debian_chroot)
 
fi
 

	
 
# 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
 

	
 
# colored GCC warnings and errors
 
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
 

	
 
# some more ls aliases
 
#alias ll='ls -l'
 
#alias la='ls -A'
 
#alias l='ls -CF'
 

	
 
# Alias definitions.
 
# You may want to put all your additions into a separate file like
 
# ~/.bash_aliases, instead of adding them here directly.
 
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
 

	
 
if [ -f ~/.bash_aliases ]; then
 
    . ~/.bash_aliases
 
fi
 

	
 
# enable programmable completion features (you don't need to enable
 
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
 
# sources /etc/bash.bashrc).
 
if ! shopt -oq posix; then
 
  if [ -f /usr/share/bash-completion/bash_completion ]; then
 
    . /usr/share/bash-completion/bash_completion
 
  elif [ -f /etc/bash_completion ]; then
 
    . /etc/bash_completion
 
  fi
 
fi
roles/common/tasks/main.yml
Show inline comments
 
@@ -19,6 +19,17 @@
 
- name: Set home directory mask
 
  lineinfile: dest=/etc/adduser.conf state=present backrefs=yes regexp='^DIR_MODE=' line='DIR_MODE=0750'
 

	
 
- name: Deploy bash profile configuration for fancier prompts
 
  template: src="bash_prompt.sh.j2" dest="/etc/profile.d/bash_prompt.sh"
 
            owner=root group=root mode=644
 

	
 
- name: Replace default and skeleton bashrc
 
  copy: src="{{ item.key }}" dest="{{ item.value }}"
 
        owner=root group=root mode=644
 
  with_dict:
 
    skel_bashrc: "/etc/skel/.bashrc"
 
    bashrc: "/etc/bash.bashrc"
 

	
 
- name: Install sudo
 
  apt: name=sudo state=present
 

	
roles/common/templates/bash_prompt.sh.j2
Show inline comments
 
new file 100644
 
# Set-up colours.
 
if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
 
    _colour_terminal=$(tput colors 2>&1)
 
    if [[ -t 1 ]] && (( ${_colour_terminal} > 0 )); then
 
        export PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[{{ prompt_colour_mapping[prompt_colour] }}m\]\u@\h{% if prompt_id %}[{{ prompt_id }}]{% endif %}:\w\$ \[\033[0m\]'
 
    else
 
        export PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h{% if prompt_id %}[{{ prompt_id }}]{% endif %}:\w\$ '
 
    fi
 
fi
testsite/group_vars/all.yml
Show inline comments
 
@@ -79,3 +79,7 @@ backup_server_host_ssh_public_keys:
 
  - "{{ lookup('file', inventory_dir + '/ssh/backup_server_ecdsa_key.pub') }}"
 

	
 
backup_ssh_key: "{{ lookup('file', inventory_dir + '/ssh/' + ansible_fqdn) }}"
 

	
 
# Set-up prompt.
 
prompt_colour: light_purple
 
prompt_id: MAR
 
\ No newline at end of file
0 comments (0 inline, 0 general)