1
0
Fork 0
mirror of https://github.com/roles-ansible/ansible_collection_users.git synced 2024-08-16 10:29:50 +02:00

Create bashrc config - global and pre user

This commit is contained in:
L3D 2024-03-26 15:58:56 +01:00
parent dcaf92f596
commit cd250f1472
Signed by: l3d
GPG key ID: CD08445BFF4313D1
6 changed files with 118 additions and 15 deletions

View file

@ -70,6 +70,7 @@ The Option of these directory-variables are the following.
| ``pubkeys`` | string or lookup | - | see examples | | ``pubkeys`` | string or lookup | - | see examples |
| ``exklusive_pubkeys`` | ``true`` | - | delete all undefined ssh keys | | ``exklusive_pubkeys`` | ``true`` | - | delete all undefined ssh keys |
| ``password`` | password hash | - | See [official FAQ](https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-generate-encrypted-passwords-for-the-user-module) | | ``password`` | password hash | - | See [official FAQ](https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-generate-encrypted-passwords-for-the-user-module) |
| ``bashrc`` | list | - | adding additional content to l3d.users.dotfiles to .bashrc |
| ``groups`` | list | - | Additional groups for your user | | ``groups`` | list | - | Additional groups for your user |
| ``remove`` | ``false`` | - | completly remove user if ``state: absent`` | | ``remove`` | ``false`` | - | completly remove user if ``state: absent`` |

View file

@ -27,6 +27,7 @@ The Option of these directory-variables are the following.
| ``pubkeys`` | string or lookup | - | see examples | | ``pubkeys`` | string or lookup | - | see examples |
| ``exklusive_pubkeys`` | ``true`` | - | delete all undefined ssh keys | | ``exklusive_pubkeys`` | ``true`` | - | delete all undefined ssh keys |
| ``password`` | password hash | - | See [official FAQ](https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-generate-encrypted-passwords-for-the-user-module) | | ``password`` | password hash | - | See [official FAQ](https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-generate-encrypted-passwords-for-the-user-module) |
| ``bashrc`` | list | - | adding additional content to l3d.users.dotfiles to .bashrc |
| ``groups`` | list | - | Additional groups for your user | | ``groups`` | list | - | Additional groups for your user |
| ``remove`` | ``false`` | - | completly remove user if ``state: absent`` | | ``remove`` | ``false`` | - | completly remove user if ``state: absent`` |

View file

@ -15,6 +15,8 @@ l3d_users__default_users: []
# admin_commands: 'ALL' # admin_commands: 'ALL'
# admin_nopassword: false # admin_nopassword: false
# admin_ansible_login: true # admin_ansible_login: true
# bashrc:
# - '[[ $- == *i* ]] && eval $(keychain --eval --quiet id_ed25519)'
# - name: 'bob' # - name: 'bob'
# state: 'present' # state: 'present'
# shell: '/bin/zsh' # shell: '/bin/zsh'
@ -29,6 +31,31 @@ l3d_users__local_users: []
# pubkeys: "{{ lookup('url', 'https://github.com/do1jlr.keys', split_lines=False) }}" # pubkeys: "{{ lookup('url', 'https://github.com/do1jlr.keys', split_lines=False) }}"
l3d_users__bashrc: true l3d_users__bashrc: true
l3d_users__dotfiles__bash_completion_enabled: true
l3d_users__dotfiles__aliases:
- {alias: "ls", command: "ls ", color: true}
- {alias: "grep", command: "grep", color: true}
- {alias: "ll", command: "ls -alF", color: false}
- {alias: "la", command: "ls -A", color: false}
- {alias: "l", command: "ls -CF", color: false}
- {alias: "lz", command: "ls -Z", color: false}
- {alias: "EDITOR", command: "/usr/bin/vim", color: false}
- {alias: "VISUAL", command: "/usr/bin/gedit", color: false}
- {alias: "gitsubpull", command: "git submodule foreach '(git checkout \\$(git symbolic-ref --short refs/remotes/origin/HEAD | sed 's@^origin/@@'); git pull)'", color: false}
- {alias: "pwgen", command: "/usr/bin/pwgen --num-passwords=3000 --numerals --capitalize --secure --no-vowels --ambiguous 95 1", color: false}
- {alias: "gdiff", command: "git diff --submodule=diff", color: false}
dotfiles__additional_user_bashrc_lines: []
l3d_users__bashrc_path: "$HOME/.local/bin:$HOME/bin:$HOME/.cargo/env:$PATH"
# PS1 Prompt
l3d_users__dotfiles__user_prompt: '\e]0; \u@\H <\A> \w\a\[\033[01;33m\] $(printf "\xE2\x9D\xA4") \[\033[01;32m\]\u\[\033[01;36m\]@\[\033[01;32m\]\H\[\033[01;34m\] <\A> \[\033[01;35m\] \j \[\033[01;36m\] \w \[\033[01;33m\]\n\[\033[01;33m\] $(git branch 2>/dev/null | sed -n "s/* \(.*\)/\1 /p")$\[\033[01;00m\]'
l3d_users__dotfiles__root_prompt: '\e]0; \u@\H <\A> \w\a\[\033[01;31m\] $(printf "\xE2\x9D\xA4") \[\033[01;32m\]\u\[\033[01;36m\]@\[\033[01;32m\]\H\[\033[01;34m\] <\A> \[\033[01;35m\] \j \[\033[01;36m\] \w \[\033[01;33m\]\n\[\033[01;33m\] $(git branch 2>/dev/null | sed -n "s/* \(.*\)/\1 /p")$\[\033[01;00m\]'
# bash_history
l3d_users__dotfiles__history_control: 'ignoreboth'
l3d_users__dotfiles__history_size: '-1'
l3d_users__dotfiles__history_file_size: '-1'
# run simple versionscheck # run simple versionscheck
submodules_versioncheck: false submodules_versioncheck: false

View file

@ -4,6 +4,21 @@
ansible.builtin.template: ansible.builtin.template:
src: 'templates/bash.bashrc.j2' src: 'templates/bash.bashrc.j2'
dest: '/etc/bash.bashrc' dest: '/etc/bash.bashrc'
owner: root owner: 'root'
group: root group: 'root'
mode: 'u=rw,g=r,o=r' mode: 'u=rw,g=r,o=r'
- name: Create global bashrc configuration
become: true
ansible.builtin.template:
src: 'templates/dotbashrc.j2'
dest: "{{ user.home | default('/home/' + user.name) }}/.bashrc"
owner: "{{ user.name }}"
group: "{{ user.name }}"
mode: '0640'
loop: "{{ _l3d_users__merged_users }}"
loop_control:
label: "user={{ user.name }}"
loop_var: user
when: user.state | default ('present') == 'present'

View file

@ -1,11 +1,9 @@
# /etc/bashrc # /etc/bashrc
{{ ansible_managed | comment }}
# System wide functions and aliases # System wide functions and aliases
# Environment stuff goes in /etc/profile # Environment stuff goes in /etc/profile
# This file may be overwritten by ansible. Please think about commiting
# changes you want to keep persistent.
# enable color support of ls and also add handy aliases # enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
@ -16,13 +14,13 @@ if [ -x /usr/bin/dircolors ]; then
{% endfor %} {% endfor %}
fi fi
{% for alias in dotfiles__aliases %} {% for alias in l3d_users__dotfiles__aliases %}
{% if not alias.color %} {% if not alias.color %}
alias {{ alias.alias }}="{{ alias.command }}" alias {{ alias.alias }}="{{ alias.command }}"
{% endif%} {% endif%}
{% endfor %} {% endfor %}
{%if dotfiles__bash_completion_enabled %} {%if l3d_users__dotfiles__bash_completion_enabled %}
if ! shopt -oq posix; then if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion . /usr/share/bash-completion/bash_completion
@ -35,13 +33,13 @@ fi
# fancy Prompt # fancy Prompt
if [ $(id -u) -eq 0 ]; then if [ $(id -u) -eq 0 ]; then
export PS1='{{ dotfiles__root_prompt }} ' export PS1='{{ l3d_users__dotfiles__root_prompt }} '
else else
export PS1='{{ dotfiles__user_prompt }} ' export PS1='{{ l3d_users__dotfiles__user_prompt }} '
fi fi
HISTCONTROL={{ dotfiles__history_control }} HISTCONTROL={{ l3d_users__dotfiles__history_control }}
shopt -s histappend shopt -s histappend
{% if ansible_os_family == 'Redhat' %} {% if ansible_os_family == 'Redhat' %}
# HISTSIZE={{ dotfiles__history_size }} # HISTSIZE={{ dotfiles__history_size }}
@ -53,9 +51,4 @@ shopt -s histappend
HISTSIZE={{ dotfiles__history_size }} HISTSIZE={{ dotfiles__history_size }}
HISTFILESIZE={{ dotfiles__history_file_size }} HISTFILESIZE={{ dotfiles__history_file_size }}
{% endif %} {% endif %}
{% for _row in dotfiles__additional_bashrc_lines | default() %}
{{ _row }}
{% endfor %}
# vim:ts=4:sw=4 # vim:ts=4:sw=4

View file

@ -0,0 +1,66 @@
# {{ user.home | default('/home/' + user.name) }}/.bashrc"
# for user {{ user.name }}
{{ ansible_managed | comment }}
# Source global definitions
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
# User specific environment
PATH="{{ l3d_users__bashrc_path }}"
export PATH
# 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)"
{% for alias in dotfiles__aliases %}
{% if alias.color %}
alias {{ alias.alias }}="{{ alias.command }} --color=auto"
{% endif%}
{% endfor %}
fi
{% for alias in l3d_users__dotfiles__aliases %}
{% if not alias.color %}
alias {{ alias.alias }}="{{ alias.command }}"
{% endif%}
{% endfor %}
{%if l3d_users__dotfiles__bash_completion_enabled %}
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
# fancy Prompt
export PS1='{{ l3d_users__dotfiles__user_prompt }} '
# baqsh_history
HISTCONTROL={{ l3d_users__dotfiles__history_control }}
shopt -s histappend
{% if ansible_os_family == 'Redhat' %}
# HISTSIZE={{ dotfiles__history_size }}
# HISTFILESIZE={{ dotfiles__history_file_size }}
{% elif ansible_distribution == "CentOS" %}
# HISTSIZE={{ dotfiles__history_size }}
# HISTFILESIZE={{ dotfiles__history_file_size }}
{% else %}
HISTSIZE={{ dotfiles__history_size }}
HISTFILESIZE={{ dotfiles__history_file_size }}
{% endif %}
# additional general rules
{% for _row in dotfiles__additional_user_bashrc_lines | default() %}
{{ _row }}
{% endfor %}
# additional user rules
{% for custom in {{ user.bashrc | default([]) }} %}
{{ custom }}
{% endfor %}
# vim:ts=4:sw=4