From 17f7954f8755098363e4dea9f2a8d178329ca579 Mon Sep 17 00:00:00 2001 From: L3D Date: Fri, 24 May 2024 11:40:08 +0200 Subject: [PATCH] improved editor config --- README.md | 2 ++ roles/dotfiles/README.md | 2 ++ roles/dotfiles/defaults/main.yml | 7 +++++-- roles/dotfiles/tasks/bashrc.yml | 13 +++++++++++++ roles/dotfiles/templates/bash.bashrc.j2 | 5 +++++ roles/dotfiles/templates/dotbashrc.j2 | 14 ++++++++++---- roles/dotfiles/vars/main.yml | 2 +- 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ae40191..5fdaf36 100644 --- a/README.md +++ b/README.md @@ -107,8 +107,10 @@ There is also the ``l3d_users__ssh_login`` variable which only supports ``name`` | ``l3d_users__sshd_macs`` | ``['hmac-sha2-512-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512']`` | Used MACs | | ``l3d_users__sshd_xforwarding`` |``true`` | Enable X-Forwarding | | ``l3d_users__bashrc`` | ``true`` | Configure bashrc | +| ``l3d_users__root_bashrc`` | ``true`` | Set bashrc for root | | ``l3d_users__dotfiles__bash_completion_enabled`` | ``true`` | Enable bash completion | | ``l3d_users__dotfiles__aliases`` | *see [roles/dotfiles/defaults/main.yml](roles/dotfiles/defaults/main.yml)* | A predefined list of usefull aliases for your bash config | +| ``l3d_users__dotfiles__variables`` | *see [defaults/main.yml](defaults/main.yml)* | A predefined list of usefull variables for your bash config | | ``l3d_users__dotfiles__additional_user_bashrc_lines`` | ``[]`` | variable for additional bashrc lines | | ``l3d_users__bashrc_path`` | ``$HOME/.local/bin:$HOME/bin:$HOME/.cargo/env:$PATH``| bashrc $PATH | | ``l3d_users__dotfiles__user_prompt`` | *see [roles/dotfiles/defaults/main.yml](roles/dotfiles/defaults/main.yml)* | PS1 prompt for users | diff --git a/roles/dotfiles/README.md b/roles/dotfiles/README.md index 6def50f..9608a28 100644 --- a/roles/dotfiles/README.md +++ b/roles/dotfiles/README.md @@ -38,8 +38,10 @@ There is a third directory-variable called ``l3d_users__ssh_login: []`` which on | name | default value | description | | --- | --- | --- | | ``l3d_users__bashrc`` | ``true`` | Configure bashrc | +| ``l3d_users__root_bashrc`` | ``true`` | Set bashrc for root | | ``l3d_users__dotfiles__bash_completion_enabled`` | ``true`` | Enable bash completion | | ``l3d_users__dotfiles__aliases`` | *see [defaults/main.yml](defaults/main.yml)* | A predefined list of usefull aliases for your bash config | +| ``l3d_users__dotfiles__variables`` | *see [defaults/main.yml](defaults/main.yml)* | A predefined list of usefull variables for your bash config | | ``l3d_users__dotfiles__additional_user_bashrc_lines`` | ``[]`` | variable for additional bashrc lines | | ``l3d_users__bashrc_path`` | ``$HOME/.local/bin:$HOME/bin:$HOME/.cargo/env:$PATH``| bashrc $PATH | | ``l3d_users__dotfiles__user_prompt`` | *see [defaults/main.yml](defaults/main.yml)* | PS1 prompt for users | diff --git a/roles/dotfiles/defaults/main.yml b/roles/dotfiles/defaults/main.yml index ab00062..45babd6 100644 --- a/roles/dotfiles/defaults/main.yml +++ b/roles/dotfiles/defaults/main.yml @@ -31,6 +31,7 @@ l3d_users__local_users: [] # pubkeys: "{{ lookup('url', 'https://github.com/do1jlr.keys', split_lines=False) }}" l3d_users__bashrc: true +l3d_users__root_bashrc: true l3d_users__dotfiles__bash_completion_enabled: true l3d_users__dotfiles__aliases: - {alias: "ls", command: "ls ", color: true} @@ -39,13 +40,15 @@ l3d_users__dotfiles__aliases: - {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 ; 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} - {alias: "ip", command: "ip ", color: true} +l3d_users__dotfiles__variables: + - {var: "EDITOR", command: "/usr/bin/vim"} + - {var: "VISUAL", command: "/usr/bin/gedit"} + l3d_users__dotfiles__additional_user_bashrc_lines: [] l3d_users__bashrc_path: "$HOME/.local/bin:$HOME/bin:$HOME/.cargo/env:$PATH" diff --git a/roles/dotfiles/tasks/bashrc.yml b/roles/dotfiles/tasks/bashrc.yml index d6220f5..7003db1 100644 --- a/roles/dotfiles/tasks/bashrc.yml +++ b/roles/dotfiles/tasks/bashrc.yml @@ -6,6 +6,7 @@ dest: '/etc/bash.bashrc' owner: 'root' group: 'root' + backup: true mode: 'u=rw,g=r,o=r' - name: Create bashrc configuration per user @@ -16,8 +17,20 @@ owner: "{{ user.name }}" group: "{{ user.name }}" mode: '0640' + backup: true loop: "{{ _l3d_users__merged_users }}" loop_control: label: "user={{ user.name }}" loop_var: user when: user.state | default ('present') == 'present' + +- name: Create bashrc for root + become: true + ansible.builtin.template: + src: 'templates/dotbashrc.j2' + dest: "/root/.bashrc" + owner: 'root' + group: 'root' + mode: '0640' + backup: true + when: user.state | default ('present') == 'present' diff --git a/roles/dotfiles/templates/bash.bashrc.j2 b/roles/dotfiles/templates/bash.bashrc.j2 index 59433e2..9e16983 100644 --- a/roles/dotfiles/templates/bash.bashrc.j2 +++ b/roles/dotfiles/templates/bash.bashrc.j2 @@ -20,6 +20,11 @@ fi {% endif %} {% endfor %} +# set variables +{% for vars in l3d_users__dotfiles__variables %} +export {{ vars.var }}="{{ vars.command }}" +{% endfor %} + {% if l3d_users__dotfiles__bash_completion_enabled %} if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then diff --git a/roles/dotfiles/templates/dotbashrc.j2 b/roles/dotfiles/templates/dotbashrc.j2 index e123388..b088d12 100644 --- a/roles/dotfiles/templates/dotbashrc.j2 +++ b/roles/dotfiles/templates/dotbashrc.j2 @@ -1,5 +1,9 @@ +{% if user is defined %} # {{ user.home | default('/home/' + user.name) }}/.bashrc" # for user {{ user.name }} +{% else %} +# /root/.bashrc +{% endif %} {{ ansible_managed | ansible.builtin.comment }} # Source global definitions @@ -40,7 +44,7 @@ fi # fancy Prompt export PS1='{{ l3d_users__dotfiles__user_prompt }} ' -# baqsh_history +# bash_history HISTCONTROL={{ l3d_users__dotfiles__history_control }} shopt -s histappend {% if ansible_os_family == 'Redhat' %} @@ -59,9 +63,11 @@ HISTFILESIZE={{ l3d_users__dotfiles__history_file_size }} {{ _row }} {% endfor %} +{% if user is defined %} # additional user rules -{% for custom in user.bashrc | default([]) %} -{{ custom }} -{% endfor %} +{% for custom in user.bashrc | default([]) %} +{{ custom }} +{% endfor %} +{% endif %} # vim:ts=4:sw=4 diff --git a/roles/dotfiles/vars/main.yml b/roles/dotfiles/vars/main.yml index 93d31ac..cc3912b 100644 --- a/roles/dotfiles/vars/main.yml +++ b/roles/dotfiles/vars/main.yml @@ -5,5 +5,5 @@ l3d_users__dotfiles_packages: - htop - tmux -playbook_version_number: 9 +playbook_version_number: 10 playbook_version_path: 'l3d.users.dotfiles.version'