feat: support bashrc aliases, envs and functions
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
75fea198c2
commit
5907f1617a
@ -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: ""
|
||||||
|
25
tasks/create_shell_rc_file.yml
Normal file
25
tasks/create_shell_rc_file.yml
Normal 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"
|
@ -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
|
||||||
|
23
templates/shell_rc_file.j2
Normal file
23
templates/shell_rc_file.j2
Normal 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 %}
|
Loading…
Reference in New Issue
Block a user