forked from openedx-unsupported/configuration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage_edxapp_users_and_groups.yml
285 lines (276 loc) · 12.4 KB
/
manage_edxapp_users_and_groups.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#
# edX Configuration
#
# github: https://github.com/openedx/configuration
# wiki: https://openedx.atlassian.net/wiki/display/OpenOPS
# code style: https://openedx.atlassian.net/wiki/display/OpenOPS/Ansible+Code+Conventions
# license: https://github.com/openedx/configuration/blob/master/LICENSE.TXT
#
# Usage: ansible-playbook -i edxapp-host-1, -e@/path/to/configfile-of-users-andor-groups
# -e 'group_environment=prod-edge'
# Overview:
# This playbook ensures that the specified users and groups exist in the targeted
# edxapp cluster.
#
# Users have the following properties:
# - username (required, str)
# - email (required, str)
# - initial_password_hash (optional, str)
# - remove (optional, bool): ensures the user does not exist
# - staff (optional, bool)
# - superuser (optional, bool)
# - unusable_password (optional, bool): ensures the password is unusable
# - groups (optional, list[str])
# - _comment (optional, str): ignored
#
# Groups can have the following properties:
# - name (required, str)
# - permissions (required, list[str])
# - remove (optional, bool): ensures the group does not exist
# - _comment (optional, str): ignored
#
# Example:
#
# django_users:
#
# - username: bobby
# email: [email protected]
# staff: true
# superuser: true
# groups:
# - group1
# - group2
#
# - username: fred
# email: fred@smith
# remove: true
#
# - username: smitty
# email: [email protected]
# groups:
# - group1
# _comment: |
# he was
# number one!
#
# - username: frank
# email: [email protected]
# staff: false
# superuser: false
# unusable_password: true
# groups: []
#
# - username: zoe
# email: [email protected]
# initial_password_hash: 'pbkdf2_sha256$20000$levJ6jdVYCsu$gdBLGf2DNPqfaKdcETXtFocRU8Kk+sMsIvKkmw1dKbY='
#
# django_groups:
#
# - name: group1
# permissions:
# - permission1
# - permission2
#
# - name: group3
# remove: true
# permissions: []
# _comment: |
# group3 is the best group
# yada yada
#
# Note:
#
# LMS and CMS do still share the edxapp database, and therefore share a
# User table and Group table. So, edxapp users are created in an LMS context
# but exist in CMS as well.
#
# However, some edxapp Django apps are only installed into CMS (but not LMS),
# and vice versa. In order to create a group and grant it permissions,
# the permissions must be from apps that are installed into the running
# service. So, to create groups for LMS-only apps, we must create groups
# in an LMS context, and to create groups for CMS-only apps, we must create
# groups in a CMS context. Thus, while users are managed jointly for LMS/CMS,
# groups are managed separately.
#
# That being said, note that the groups created in one service variant should be
# disjoint with those created the other, as the underlying Group table is shared.
# That is, each group name should be defined for LMS *or* CMS, not both.
# Otherwise, whichever group is created second will override the first one.
#
# Of course, the jointly-managed LMS/CMS users can be assigned to any combination
# of both LMS and CMS groups. Assigning users to CMS groups does in fact work through
# an LMS context, since the actual CMS permissions are not being referenced.
#
# Note: to get a list of all available permissions, run the following code within a Django shell:
#
# from django.contrib.auth.models import Permission
# for perm in Permission.objects.all():
# print '{}:{}:{}'.format(perm.content_type.app_label, perm.content_type.model, perm.codename)
#
- hosts: all
vars:
env_path: /edx/app/edxapp/edxapp_env
python_path: /edx/app/edxapp/venvs/edxapp/bin/python
manage_path: /edx/bin/manage.edxapp
ignore_user_creation_errors: no
deployment_settings: "{{ EDXAPP_SETTINGS | default('production') }}"
group_environment: "" # By default, create groups for all envs (for backwards compatibility).
service: "" # Used to display the service name during execution with *-ida tags. Set using ansible-playbook -e.
vars_files:
- roles/common_vars/defaults/main.yml
tasks:
- name: Manage LMS groups
tags:
- manage-groups-lms
- manage-groups # Old tag pre-lms/cms-group-split, can be removed after TNL-8274.
shell: >
. {{env_path}} && {{ python_path }} {{ manage_path }} lms --settings={{ deployment_settings }}
manage_group {{ item.name | quote }}
{% if item.get('permissions', []) | length %}--permissions {{ item.permissions | default([]) | map('quote') | join(' ') }}{% endif %}
{% if item.get('remove') %}--remove{% endif %}
with_items: "{{ django_groups }}"
when: (not group_environment) or group_environment in item.environments
become: true
become_user: "{{ common_web_user }}"
- name: Manage CMS groups
tags:
- manage-groups-cms
shell: >
. {{env_path}} && {{ python_path }} {{ manage_path }} cms --settings={{ deployment_settings }}
manage_group {{ item.name | quote }}
{% if item.get('permissions', []) | length %}--permissions {{ item.permissions | default([]) | map('quote') | join(' ') }}{% endif %}
{% if item.get('remove') %}--remove{% endif %}
with_items: "{{ django_groups }}"
when: (not group_environment) or group_environment in item.environments
become: true
become_user: "{{ common_web_user }}"
- name: Manage recent LMS/CMS users
tags:
- manage-recent-users-edxapp
shell: >
. {{env_path}} && {{ python_path }} {{ manage_path }} lms --settings={{ deployment_settings }}
manage_user {{ item.username | quote }} {{ item.email | quote }}
{% if item.get('groups', []) | length %}--groups {{ item.groups | default([]) | map('quote') | join(' ') }}{% endif %}
{% if item.get('remove') %}--remove{% endif %}
{% if item.get('superuser') %}--superuser{% endif %}
{% if item.get('staff') %}--staff{% endif %}
{% if item.get('unusable_password') %}--unusable-password{% endif %}
{% if item.get('initial_password_hash') %}--initial-password-hash {{ item.initial_password_hash | quote }}{% endif %}
with_items: "{{ django_users }}"
register: manage_users_result
failed_when: (manage_users_result is failed) and not (ignore_user_creation_errors | bool)
retries: 3
until: manage_users_result is not failed
become: true
become_user: "{{ common_web_user }}"
- name: Manage active LMS/CMS users
tags:
- manage-active-users-edxapp
shell: >
. {{env_path}} && {{ python_path }} {{ manage_path }} lms --settings={{ deployment_settings }}
manage_user {{ item.username | quote }} {{ item.email | quote }}
{% if item.get('groups', []) | length %}--groups {{ item.groups | default([]) | map('quote') | join(' ') }}{% endif %}
{% if item.get('remove') %}--remove{% endif %}
{% if item.get('superuser') %}--superuser{% endif %}
{% if item.get('staff') %}--staff{% endif %}
{% if item.get('unusable_password') %}--unusable-password{% endif %}
{% if item.get('initial_password_hash') %}--initial-password-hash {{ item.initial_password_hash | quote }}{% endif %}
with_items: "{{ django_users }}"
when: not item.get('unusable_password')
register: manage_users_result
failed_when: (manage_users_result is failed) and not (ignore_user_creation_errors | bool)
retries: 3
until: manage_users_result is not failed
become: true
become_user: "{{ common_web_user }}"
- name: Manage inactive LMS/CMS users
tags:
- manage-inactive-users-edxapp
shell: >
. {{env_path}} && {{ python_path }} {{ manage_path }} lms --settings={{ deployment_settings }}
manage_user {{ item.username | quote }} {{ item.email | quote }}
{% if item.get('groups', []) | length %}--groups {{ item.groups | default([]) | map('quote') | join(' ') }}{% endif %}
{% if item.get('remove') %}--remove{% endif %}
{% if item.get('superuser') %}--superuser{% endif %}
{% if item.get('staff') %}--staff{% endif %}
{% if item.get('unusable_password') %}--unusable-password{% endif %}
{% if item.get('initial_password_hash') %}--initial-password-hash {{ item.initial_password_hash | quote }}{% endif %}
with_items: "{{ django_users }}"
when: item.get('unusable_password')
register: manage_users_result
failed_when: (manage_users_result is failed) and not (ignore_user_creation_errors | bool)
retries: 3
until: manage_users_result is not failed
become: true
become_user: "{{ common_web_user }}"
- name: Manage {{ service }} groups
tags:
- manage-groups-ida
shell: >
. {{env_path}} && {{ python_path }} {{ manage_path }}
manage_group {{ item.name | quote }}
{% if item.get('permissions', []) | length %}--permissions {{ item.permissions | default([]) | map('quote') | join(' ') }}{% endif %}
{% if item.get('remove') %}--remove{% endif %}
with_items: "{{ django_groups }}"
when: (not group_environment) or group_environment in item.environments
become: true
become_user: "{{ common_web_user }}"
- name: Manage recent {{ service }} users
tags:
- manage-recent-users-ida
shell: >
. {{env_path}} && {{ python_path }} {{ manage_path }}
manage_user {{ item.username | quote }} {{ item.email | quote }}
{% if item.get('groups', []) | length %}--groups {{ item.groups | default([]) | map('quote') | join(' ') }}{% endif %}
{% if item.get('remove') %}--remove{% endif %}
{% if item.get('superuser') %}--superuser{% endif %}
{% if item.get('staff') %}--staff{% endif %}
{% if item.get('unusable_password') %}--unusable-password{% endif %}
{% if item.get('initial_password_hash') %}--initial-password-hash {{ item.initial_password_hash | quote }}{% endif %}
with_items: "{{ django_users }}"
register: manage_users_result
failed_when: (manage_users_result is failed) and not (ignore_user_creation_errors | bool)
retries: 3
until: manage_users_result is not failed
become: true
become_user: "{{ common_web_user }}"
- name: Manage active {{ service }} users
tags:
- manage-active-users-ida
shell: >
. {{env_path}} && {{ python_path }} {{ manage_path }}
manage_user {{ item.username | quote }} {{ item.email | quote }}
{% if item.get('groups', []) | length %}--groups {{ item.groups | default([]) | map('quote') | join(' ') }}{% endif %}
{% if item.get('remove') %}--remove{% endif %}
{% if item.get('superuser') %}--superuser{% endif %}
{% if item.get('staff') %}--staff{% endif %}
{% if item.get('unusable_password') %}--unusable-password{% endif %}
{% if item.get('initial_password_hash') %}--initial-password-hash {{ item.initial_password_hash | quote }}{% endif %}
with_items: "{{ django_users }}"
when: not item.get('unusable_password')
register: manage_users_result
failed_when: (manage_users_result is failed) and not (ignore_user_creation_errors | bool)
retries: 3
until: manage_users_result is not failed
become: true
become_user: "{{ common_web_user }}"
- name: Manage inactive {{ service }} users
tags:
- manage-inactive-users-ida
shell: >
. {{env_path}} && {{ python_path }} {{ manage_path }}
manage_user {{ item.username | quote }} {{ item.email | quote }}
{% if item.get('groups', []) | length %}--groups {{ item.groups | default([]) | map('quote') | join(' ') }}{% endif %}
{% if item.get('remove') %}--remove{% endif %}
{% if item.get('superuser') %}--superuser{% endif %}
{% if item.get('staff') %}--staff{% endif %}
{% if item.get('unusable_password') %}--unusable-password{% endif %}
{% if item.get('initial_password_hash') %}--initial-password-hash {{ item.initial_password_hash | quote }}{% endif %}
with_items: "{{ django_users }}"
when: item.get('unusable_password')
register: manage_users_result
failed_when: (manage_users_result is failed) and not (ignore_user_creation_errors | bool)
retries: 3
until: manage_users_result is not failed
become: true
become_user: "{{ common_web_user }}"