Skip to content

Commit

Permalink
feat: add default values
Browse files Browse the repository at this point in the history
- users_home_files
- users_home_create
- users_shell

Merge branch 'weekendesk-add-default-variables'
  • Loading branch information
franklinkim committed Jul 10, 2019
2 parents 1be4996 + 5493a19 commit b5bc711
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,20 @@ Here is a list of all the default variables for this role, which are also availa
# list of users to add
users: []
# default user's dotfiles
users_home_files: []
# users home directory
users_home: /home
# create user's home directory
users_home_create: yes
# default user's primary group for users
users_group:
# default user's secondary groups
users_groups: []
# default user's home directory permissions
users_home_mode: "0755"
# default user login shell
#users_shell:
# default user's ssh key type
users_ssh_key_type: rsa
# default user's ssh key bits
Expand Down
6 changes: 6 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,20 @@

# list of users to add
users: []
# default user's dotfiles
users_home_files: []
# users home directory
users_home: /home
# create user's home directory
users_home_create: yes
# default user's primary group for users
users_group:
# default user's secondary groups
users_groups: []
# default user's home directory permissions
users_home_mode: "0755"
# default user login shell
#users_shell:
# default user's ssh key type
users_ssh_key_type: rsa
# default user's ssh key bits
Expand Down
6 changes: 3 additions & 3 deletions tasks/manage_user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
ssh_key_file: ".ssh/id_{{ item.ssh_key_type | default(users_ssh_key_type) }}"
ssh_key_passphrase: "{{ item.ssh_key_password | default(omit) }}"
ssh_key_bits: "{{ item.ssh_key_bits | default(users_ssh_key_bits) }}"
createhome: "{{ item.home_create | default(omit) }}"
shell: "{{ item.shell | default(omit) }}"
createhome: "{{ item.home_create | default(users_home_create) }}"
shell: "{{ item.shell | default(users_shell | default(omit)) }}"
update_password: "{{ item.update_password | default(omit) }}"

- name: Configuring user's home
import_tasks: manage_user_home.yml
when: item.home_create is not defined or item.home_create
when: item.home_create | default(users_home_create)
7 changes: 3 additions & 4 deletions tasks/manage_user_home.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
mode: '0700'

- name: Adding user's private key
template:
src: home/user/ssh/private-key.j2
copy:
content: "{{ item.ssh_key }}"
dest: "{{ item.home | default(users_home ~ '/' ~ item.username) }}/.ssh/id_{{ item.ssh_key_type | default('rsa') }}"
owner: "{{ item.username }}"
group: "{{ item.group if item.group is defined else (users_group if users_group else item.username) }}"
Expand All @@ -38,7 +38,6 @@
dest: "{{ item.home | default(users_home ~ '/' ~ item.username) }}/{{ home_file | basename }}"
owner: "{{ item.username }}"
group: "{{ item.group if item.group is defined else (users_group if users_group else item.username) }}"
with_items: "{{ item.home_files }}"
with_items: "{{ item.home_files | default(users_home_files) }}"
loop_control:
loop_var: home_file
when: item.home_files is defined
1 change: 0 additions & 1 deletion templates/home/user/ssh/private-key.j2

This file was deleted.

0 comments on commit b5bc711

Please sign in to comment.