-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path906_add_users_keys.yaml
More file actions
41 lines (35 loc) · 991 Bytes
/
906_add_users_keys.yaml
File metadata and controls
41 lines (35 loc) · 991 Bytes
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
---
- hosts: ansible2
vars_files: vars/906_vars.yaml
tasks:
- name: Add group
group:
name: webadmin
- name: Add users
user:
name: "{{ item.username }}"
group: "{{ item.groups }}"
loop: "{{ users }}"
- name: Copy pub key
authorized_key:
key: "{{ lookup('file', 'files/'+ item.username + '.key.pub') }}"
# without lookup it doesnt work
# key: "files/{{ item.username }}.key.pub"
user: "{{ item.username }}"
loop: "{{ users }}"
- name: Add record to sudoers.d/webadmin
copy:
content: "%webadmin ALL=(ALL) NOPASSWD: ALL"
dest: /etc/sudoers.d/webadmin
mode: 0440
- name: Deny root login via ssh
lineinfile:
dest: /etc/ssh/sshd_config
regexp: ^PermitRootLogin
line: "PermitRootLogin no"
notify: Restart sshd
handlers:
- name: Restart sshd
service:
name: sshd
state: restarted