Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,12 @@ This is an example playbook:
- username: foobar_file
home_files:
- "tests/.bashrc"
users_group: staff
users_group:
name: staff
gid: 50
users_groups:
- www-data
- name: www-data
gid: 33
users_authorized_keys_exclusive: yes
users_remove:
- foobar
Expand Down
8 changes: 5 additions & 3 deletions tasks/manage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

- name: Adding primary group
ansible.builtin.group:
name: "{{ users_group }}"
name: "{{ users_group.name }}"
gid: "{{ users_group.gid | default(omit) }}"
state: present
when: users_group is defined and users_group
when: users_group is defined and users_group.name is defined

- name: Adding secondary groups
ansible.builtin.group:
name: "{{ item }}"
name: "{{ item.name }}"
gid: "{{ item.gid | default(omit) }}"
state: present
with_items: "{{ users_groups | default([]) }}"

Expand Down
4 changes: 2 additions & 2 deletions tasks/manage_user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
generate_ssh_key: "{{ user.ssh_key_generate | default(omit) }}"
group: "{{
omit if user.group is defined and user.group == user.username
else (user.group if user.group is defined else (users_group if users_group else omit))
else (user.group if user.group is defined else (users_group.name if users_group else omit))
}}"
groups: "{{ user.groups|join(',') if user.groups is defined else users_groups|join(',') }}"
groups: "{{ user.groups if user.groups is defined else users_groups | map(attribute='name') | list }}"
append: "{{ user.append | default(omit) }}"
password: "{{ user.password | default(omit) }}"
ssh_key_file: ".ssh/id_{{ user.ssh_key_type | default(users_ssh_key_type) }}"
Expand Down
10 changes: 5 additions & 5 deletions tasks/manage_user_home.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
file:
dest: "{{ user.home | default(users_home ~ '/' ~ user.username) }}"
owner: "{{ user.username }}"
group: "{{ user.group if user.group is defined else (users_group if users_group else user.username) }}"
group: "{{ user.group if user.group is defined else (users_group.name if users_group else user.username) }}"
mode: "{{ user.home_mode if user.home_mode is defined else users_home_mode }}"
ignore_errors: "{{ ansible_check_mode }}"

- name: Adding user's .ssh directory
file:
path: "{{ user.home | default(users_home ~ '/' ~ user.username) }}/.ssh"
owner: "{{ user.username }}"
group: "{{ user.group if user.group is defined else (users_group if users_group else user.username) }}"
group: "{{ user.group if user.group is defined else (users_group.name if users_group else user.username) }}"
state: directory
mode: 0700

Expand All @@ -21,7 +21,7 @@
content: "{{ user.ssh_key }}"
dest: "{{ user.home | default(users_home ~ '/' ~ user.username) }}/.ssh/id_{{ user.ssh_key_type | default('rsa') }}"
owner: "{{ user.username }}"
group: "{{ user.group if user.group is defined else (users_group if users_group else user.username) }}"
group: "{{ user.group if user.group is defined else (users_group.name if users_group else user.username) }}"
mode: 0600
when: user.ssh_key is defined
no_log: true
Expand All @@ -31,7 +31,7 @@
content: "{{ item.value }}"
dest: "{{ user.home | default(users_home ~ '/' ~ user.username) }}/.ssh/{{ item.key }}"
owner: "{{ user.username }}"
group: "{{ user.group if user.group is defined else (users_group if users_group else user.username) }}"
group: "{{ user.group if user.group is defined else (users_group.name if users_group else user.username) }}"
mode: 0600
when: user.ssh_key is not defined and user.ssh_keys is defined
with_dict: "{{ user.ssh_keys }}"
Expand All @@ -48,7 +48,7 @@
src: "{{ home_file }}"
dest: "{{ user.home | default(users_home ~ '/' ~ user.username) }}/{{ home_file | basename }}"
owner: "{{ user.username }}"
group: "{{ user.group if user.group is defined else (users_group if users_group else user.username) }}"
group: "{{ user.group if user.group is defined else (users_group.name if users_group else user.username) }}"
with_items: "{{ user.home_files | default(users_home_files) }}"
loop_control:
loop_var: home_file
5 changes: 3 additions & 2 deletions tests/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@
- username: foobar_file
home_files:
- "tests/.bashrc"
users_group: staff
users_group:
name: staff
users_groups:
- www-data
- name: www-data
users_authorized_keys_exclusive: yes
users_remove:
- foobar
Expand Down