-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nomis: D1568: add support for user creation (#437)
* Add regular user functionality to users-and-groups role * Add regular users to nomis-dev servers * whitespace * Commit changes made by code formatters --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
d1331be
commit f7b0849
Showing
9 changed files
with
198 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
--- | ||
# Define which users to create using this variable. Groups are automatically | ||
# created if they are referenced by a user. For example: | ||
# Define which system users to create using this variable. Groups are | ||
# automatically created if they are referenced by a user. For example: | ||
# users_and_groups_system: | ||
# - { name: oracle, group: oinstall } | ||
# - { group: mygroup } # if just a group required | ||
users_and_groups_system: [] | ||
|
||
# override this to load a different uid/gid vars file | ||
users_and_groups_system_vars_prefix: "default" | ||
# Define which regular users to create using this variable. Although you can | ||
# specify individual users in the same way as `users_and_groups_system`, it | ||
# is recommended just to specify group and all group members will be added. | ||
# users_and_groups_regular: | ||
# - group: studio-webops | ||
users_and_groups_regular: [] | ||
|
||
# Override these in vars/ | ||
system_uids: {} # username -> uid | ||
system_gids: {} # group -> gid | ||
regular_uids: {} # username -> uid | ||
regular_gids: {} # group -> gid | ||
regular_users_authorized_keys: {} # username -> key (multi-line string) | ||
regular_groups_additional_groups: {} # username -> groups | ||
regular_groups_members: {} # group -> list of usernames | ||
|
||
# Define which files to read in from /vars | ||
users_and_groups_system_vars_prefixes: | ||
- "default" | ||
- "{{ ec2.tags['business-unit'] | lower }}" | ||
users_and_groups_regular_vars_prefixes: | ||
- "default" | ||
- "{{ ec2.tags['business-unit'] | lower }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
dependencies: | ||
- role: get-ec2-facts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--- | ||
# Note these tasks can also be used elsewhere via import_role | ||
|
||
- name: Include uid and gid vars | ||
ansible.builtin.include_vars: | ||
dir: vars | ||
files_matching: "{{ item }}-regular-.*.yml$" | ||
loop: "{{ users_and_groups_regular_vars_prefixes }}" | ||
|
||
- name: Calculate list of groups | ||
ansible.builtin.set_fact: | ||
regular_groups_1: "{{ users_and_groups_regular | map(attribute='group') }}" | ||
regular_groups_2: "{{ users_and_groups_regular | selectattr('groups', 'defined') | map(attribute='groups') | flatten }}" | ||
|
||
- name: Add regular groups | ||
ansible.builtin.group: | ||
name: "{{ item }}" | ||
state: present | ||
system: no | ||
gid: "{{ regular_gids[item]|default(omit) }}" | ||
loop: "{{ (regular_groups_1 + regular_groups_2) | unique }}" | ||
|
||
- name: Calculate groups where we will add all members | ||
ansible.builtin.set_fact: | ||
regular_groups_for_adding_users: "{{ users_and_groups_regular | rejectattr('name', 'defined') | selectattr('group', 'defined') | map(attribute='group') }}" | ||
users_regular: [] | ||
|
||
- name: Add group members to user list fact | ||
ansible.builtin.set_fact: | ||
users_regular: "{{ users_regular + [{ | ||
'name': item.name, | ||
'group': item.group, | ||
'groups': item.groups|default([]) + regular_groups_additional_groups[item.group]|default([]), | ||
'uid': item.uid | default(regular_uids[item.name]|default(omit)), | ||
'create_home': item.create_home | default(true), | ||
'home': item.home | default('/home/' + item.name), | ||
'state': item.state | default('present'), | ||
'authorized_keys': item.authorized_keys | default(regular_users_authorized_keys[item.name]|default(omit)) | ||
}] }}" | ||
vars: | ||
item: | ||
group: "{{ loop_item[0].key }}" | ||
name: "{{ loop_item[1] }}" | ||
when: item.group in regular_groups_for_adding_users | ||
loop_control: | ||
loop_var: loop_item | ||
label: "{{ item.name }}:{{ item.group }}" | ||
loop: "{{ regular_groups_members | dict2items | subelements('value') }}" | ||
|
||
- name: Add regular users to user list fact | ||
set_fact: | ||
users_regular: "{{ users_regular + [{ | ||
'name': item.name, | ||
'group': item.group, | ||
'groups': item.groups|default([]) + regular_groups_additional_groups[item.group]|default([]), | ||
'uid': item.uid | default(regular_uids[item.name]|default(omit)), | ||
'create_home': item.create_home | default(true), | ||
'home': item.home | default('/home/' + item.name), | ||
'state': item.state | default('present'), | ||
'authorized_keys': item.authorized_keys | default(regular_users_authorized_keys[item.name]|default(omit)) | ||
}] }}" | ||
loop_control: | ||
label: "{{ item.name }}" | ||
loop: "{{ users_and_groups_regular | selectattr('name', 'defined') }}" | ||
|
||
- name: Update regular users | ||
ansible.builtin.user: | ||
name: "{{ item.name }}" | ||
group: "{{ item.group }}" | ||
groups: "{{ item.groups }}" | ||
uid: "{{ item.uid|default(omit) }}" | ||
create_home: "{{ item.create_home }}" | ||
home: "{{ item.home }}" | ||
state: "{{ item.state }}" | ||
system: no | ||
loop_control: | ||
label: "{{ item.name }}:{{ item.group }}" | ||
loop: "{{ users_regular }}" | ||
|
||
- name: Update authorized keys | ||
ansible.posix.authorized_key: | ||
user: "{{ item.name }}" | ||
key: "{{ item.authorized_keys }}" | ||
loop_control: | ||
label: "{{ item.name }}" | ||
loop: "{{ users_regular | rejectattr('state', 'equalto', 'absent') | selectattr('authorized_keys', 'defined') }}" | ||
when: not ansible_check_mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
ansible/roles/users-and-groups/vars/hmpps-regular-groups.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# define all non-system groups in use in hmpps accounts here | ||
|
||
# define gid if you want consistency across servers | ||
regular_gids: | ||
studio-webops: 2001 | ||
syscon-nomis: 2051 | ||
|
||
# define any additional groups that team members should be added to | ||
regular_groups_additional_groups: | ||
studio-webops: | ||
- wheel | ||
syscon-nomis: | ||
- wheel | ||
|
||
# define members of each group | ||
regular_groups_members: | ||
studio-webops: | ||
- drobinson-moj | ||
- Sandhya1874 | ||
- KarenMoss1510 | ||
syscon-nomis: | ||
- vinnydigital |
21 changes: 21 additions & 0 deletions
21
ansible/roles/users-and-groups/vars/hmpps-regular-users.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Define UID/ssh keys for hmpps non-system users | ||
# NOTE: please do not commit email addresssed in authorized keys | ||
|
||
# define a UID if you want consistency across servers | ||
regular_uids: | ||
drobinson-moj: 2001 | ||
Sandhya1874: 2002 | ||
KarenMoss1510: 2003 | ||
vinnydigital: 2051 | ||
|
||
# please do not commit email addresses | ||
regular_users_authorized_keys: | ||
drobinson-moj: | | ||
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDMmybIRrtx8sU+/7+d9s7RppiZv+UTgszC9Ed7NqOMYBI5D6lD32AJQmDgDvHWZtmt1PCq5SLkkrz8wVqKkKewTtsf7AZ8Nb8B2NBcKNvKeAS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