-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_add_batch.yml
57 lines (52 loc) · 1.48 KB
/
user_add_batch.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
---
- name: Create users and configure sudoers
hosts: all
become: yes
vars:
pwds_normal:
user1: password1
user2: password2
user3: password3
pwds_admin:
admin1: password1
admin2: password2
admin3: password3
tasks:
- name: Ensure bash is the default shell for user creation
user:
name: "{{ item }}"
shell: /bin/bash
loop:
- user1
- user2
- user3
- admin1
- admin2
- admin3
- name: Create normal users
user:
name: "{{ item.key }}"
password: "{{ item.value | password_hash('sha512') }}"
home: "/home/{{ item.key }}"
state: present
loop: "{{ pwds_normal | dict2items }}"
- name: Create admin users
user:
name: "{{ item.key }}"
password: "{{ item.value | password_hash('sha512') }}"
home: "/home/{{ item.key }}"
system: yes
state: present
loop: "{{ pwds_admin | dict2items }}"
- name: Add sudo privileges for normal users (Docker access only)
copy:
dest: "/etc/sudoers.d/{{ item.key }}"
content: "{{ item.key }} ALL=(ALL) NOPASSWD: /usr/bin/docker"
mode: '0440'
loop: "{{ pwds_normal | dict2items }}"
- name: Add sudo privileges for admin users (Full access)
copy:
dest: "/etc/sudoers.d/{{ item.key }}"
content: "{{ item.key }} ALL=(ALL) NOPASSWD:ALL"
mode: '0440'
loop: "{{ pwds_admin | dict2items }}"