-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-create-user.yml
44 lines (37 loc) · 1 KB
/
01-create-user.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
# This playbook is to be run only once and before other playbooks
- name: Create a user with sudo privileges
hosts: all
become: true
remote_user: root
tasks:
- name: Check for 'wheel' group
group:
name=wheel
state=present
- name: Allow wheel group to have passwordless sudo
lineinfile:
dest: /etc/sudoers
state: present
regexp: '^%wheel'
line: '%wheel ALL=(ALL) NOPASSWD: ALL'
- name: Create a user
user:
name: "{{ user }}"
groups: wheel
append: yes
state: present
- name: Set authorized key
authorized_key:
user: "{{ user }}"
state: present
key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
- name: Disallow root SSH access
lineinfile:
dest: /etc/ssh/sshd_config
regexp: "^PermitRootLogin"
line: "PermitRootLogin no"
state: present
- name: Reboot the machine
remote_user: "{{ user }}"
become: true
reboot: