-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhost-setup.yml
More file actions
80 lines (69 loc) · 1.82 KB
/
host-setup.yml
File metadata and controls
80 lines (69 loc) · 1.82 KB
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
72
73
74
75
76
77
78
79
80
- hosts: all
user: root
gather_facts: true
vars:
user: neil
packages:
- git
- wget
- curl
- htop
- haveged
tasks:
- name: update all RedHat things
yum: name=* state=latest
when: ansible_os_family == "RedHat"
- name: update all Ubuntu things
apt: name=* state=latest
when: ansible_os_family == "Debian"
- name: Make sure we have a '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'
validate: 'visudo -cf %s'
- name: Add sudoers users to wheel group
user:
user="{{ user }}"
groups=wheel
append=yes
state=present
createhome=yes
shell=/bin/bash
- name: Set up authorized keys for the deployer user
authorized_key: user="{{ user }}" key="{{item}}"
with_file:
- /home/{{ user }}/.ssh/id_rsa.pub
- name: Ensure packages are installed
apt:
name: "{{ packages }}"
state: present
when: ansible_os_family == "Debian"
- name: Log in as the new user to disable root
hosts: all
user: neil
gather_facts: false
become: yes
tasks:
- name: Disable root login over SSH
lineinfile:
dest: /etc/ssh/sshd_config
regexp: "^PermitRootLogin"
line: "PermitRootLogin no"
state: present
notify:
- restart sshd
- name: Disable password login
lineinfile: dest=/etc/ssh/sshd_config regexp="^PasswordAuthentication" line="PasswordAuthentication no" state=present
notify:
- restart sshd
handlers:
- name: restart ssh daemon
service:
name: ssh
state: reloaded