90 lines
3.1 KiB
YAML
90 lines
3.1 KiB
YAML
- block:
|
|
- name: "Create user '{{ user.username }}'."
|
|
tags: users
|
|
ansible.builtin.user:
|
|
name: "{{ user.username }}"
|
|
state: "{{ user.state | default('present') }}"
|
|
group: "{{ user.group | default(user.username) }}"
|
|
groups: "{{ user.groups | default(omit) | join(',') }}"
|
|
comment: "{{ user.comment | default(omit) }}"
|
|
shell: "{{ user.shell | default(omit) }}"
|
|
password: "{{ user.password | default(omit) }}"
|
|
system: "{{ user.system | default(omit) }}"
|
|
uid: "{{ user.uid | default(omit) }}"
|
|
gid: "{{ user.gid | default(omit) }}"
|
|
update_password: on_create
|
|
|
|
- name: "Create sudoers file for user '{{ user.username }}'."
|
|
tags: users,sudo
|
|
ansible.builtin.template:
|
|
src: "sudoers"
|
|
dest: "/etc/sudoers.d/{{ user.username }}"
|
|
owner: root
|
|
group: root
|
|
mode: 0440
|
|
when:
|
|
- user.sudo | default(false)
|
|
|
|
- name: "Create config directories for user '{{ user.username }}'."
|
|
tags: users
|
|
ansible.builtin.file:
|
|
path: "{{ user.home_dir | default('/home/' + user.username) }}/{{ item }}"
|
|
state: directory
|
|
owner: "{{ user.username }}"
|
|
group: "{{ user.username }}"
|
|
mode: 0700
|
|
with_items: "{{ user.config_dirs | default([]) }}"
|
|
|
|
- name: "Copy config files for user '{{ user.username }}'."
|
|
tags: users
|
|
ansible.builtin.copy:
|
|
src: "{{ item.src }}"
|
|
dest: "{{user.home_dir | default('/home/' + user.username) }}/{{ item.dest }}"
|
|
owner: "{{ user.username }}"
|
|
group: "{{ user.username }}"
|
|
mode: 0600
|
|
with_items: "{{ user.config_files | default([]) }}"
|
|
register: dotfiles_installed
|
|
|
|
- name: "Create config files from templates for user '{{ user.username }}'."
|
|
tags: users
|
|
ansible.builtin.template:
|
|
src: "{{ item.src }}"
|
|
dest: "{{user.home_dir | default('/home/' + user.username) }}/{{ item.dest }}"
|
|
owner: "{{ user.username }}"
|
|
group: "{{ user.username }}"
|
|
mode: 0600
|
|
with_items: "{{ user.config_templates | default([]) }}"
|
|
register: dotfiles_installed
|
|
|
|
- name: "Add ssh public keys for user '{{ user.username }}'."
|
|
tags: users
|
|
ansible.builtin.authorized_key:
|
|
user: "{{ user.username }}"
|
|
key: "{{ item }}"
|
|
with_items: "{{ user.ssh_keys | default([]) }}"
|
|
|
|
- name: "Install antigen for '{{ user.username }}'."
|
|
tags: users
|
|
become: true
|
|
become_user: "{{ user.username }}"
|
|
ansible.builtin.get_url:
|
|
url: https://git.io/antigen
|
|
dest: "{{ user.home_dir | default('/home/' + user.username) }}/.zsh/antigen.zsh"
|
|
mode: 0600
|
|
when:
|
|
- user.shell is defined
|
|
- "'/zsh' in user.shell"
|
|
|
|
- name: "Install tpm for user '{{ user.username }}'."
|
|
tags: users
|
|
become: true
|
|
become_user: "{{ user.username }}"
|
|
ansible.builtin.git:
|
|
repo: "https://github.com/tmux-plugins/tpm"
|
|
dest: "{{ user.home_dir | default('/home/' + user.username) }}/.tmux/plugins/tpm"
|
|
version: v3.0.0
|
|
|
|
when:
|
|
- user.state | default('present') == 'present'
|