-
Notifications
You must be signed in to change notification settings - Fork 2
/
createUsers.yml
32 lines (32 loc) · 1.15 KB
/
createUsers.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
---
- name: Create user(s) on a Linux machine
hosts: target_host
become: yes
tasks:
- name: Include the input for the users management
include_vars: users.yml
- name: Enable password-based login
lineinfile: dest=/etc/ssh/sshd_config regexp='^#?PasswordAuthentication' line='PasswordAuthentication yes'
- name: Create users
user:
name: "{{ item.key }}"
password: "{{ item.value.password | password_hash('sha512') }}"
state: present
shell: "{{ item.value.shell | default ('/bin/bash') }}"
system: no # Defaults to no
createhome: yes # Defaults to yes
home: "{{ item.value.home | default ('/home/' + item.key) }}"
with_dict: "{{ users }}"
- name: Add sudoers users to wheel group
user:
name: "{{ item.key }}"
groups: wheel
append: yes
state: present
with_dict: "{{ users }}"
when: item.value.sudoers == true
# Ref: https://github.com/gdha/rear-automated-testing/issues/19
- name: Restart sshd so that the newly-created user can login
shell: sleep 3; service sshd restart
async: 1
poll: 0