-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook.yml
43 lines (37 loc) · 1.03 KB
/
playbook.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
- name: Setup a new VPS
hosts: all
become: true
vars:
new_username: "john_doe"
tasks:
- name: Creating passwordless user
user:
name: "{{ new_username }}"
shell: /bin/bash
password: ""
generate_ssh_key: yes
- name: Allow sudo without password
lineinfile:
dest: /etc/sudoers
line: "{{ new_username }} ALL=(ALL) NOPASSWD: ALL"
validate: "visudo -cf %s"
become: true
become_user: root
- name: Enable SSH authentication for the user
authorized_key:
user: "{{ new_username }}"
state: present
key: "{{ lookup('file', '~/.ssh/id_ed25519.pub') }}"
- name: Disable SSH login as root
lineinfile:
path: /etc/ssh/sshd_config
regex: '^#?PermitRootLogin'
line: 'PermitRootLogin no'
state: present
notify:
- restart ssh
handlers:
- name: restart ssh
service:
name: ssh
state: restarted