-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic-setup.yml
110 lines (89 loc) · 2.52 KB
/
basic-setup.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
- hosts: all
remote_user: root
become: yes
vars_prompt:
- name: host_name
prompt: Enter machine hostname
private: no
- name: swap_size
prompt: Enter swap file size (e.g. 4G) or leave as 0 to disable swap
default: "0"
private: no
- name: root_password
prompt: Enter new root password
private: yes
encrypt: sha512_crypt
confirm: yes
salt_size: 7
- name: ssh_key
prompt: Enter filename of public ssh key
default: "~/.ssh/id_rsa.pub"
private: no
tasks:
- name: Create apt lock folder
file:
path: /var/lib/apt/lists
state: directory
- name: Install packages
apt:
name:
- curl
- neovim
- htop
- wget
- git
- man
- bash-completion
- locales
update_cache: yes
state: latest
- name: Ensure a locale exists
locale_gen:
name: en_US.UTF-8
state: present
- name: Apply root password
user:
name: root
password: "{{ root_password }}"
- name: Remove other ssh keys
file:
path: /root/.ssh/authorized_keys
state: touch
force: yes
- name: Set authorized key for root
authorized_key:
user: root
state: present
key: "{{ lookup('file', ssh_key) }}"
- name: Disable password authentication
lineinfile:
path: /etc/ssh/sshd_config
state: present
regexp: '^#?PasswordAuthentication'
line: 'PasswordAuthentication no'
- name: Setup system hostname
hostname:
name: "{{ host_name }}"
- name: Setup /etc/hosts
lineinfile:
path: /etc/hosts
state: present
regexp: '^127.0.0.1'
line: '127.0.0.1 localhost {{ host_name }}'
- name: Install swap file
block:
- name: Create the file to be used for swap
command: fallocate -l {{ swap_size }} /mnt/swap
- name: Format the file for swap
command: mkswap /mnt/swap
- name: Change swap file permissions
file: path=/mnt/swap owner=root group=root mode=0600
- name: Add the file to the system as a swap file
command: swapon /mnt/swap
- name: Write swap entry in fstab
mount: name=none src=/mnt/swap fstype=swap opts=sw passno=0 dump=0 state=present
when: swap_size != "0"
- name: Reboot system
reboot:
reboot_timeout: 1200