Enabling color prompt
The default color of the Ubuntu Bash prompt is a light shade of gray. This playbook enables color prompts.
Creating the playbook
Executed:
aadmin@uvm0:~/code/it-wiz/devops/ansible/projects/playbooks$ touch enable_color_prompt.yml
Brought enable_color_prompt.yml to the following form:
- name: Update .bashrc for all human users and root and in /etc/skel/.bashrc
hosts: all
tasks:
- name: Get list of human users
ansible.builtin.shell: |
getent passwd | awk -F: '$3 >= 1000 && $3 != 65534 {print $1}'
register: human_users
changed_when: false
- name: Update .bashrc for human users
ansible.builtin.lineinfile:
path: "/home/{{ item }}/.bashrc"
regexp: '^#force_color_prompt=yes'
line: 'force_color_prompt=yes'
loop: "{{ human_users.stdout_lines }}"
no_log: true
- name: Update .bashrc for root
ansible.builtin.lineinfile:
path: "/root/.bashrc"
regexp: '^#force_color_prompt=yes'
line: 'force_color_prompt=yes'
- name: Update /etc/skel/.bashrc
ansible.builtin.lineinfile:
path: "/etc/skel/.bashrc"
regexp: '^#force_color_prompt=yes'
line: 'force_color_prompt=yes'
Intended result
In each .bashrc file #force_color_prompt=yes
string should get replaced by force_color_prompt=yes
.
Explanations
The first task registers all the names of the users with UIDs starting with 1000, while skipping the nobody (having the UID of 65534).
The no_log: true
instruction obfuscates the names of the human users and can be skipped, if the names should be visible.
First execution of the playbook
Executed:
aadmin@uvm0:~/code/it-wiz/devops/ansible/projects$ ansible-playbook playbooks/enable_color_prompt.yml --ask-vault-password
Details
aadmin@uvm0:~/code/it-wiz/devops/ansible/projects$ ansible-playbook playbooks/enable_color_prompt.yml --ask-vault-password
Vault password:
PLAY [Modify .bashrc for all human users and root and in /etc/skel/.bashrc] **************************************
TASK [Gathering Facts] *******************************************************************************************
ok: [uvm27]
ok: [uvm26]
TASK [Get list of human users] ***********************************************************************************
ok: [uvm26]
ok: [uvm27]
TASK [Modify .bashrc for human users] ****************************************************************************
changed: [uvm26] => (item=None)
changed: [uvm27] => (item=None)
changed: [uvm26] => (item=None)
changed: [uvm26]
changed: [uvm27] => (item=None)
changed: [uvm27]
TASK [Modify .bashrc for root] ***********************************************************************************
changed: [uvm26]
changed: [uvm27]
TASK [Modify /etc/skel/.bashrc] **********************************************************************************
changed: [uvm26]
changed: [uvm27]
PLAY RECAP *******************************************************************************************************
uvm26 : ok=5 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
uvm27 : ok=5 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Result
All user prompts for exising users became colored.
In particular, the color of the prompt turned green both in PuTTY and in the VMware Remote Console.
PuTTY
VRMC
Prompts for new users should also become colored.
Subsequent execution of the playbook
Executed:
aadmin@uvm0:~/code/it-wiz/devops/ansible/projects$ ansible-playbook playbooks/enable_color_prompt.yml --ask-vault-password
Details
aadmin@uvm0:~/code/it-wiz/devops/ansible/projects$ ansible-playbook playbooks/enable_color_prompt.yml --ask-vault-password
Vault password:
PLAY [Modify .bashrc for all human users and root and in /etc/skel/.bashrc] **************************************
TASK [Gathering Facts] *******************************************************************************************
ok: [uvm27]
ok: [uvm26]
TASK [Get list of human users] ***********************************************************************************
ok: [uvm26]
ok: [uvm27]
TASK [Modify .bashrc for human users] ****************************************************************************
ok: [uvm26] => (item=None)
ok: [uvm27] => (item=None)
ok: [uvm26] => (item=None)
ok: [uvm26]
ok: [uvm27] => (item=None)
ok: [uvm27]
TASK [Modify .bashrc for root] ***********************************************************************************
ok: [uvm26]
ok: [uvm27]
TASK [Modify /etc/skel/.bashrc] **********************************************************************************
ok: [uvm26]
ok: [uvm27]
PLAY RECAP *******************************************************************************************************
uvm26 : ok=5 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
uvm27 : ok=5 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Result
No changes were made.