diff --git a/roles/user-administrator/README.md b/roles/user-administrator/README.md index 65cbed68..6262e1f2 100644 --- a/roles/user-administrator/README.md +++ b/roles/user-administrator/README.md @@ -4,3 +4,6 @@ This user needs to type in his password before executing sudo. For security reasons it's recommended to use this user instead of the standard root user. This user should not be used to login to other systems. It's just there to let administration tasks run. For this reason no ssh-keys are generated. + +## Author +This role was created by [Kevin Veen-Birkenbach](https://www.veen.world/) diff --git a/roles/user-administrator/tasks/main.yml b/roles/user-administrator/tasks/main.yml index 5e00ee6c..5cd877e0 100644 --- a/roles/user-administrator/tasks/main.yml +++ b/roles/user-administrator/tasks/main.yml @@ -46,6 +46,13 @@ notify: sshd restart when: run_once_user_administrator is not defined +- name: "embed user routines for {{ role_path | basename }}" + include_role: + name: user + vars: + user_name: "administrator" + when: run_once_user_administrator is not defined + - name: run the user_administrator tasks once set_fact: run_once_user_administrator: true diff --git a/roles/user-root/README.md b/roles/user-root/README.md index d9f81b20..8eba0247 100644 --- a/roles/user-root/README.md +++ b/roles/user-root/README.md @@ -1,4 +1,3 @@ -Certainly! Below is a README file in English for an Ansible role that includes the tasks you've provided: # Root User ## Overview @@ -14,16 +13,9 @@ This Ansible role is designed to manage the generation and handling of an SSH ke 4. **Output the public SSH key**: Debug task to display the SSH public key in the Ansible output. 5. **Run the user_root tasks once**: Sets a fact to ensure that the tasks for generating and displaying the key are executed only once. -## Usage -To use this role, include it in your playbook and set any necessary variables in your playbook's `vars` section. Ensure you have the necessary permissions to execute tasks as the root user. - -```yaml -- hosts: servers - become: yes - roles: - - ssh_key_generator_root -``` - ## Important Notes - Running this role will affect the root user's SSH configuration on the target system. Ensure you understand the implications of modifying root SSH keys. - Always test the role in a controlled environment before deploying to production. + +## Author +This role was created by [Kevin Veen-Birkenbach](https://www.veen.world/) diff --git a/roles/user-root/tasks/main.yml b/roles/user-root/tasks/main.yml index 046d5fa5..1fe7f5a4 100644 --- a/roles/user-root/tasks/main.yml +++ b/roles/user-root/tasks/main.yml @@ -20,6 +20,13 @@ msg: "{{ public_key.stdout }}" when: not ssh_key.stat.exists and run_once_user_root is not defined +- name: "embed user routines for {{ role_path | basename }}" + include_role: + name: user + vars: + user_name: "root" + when: run_once_user_root is not defined + - name: run the user_root tasks once set_fact: run_once_user_root: true diff --git a/roles/user/README.md b/roles/user/README.md new file mode 100644 index 00000000..bdc1def6 --- /dev/null +++ b/roles/user/README.md @@ -0,0 +1 @@ +This role executes tasks which are relevant for all users \ No newline at end of file diff --git a/roles/user/tasks/main.yml b/roles/user/tasks/main.yml new file mode 100644 index 00000000..98fcad39 --- /dev/null +++ b/roles/user/tasks/main.yml @@ -0,0 +1,6 @@ +- name: create .bashrc + template: + src: "bashrc.j2" + dest: "/home/{{user_name}}/.bashrc" + owner: {{user_name}} + group: {{user_name}} \ No newline at end of file diff --git a/roles/user/templates/bashrc.j2 b/roles/user/templates/bashrc.j2 new file mode 100644 index 00000000..7c32d25e --- /dev/null +++ b/roles/user/templates/bashrc.j2 @@ -0,0 +1,59 @@ + GNU nano 8.3 .bashrc +#!/bin/bash + +# If not running interactively, don't do anything +[[ $- != *i* ]] && return + +# Set color variables based on the current user +if [ "$USER" = "root" ]; then + HEADER_COLOR="\033[1;31m" # Bold red for root +elif [ "$USER" = "administrator" ]; then + HEADER_COLOR="\033[1;38;5;208m" # Bold orange for administrator +else + HEADER_COLOR="\033[1;33m" # Bold yellow for other users +fi +RESET_COLOR="\033[0m" + +# Welcome message +echo -e "${HEADER_COLOR}Welcome, $USER on $HOSTNAME!${RESET_COLOR}" +echo -e "${HEADER_COLOR}Today is $(date +"%A, %d.%m.%Y %T")${RESET_COLOR}" +echo "" + +# System Load (shows load averages and uptime) +echo -e "${HEADER_COLOR}System Load:${RESET_COLOR}" +uptime +echo "" + +# Memory Usage (RAM and swap) +echo -e "${HEADER_COLOR}Memory Usage:${RESET_COLOR}" +free -h +echo "" + +# Disk Usage +echo -e "${HEADER_COLOR}Disk Usage:${RESET_COLOR}" +df -h +echo "" + +# CPU Information (e.g., model name) +echo -e "${HEADER_COLOR}CPU Information:${RESET_COLOR}" +lscpu | grep "Model name" +echo "" + +# Top 5 Processes by CPU Usage +echo -e "${HEADER_COLOR}Top 5 Processes by CPU Usage:${RESET_COLOR}" +ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%cpu | head -n 6 +echo "" + +alias ls='ls --color=auto' +alias grep='grep --color=auto' +PS1="\$(if [ \"\$USER\" = \"administrator\" ]; then \ + echo \"\[\033[4;38;5;208m\]$USER\"; \ + elif [ \"\$USER\" = \"root\" ]; then \ + echo \"\[\033[4;5;1;31m\]$USER\"; \ + else \ + echo \"\[\033[4;33m\]\$USER\"; \ + fi)@\$(if [ \"\$USER\" = \"root\" ]; then \ + echo \"\[\033[1;4;5;32m\]\h\"; \ + else \ + echo \"\[\033[1;4;32m\]\h\"; \ + fi) \[\033[90m\]\$(date +%H:%M:%S)\[\033[0m\]:\[\033[38;5;13m\]\w \[\033[0m\]\$ " \ No newline at end of file