-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuser.yml
71 lines (59 loc) · 1.69 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
- name: configure a user
hosts: ansibleexample
become: yes
gather_facts: False
vars:
# created with: openssl passwd -1 "123"
cloudgenius_password: $1$Aj02So58$YWne25ZH80FNjvTM.AkMO/
tasks:
- name: Install the package "sudo"
apt:
name: sudo
state: present
- name: Add user cloudgenius
user: name=cloudgenius password={{cloudgenius_password}} shell=/bin/bash groups=root append=yes
- name: Add user cloudgenius to sudoers
lineinfile:
"path=/etc/sudoers
regexp='^cloudgenius ALL'
line='cloudgenius ALL=(ALL) NOPASSWD: ALL'
state=present"
- name: Add SSH public key to user cloudgenius in remote machine
authorized_key:
user=cloudgenius
key="{{ lookup('file', "~/.ssh/id_rsa.pub") }}"
state=present
- name: Disallow root SSH access
lineinfile:
path=/etc/ssh/sshd_config
regexp="^PermitRootLogin"
line="PermitRootLogin no"
state=present
notify:
- restart ssh
- name: Disallow SSH password authentication
lineinfile:
path=/etc/ssh/sshd_config
regexp="^PasswordAuthentication"
line="PasswordAuthentication no"
state=present
notify:
- restart ssh
- name: Totally block root access
file:
path=/root/.ssh/authorized_keys
state=absent
- name: Disallow SSH GSS API authentication
lineinfile:
path=/etc/ssh/sshd_config
regexp="^GSSAPIAuthentication"
line="GSSAPIAuthentication no"
state=present
notify:
- restart ssh
handlers:
- name: restart ssh
service:
name=ssh
state=restarted