-
Notifications
You must be signed in to change notification settings - Fork 0
/
addusers.yml
39 lines (36 loc) · 1.25 KB
/
addusers.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
- name: Test for existence of /mnt/users
stat:
path: /mnt/users
register: usersdir
- name: Add user with random password
block:
- shell: cat /dev/urandom | tr -dc 'a-zA-Z0-9@#$%*_\-' | fold -w 12 | head -n1
register: randompass
- command: "mkpasswd --method=sha-512 -- {{ randompass.stdout }}"
register: cryptopass
- group:
name: "{{ item.group }}"
state: present
- user:
name: "{{ item.user }}"
group: "{{ item.group }}"
groups: [jupyterhub, users]
password: "{{ cryptopass.stdout }}"
shell: /bin/bash
home: "/mnt/users/{{ item.user }}"
- file:
path: "/mnt/users/{{ item.user }}"
mode: 0750
- debug:
msg: "{{ item.user }} {{ item.group }} {{ randompass.stdout }}"
when: usersdir.stat.exists
- name: Add workpackage groups
group:
name: "{{ item }}"
loop: [wp1, wp2, wp3, wp4, wp5, wp6, wp7]
# Add a group and user later on, with fixed group id and user id:
# groupadd -g 1005 <groupname>
# pw=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9@#$%*_\-' | fold -w 12 | head -n1)
# Or use: pw=$(openssl rand -base64 12)
# cryptopass=$(mkpasswd --method=sha-512 -- $pw)
# useradd -u 1004 -g <groupname> -G jupyterhub,users -m -b /mnt/users -p $cryptopass -s /bin/bash <username>