-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook_vps.yml
146 lines (128 loc) · 5.09 KB
/
playbook_vps.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
- name: Setup ssh port
hosts: vps
gather_facts: false
vars_files:
- vars/all.yml
- vars/vps.yml
tasks:
- name: SSH Port Juggle
ansible.builtin.import_tasks: tasks/sshd_port_juggling.yml
when: testing is undefined or testing != 'true'
- name: SSH User Juggle
ansible.builtin.import_tasks: tasks/sshd_login_user_juggling.yml
when: testing is undefined or testing != 'true'
- name: Read ssh_public_key from {{ ssh_public_key_file }}
ansible.builtin.set_fact:
ssh_public_key: "{{ lookup('file', ssh_public_key_file) }}"
when: testing is undefined or testing != 'true'
- name: Setup local_ipv4
hosts: vps
gather_facts: true
tasks:
# https://medium.com/opsops/ansible-default-ipv4-is-not-what-you-think-edb8ab154b10
- name: Geather local_ipv4
ansible.builtin.set_fact:
local_ipv4: "{{ ansible_default_ipv4.address | default(ansible_all_ipv4_addresses[0]) }}"
- name: Debug local_ipv4
ansible.builtin.debug:
var: local_ipv4
- name: Setup for testing
hosts: vps
gather_facts: false
become: true
tasks:
- name: For testing at github actions set username to "runneradmin"
ansible.builtin.set_fact:
username: "runneradmin"
when: testing is defined and testing == 'true'
- name: List all ports used
block:
- name: List all ports used
ansible.builtin.command: netstat -tulpn
become: true
changed_when: false
when: testing is defined and testing == 'true'
register: netstat_output
- name: Debug output ports
ansible.builtin.debug:
var: netstat_output.stdout_lines
when: testing is defined and testing == 'true'
- name: Configure VPS personal server.
hosts: vps
vars_files:
- vars/all.yml
- vars/vps.yml
roles:
- role: packages_install
become: true
- role: linux_server_setup
vars:
linux_server_setup_hostname: "{{ device_name }}"
linux_server_setup_login_user: "{{ username }}"
linux_server_setup_login_password: "{{ password }}"
linux_server_setup_login_user_uid: 1000
linux_server_setup_login_user_gid: 1000
linux_server_setup_login_ssh_public_key: "{{ lookup('file', '{{ ssh_public_key_path }}') }}"
linux_server_setup_open_ports:
- {port: 22, protocol: "tcp", comment: "default ssh"}
- {port: "{{ ssh_port }}", protocol: "tcp", comment: "custom ssh"}
- {port: 51820, protocol: "udp", comment: "wireguard"}
- {port: 80, protocol: "tcp", comment: "http"}
- {port: 443, protocol: "tcp", comment: "https"}
- role: hifis.unattended_upgrades
vars:
unattended_automatic_reboot_time: 04:00 # noqa: var-naming[no-role-prefix]
# apt-daily timer
unattended_apt_daily_oncalendar: "*-*-* 01:00" # noqa: var-naming[no-role-prefix]
unattended_apt_daily_randomizeddelaysec: "60m" # noqa: var-naming[no-role-prefix]
# apt-daily-upgrade timer
unattended_apt_daily_upgrade_oncalendar: "*-*-* 2:00" # noqa: var-naming[no-role-prefix]
unattended_apt_daily_upgrade_randomizeddelaysec: "60m" # noqa: var-naming[no-role-prefix]
become: true
- role: geerlingguy.security
security_ssh_port: "{{ ssh_port }}"
security_ssh_permit_root_login: "no"
become: true
- role: geerlingguy.docker
become: true
- role: dotfiles
tags: ["dotfiles"]
vars:
dotfiles_repo_url: "https://github.com/k4black/dotfiles.git"
dotfiles_dest: "~/.dotfiles"
dotfiles_symlinks:
.zshrc: "~/.zshrc"
.gitconfig: "~/.gitconfig"
- role: zsh_setup
vars:
zsh_setup_set_default_shell: true
zsh_setup_user: "{{ username }}"
become: true
tasks:
- name: Setup .gitconfig.local
ansible.builtin.template:
src: files/.gitconfig.local.j2
dest: ~/.gitconfig.local
mode: 0600
owner: "{{ ansible_user_id }}"
- name: Copy docker configs and run containers
ansible.builtin.include_role:
name: containers_setup
vars:
containers_setup_user: "{{ username }}"
containers_setup_configs_dir: "{{ services_configs_dir }}"
containers_setup_data_dir: "{{ services_data_dir }}"
containers_setup_docker_compose_template: "files/vps/docker-compose.yml.j2"
containers_setup_make_dirs:
# - "{{ services_data_dir }}/influxdb-data"
# - "{{ services_configs_dir }}/influxdb-config"
- "{{ services_configs_dir }}/pihole"
- "{{ services_configs_dir }}/pihole-dnsmasq.d"
containers_setup_touch_files: []
containers_setup_config_templates:
files/vps/server-wg0.conf.j2: "server-wg0.conf" # TODO: fix permissions
files/vps/pihole-02-custom-dns.conf.j2: "pihole-dnsmasq.d/02-custom-dns.conf"
files/vps/pihole-adlists.list: "pihole/adlists.list"
files/vps/pihole-custom.list.j2: "pihole/custom.list"
# files/vps/telegraf.conf: "{{ services_configs_dir }}/telegraf.conf"