feat: support bashrc aliases, envs and functions
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Markus Pesch 2024-03-02 19:20:05 +01:00
parent 75fea198c2
commit 5907f1617a
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
4 changed files with 67 additions and 0 deletions

View File

@ -25,6 +25,18 @@ unix_users: {}
# home: /home/alice # home: /home/alice
# btrfs: false # btrfs: false
# shell: /bin/bash # shell: /bin/bash
# shell_rc_files:
# - file: "/home/alice/.bashrc.d"
# aliases:
# - key: "dcd"
# value: "docker-compose down"
# envs:
# - export: true
# key: "PATH"
# value: "${XDG_BIN_DIR}:${PATH}"
# functions:
# - name: "foo"
# value: "echo \"bar\""
# group: alice # group: alice
# groups: [] # groups: []
# password: "" # password: ""

View File

@ -0,0 +1,25 @@
---
- name: "Create shell rc file directory {{ shell_rc_file.file | dirname }}"
ansible.builtin.file:
path: "{{ shell_rc_file.file | dirname }}"
owner: "{{ unix_user.key }}"
group: "{{ unix_user.value.group | default('users') }}"
mode: "0755"
state: "directory"
- name: "Create shell rc file {{ shell_rc_file.file }}"
ansible.builtin.template:
src: shell_rc_file.j2
dest: "{{ shell_rc_file.file }}"
owner: "{{ unix_user.key }}"
group: "{{ unix_user.value.group | default('users') }}"
mode: "0644"
- name: "Source shell rc file {{ shell_rc_file.file }}"
ansible.builtin.lineinfile:
path: "{{ user_user_home }}/.bashrc"
line: "source \"{{ shell_rc_file.file }}\""
owner: "{{ unix_user.key }}"
group: "{{ unix_user.value.group | default('users') }}"
state: "present"

View File

@ -187,3 +187,10 @@
- "{{ unix_user.value.xdg.dirs.config | default(user_user_home + '/.config') }}" - "{{ unix_user.value.xdg.dirs.config | default(user_user_home + '/.config') }}"
- "{{ unix_user.value.xdg.dirs.data | default(user_user_home + '/.local/share') }}" - "{{ unix_user.value.xdg.dirs.data | default(user_user_home + '/.local/share') }}"
- "{{ unix_user.value.xdg.dirs.state | default(user_user_home + '/.local/state') }}" - "{{ unix_user.value.xdg.dirs.state | default(user_user_home + '/.local/state') }}"
- name: "Create shell rc files"
ansible.builtin.include_tasks: create_shell_rc_file.yml
with_items:
- "{{ unix_user.value.shell_rc_files }}"
loop_control:
loop_var: shell_rc_file

View File

@ -0,0 +1,23 @@
#
# {{ ansible_managed }}
#
{% if shell_rc_file.functions is defined %}
{% for function in shell_rc_file.functions %}
function {{ function.name }} {
{{ function.body | indent(2, True) }}
}
{% endfor %}
{% endif %}
{% if shell_rc_file.envs is defined %}
{% for env in shell_rc_file.envs %}
{{ 'export ' if env.export is defined and env.export }}{{ env.key }}="{{ env.value }}"
{% endfor %}
{% endif %}
{% if shell_rc_file.aliases is defined %}
{% for alias in shell_rc_file.aliases %}
alias {{ alias.key }}='{{ alias.value }}'
{% endfor %}
{% endif %}