Compare commits
6
Commits
bd24f01110
...
60a55e6e49
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60a55e6e49 | ||
|
|
c5b51777c6 | ||
|
|
a4648e0ea7 | ||
|
|
a64d082c0c | ||
|
|
381e1b285c | ||
|
|
bcdc460297 |
@@ -0,0 +1,4 @@
|
||||
---
|
||||
# Adds prometheus-smartctl-exporter (trixie-backports) next to the node exporter
|
||||
# on hosts with physical disks.
|
||||
host_exporters_smart: false
|
||||
@@ -0,0 +1,71 @@
|
||||
---
|
||||
# Both exporters listen on all addresses; host_firewall limits who reaches them.
|
||||
# Its recommends (smartmontools, nvme-cli, ipmitool) start units that fail on hosts without such hardware.
|
||||
- name: Install the node exporter
|
||||
ansible.builtin.apt:
|
||||
name: prometheus-node-exporter
|
||||
install_recommends: false
|
||||
state: present
|
||||
|
||||
- name: Enable the node exporter
|
||||
ansible.builtin.systemd:
|
||||
name: prometheus-node-exporter
|
||||
enabled: true
|
||||
state: started
|
||||
# Check mode does not install the package.
|
||||
ignore_errors: "{{ ansible_check_mode }}"
|
||||
|
||||
- name: Install the smartctl exporter
|
||||
when: host_exporters_smart
|
||||
block:
|
||||
- name: Look for an existing backports source
|
||||
ansible.builtin.shell: >-
|
||||
grep -rEqs '^[^#]*{{ ansible_distribution_release }}-backports'
|
||||
--include='*.list' --include='*.sources' --exclude=host-exporters-backports.sources /etc/apt
|
||||
register: host_exporters_backports
|
||||
changed_when: false
|
||||
failed_when: host_exporters_backports.rc > 1
|
||||
check_mode: false
|
||||
|
||||
# Backports stay at priority 100, so only packages named with default_release come from there.
|
||||
- name: Add the backports source
|
||||
ansible.builtin.copy:
|
||||
dest: /etc/apt/sources.list.d/host-exporters-backports.sources
|
||||
mode: "0644"
|
||||
content: |
|
||||
Types: deb
|
||||
URIs: http://deb.debian.org/debian
|
||||
Suites: {{ ansible_distribution_release }}-backports
|
||||
Components: main
|
||||
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
|
||||
register: host_exporters_source
|
||||
when: host_exporters_backports.rc == 1
|
||||
|
||||
# The module rejects default_release while the release is missing from its package cache.
|
||||
- name: Look for the backports release in the package lists
|
||||
ansible.builtin.shell: apt-cache policy | grep -q 'n={{ ansible_distribution_release }}-backports'
|
||||
register: host_exporters_lists
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
check_mode: false
|
||||
|
||||
- name: Refresh the package lists for the backports source
|
||||
ansible.builtin.apt:
|
||||
update_cache: true
|
||||
when: host_exporters_lists.rc != 0
|
||||
|
||||
- name: Install the smartctl exporter from backports
|
||||
ansible.builtin.apt:
|
||||
name: prometheus-smartctl-exporter
|
||||
default_release: "{{ ansible_distribution_release }}-backports"
|
||||
state: present
|
||||
# Check mode does not write the backports source.
|
||||
ignore_errors: "{{ ansible_check_mode }}"
|
||||
|
||||
# The packaged unit runs as root, which smartctl needs for the disks.
|
||||
- name: Enable the smartctl exporter
|
||||
ansible.builtin.systemd:
|
||||
name: smartctl_exporter
|
||||
enabled: true
|
||||
state: started
|
||||
ignore_errors: "{{ ansible_check_mode }}"
|
||||
@@ -16,6 +16,12 @@ firewall:
|
||||
admin:
|
||||
v4: {}
|
||||
v6: {}
|
||||
# Metrics scrapers: on wt0 only these source addresses reach the listed tcp
|
||||
# ports (the vpn zone applies to every peer). Rendered only when both are set.
|
||||
scrapers:
|
||||
tcp: {}
|
||||
v4: {}
|
||||
v6: {}
|
||||
# Interface names (nft wildcards allowed) whose traffic is trusted.
|
||||
internal_ifaces: {}
|
||||
# Guest bridges (Proxmox vmbr*): DHCP, router solicitations and the public
|
||||
|
||||
@@ -86,6 +86,8 @@
|
||||
enabled: false
|
||||
state: stopped
|
||||
daemon_reload: "{{ firewall_units is changed }}"
|
||||
# Check mode does not install the unit.
|
||||
ignore_errors: "{{ ansible_check_mode }}"
|
||||
|
||||
- name: Remove the geo sets file
|
||||
ansible.builtin.file:
|
||||
|
||||
@@ -18,6 +18,7 @@ set {{ name }} {
|
||||
{% set guest_match = 'iifname { "' ~ (guest_ifaces | join('", "')) ~ '" }' %}
|
||||
{% set dnat = firewall.dnat | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | list %}
|
||||
{% set masquerade = firewall.masquerade | default({}, true) | dict2items | rejectattr('value', 'none') | map(attribute='value') | unique | list %}
|
||||
{% set scrapers = firewall.scrapers | default({}, true) %}
|
||||
{% set forward_guard = firewall.forward_guard | default({}, true) | dict2items | rejectattr('value', 'none') | list %}
|
||||
|
||||
# Declare-then-delete makes every load one atomic transaction that replaces
|
||||
@@ -36,6 +37,8 @@ table inet host {
|
||||
{{ addr_set('admin_v6', 'ipv6_addr', firewall.admin.v6) }}
|
||||
{{ addr_set('cluster_v4', 'ipv4_addr', cluster.v4) }}
|
||||
{{ addr_set('cluster_v6', 'ipv6_addr', cluster.v6) }}
|
||||
{{ addr_set('scrapers_v4', 'ipv4_addr', scrapers.v4) }}
|
||||
{{ addr_set('scrapers_v6', 'ipv6_addr', scrapers.v6) }}
|
||||
set ssh_meter_v4 {
|
||||
type ipv4_addr; flags dynamic; timeout 10m; size 65535;
|
||||
}
|
||||
@@ -85,6 +88,14 @@ table inet host {
|
||||
}
|
||||
|
||||
chain vpn {
|
||||
{% if list(scrapers.tcp) %}
|
||||
{% if list(scrapers.v4) %}
|
||||
ip saddr @scrapers_v4 tcp dport { {{ list(scrapers.tcp) }} } accept
|
||||
{% endif %}
|
||||
{% if list(scrapers.v6) %}
|
||||
ip6 saddr @scrapers_v6 tcp dport { {{ list(scrapers.tcp) }} } accept
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if list(firewall.vpn.tcp) %}
|
||||
tcp dport { {{ list(firewall.vpn.tcp) }} } accept
|
||||
{% endif %}
|
||||
|
||||
@@ -20,6 +20,8 @@ kopia_backup:
|
||||
# Database dumps written to /var/backups/dumps before the snapshot, which then includes that directory.
|
||||
# Each item: file, container, command (run with sh -c inside the container, output is the dump).
|
||||
dumps: []
|
||||
# Files copied to the host as they are, each { src: local path, dest, mode }; owned by root.
|
||||
files: []
|
||||
# Snapshot the newest k3s etcd snapshot, staged in /var/backups/etcd.
|
||||
etcd_snapshot: false
|
||||
# Explicit UTC: the hosts run in different timezones.
|
||||
|
||||
@@ -73,6 +73,15 @@
|
||||
when: kopia_backup_status.rc != 0
|
||||
no_log: true
|
||||
|
||||
- name: Install the files of the host
|
||||
ansible.builtin.copy:
|
||||
src: "{{ item.src }}"
|
||||
dest: "{{ item.dest }}"
|
||||
mode: "{{ item.mode }}"
|
||||
owner: root
|
||||
group: root
|
||||
loop: "{{ kopia_backup.files }}"
|
||||
|
||||
- name: Install the backup script
|
||||
ansible.builtin.template:
|
||||
src: kopia-backup.j2
|
||||
|
||||
@@ -4,3 +4,8 @@ netbird_client:
|
||||
join_network:
|
||||
setup_key:
|
||||
management_url:
|
||||
|
||||
# Interface name prefixes appended to IFaceBlackList in /var/lib/netbird/default.json
|
||||
iface_blacklist_extra: []
|
||||
# Overrides the --log-level of the netbird service when set
|
||||
log_level:
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
- name: restart_netbird
|
||||
systemd:
|
||||
name: netbird
|
||||
state: restarted
|
||||
daemon_reload: true
|
||||
@@ -0,0 +1,49 @@
|
||||
- name: Read netbird config
|
||||
slurp:
|
||||
src: /var/lib/netbird/default.json
|
||||
register: netbird_config_file
|
||||
when: netbird_client.iface_blacklist_extra | default([]) | length > 0
|
||||
tags: netbird_client_config
|
||||
|
||||
- name: Add the extra interface prefixes to IFaceBlackList
|
||||
when: netbird_config_file.content is defined
|
||||
vars:
|
||||
netbird_config: "{{ netbird_config_file.content | b64decode | from_json }}"
|
||||
netbird_blacklist_missing: "{{ netbird_client.iface_blacklist_extra | difference(netbird_config.IFaceBlackList | default([])) }}"
|
||||
tags: netbird_client_config
|
||||
block:
|
||||
# netbird writes its in-memory config back on exit, so edit only while it is stopped
|
||||
- name: Stop netbird to edit its config
|
||||
systemd:
|
||||
name: netbird
|
||||
state: stopped
|
||||
when: netbird_blacklist_missing | length > 0
|
||||
notify: restart_netbird
|
||||
register: netbird_stopped
|
||||
|
||||
- name: Re-read netbird config after stop
|
||||
slurp:
|
||||
src: /var/lib/netbird/default.json
|
||||
register: netbird_config_stopped
|
||||
when: netbird_stopped is changed
|
||||
|
||||
- name: Write IFaceBlackList
|
||||
copy:
|
||||
dest: /var/lib/netbird/default.json
|
||||
content: "{{ cfg | combine({'IFaceBlackList': cfg.IFaceBlackList | default([]) + netbird_client.iface_blacklist_extra | difference(cfg.IFaceBlackList | default([]))}) | to_nice_json(indent=4, sort_keys=False) }}\n"
|
||||
mode: "0600"
|
||||
vars:
|
||||
cfg: "{{ netbird_config_stopped.content | b64decode | from_json }}"
|
||||
when: netbird_stopped is changed
|
||||
|
||||
- name: Set netbird log level
|
||||
copy:
|
||||
dest: /etc/systemd/system/netbird.service.d/20-log-level.conf
|
||||
content: |
|
||||
[Service]
|
||||
ExecStart=
|
||||
ExecStart=/usr/bin/netbird service run --log-level {{ netbird_client.log_level }} --daemon-addr unix:///var/run/netbird.sock --log-file /var/log/netbird/client.log
|
||||
mode: "0644"
|
||||
when: netbird_client.log_level | default('') != ''
|
||||
notify: restart_netbird
|
||||
tags: netbird_client_config
|
||||
@@ -1,26 +1,28 @@
|
||||
- name: Install Packages
|
||||
# when: docker_file.stat.exists == False
|
||||
package:
|
||||
name:
|
||||
- ca-certificates
|
||||
- curl
|
||||
- gnupg
|
||||
|
||||
- name: Add netbird-key
|
||||
apt_key:
|
||||
url: https://pkgs.wiretrustee.com/debian/public.key
|
||||
state: present
|
||||
# Same keyring path the hand-installed hosts use, so the repository line is identical.
|
||||
- name: Install the netbird repository keyring
|
||||
ansible.builtin.shell:
|
||||
cmd: set -o pipefail && curl -fsSL https://pkgs.netbird.io/debian/public.key | gpg --dearmor -o /usr/share/keyrings/netbird-archive-keyring.gpg
|
||||
executable: /bin/bash
|
||||
creates: /usr/share/keyrings/netbird-archive-keyring.gpg
|
||||
|
||||
- name: Add netbird-repository
|
||||
apt_repository:
|
||||
repo: "deb https://pkgs.wiretrustee.com/debian stable main"
|
||||
repo: "deb [signed-by=/usr/share/keyrings/netbird-archive-keyring.gpg] https://pkgs.netbird.io/debian stable main"
|
||||
state: present
|
||||
filename: netbird
|
||||
update_cache: yes
|
||||
|
||||
# present, not latest: an upgrade restarts the daemon and drops the tunnels of the node.
|
||||
- name: Install wireguard & netbird
|
||||
package:
|
||||
name:
|
||||
- wireguard
|
||||
- netbird
|
||||
state: latest
|
||||
state: present
|
||||
|
||||
@@ -1,16 +1,37 @@
|
||||
- name: Read the netbird status
|
||||
when: "netbird_client.join_network.setup_key | default('') | length > 0"
|
||||
command: netbird status -d
|
||||
register: netbird_status
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
check_mode: false
|
||||
|
||||
# Joined means connected to the management server of the vars; without a management_url any server counts.
|
||||
- name: Join netbird-network
|
||||
when: "netbird_client.join_network.setup_key is defined"
|
||||
command: "netbird up --management-url {{ netbird_client.join_network.management_url }} --setup-key {{ netbird_client.join_network.setup_key }}"
|
||||
failed_when: command.rc != 0
|
||||
changed_when: "'Connected' in command.stdout"
|
||||
register: command
|
||||
when:
|
||||
- "netbird_client.join_network.setup_key | default('') | length > 0"
|
||||
- netbird_status.stdout is not search(netbird_joined_pattern, multiline=True)
|
||||
vars:
|
||||
netbird_management_url: "{{ netbird_client.join_network.management_url | default('') }}"
|
||||
netbird_joined_pattern: "^Management: Connected{{ (' to ' ~ (netbird_management_url | regex_escape) ~ '$') if netbird_management_url != '' else '' }}"
|
||||
netbird_blacklist_extra: "{{ netbird_client.iface_blacklist_extra | default([]) }}"
|
||||
netbird_up_argv: >-
|
||||
{{ ['netbird', 'up']
|
||||
+ (['--management-url', netbird_management_url] if netbird_management_url != '' else [])
|
||||
+ ['--setup-key', netbird_client.join_network.setup_key]
|
||||
+ (['--extra-iface-blacklist', netbird_blacklist_extra | join(',')] if netbird_blacklist_extra | length > 0 else []) }}
|
||||
command:
|
||||
argv: "{{ netbird_up_argv }}"
|
||||
no_log: true
|
||||
changed_when: true
|
||||
register: join
|
||||
|
||||
- name: Wait for netbird-interface to exist
|
||||
wait_for:
|
||||
path: "/sys/class/net/wt0"
|
||||
state: present
|
||||
when: command.changed
|
||||
when: join is changed
|
||||
|
||||
- name: Gather facts to get changes
|
||||
ansible.builtin.gather_facts:
|
||||
when: command.changed
|
||||
when: join is changed
|
||||
|
||||
@@ -2,3 +2,4 @@
|
||||
|
||||
- import_tasks: ./join-network.yml
|
||||
|
||||
- import_tasks: ./config.yml
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
unattended_upgrades:
|
||||
# Security updates only. Third-party repositories (Docker, Kopia, CrowdSec, NetBird, Proxmox, GitLab) stay out:
|
||||
# an update of docker-ce or a pve package restarts every container or guest.
|
||||
# Keyed by ansible_distribution; Debian lists go to Origins-Pattern, Ubuntu lists to Allowed-Origins.
|
||||
origins_pattern:
|
||||
Debian:
|
||||
- origin=Debian,codename=${distro_codename}-security,label=Debian-Security
|
||||
allowed_origins:
|
||||
Ubuntu:
|
||||
- ${distro_id}:${distro_codename}-security
|
||||
- ${distro_id}ESMApps:${distro_codename}-apps-security
|
||||
- ${distro_id}ESM:${distro_codename}-infra-security
|
||||
# Recipient of the report mail; unset sends none, as no host has an outgoing mail setup.
|
||||
mail:
|
||||
mail_report: only-on-error
|
||||
@@ -0,0 +1,33 @@
|
||||
---
|
||||
- name: Require an allowed origin for the distribution
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- (unattended_upgrades.origins_pattern[ansible_distribution] | default([]) + unattended_upgrades.allowed_origins[ansible_distribution] | default([])) | length > 0
|
||||
fail_msg: unattended_upgrades has no origins for {{ ansible_distribution }}
|
||||
|
||||
- name: Install unattended-upgrades
|
||||
ansible.builtin.apt:
|
||||
name: unattended-upgrades
|
||||
state: present
|
||||
|
||||
- name: Enable the daily package list update and upgrade
|
||||
ansible.builtin.template:
|
||||
src: 20auto-upgrades.j2
|
||||
dest: /etc/apt/apt.conf.d/20auto-upgrades
|
||||
mode: "0644"
|
||||
|
||||
# Separate file, the package owns 50unattended-upgrades.
|
||||
- name: Configure unattended-upgrades
|
||||
ansible.builtin.template:
|
||||
src: 52unattended-upgrades-local.j2
|
||||
dest: /etc/apt/apt.conf.d/52unattended-upgrades-local
|
||||
mode: "0644"
|
||||
|
||||
- name: Enable the apt timers
|
||||
ansible.builtin.systemd:
|
||||
name: "{{ item }}"
|
||||
enabled: true
|
||||
state: started
|
||||
loop:
|
||||
- apt-daily.timer
|
||||
- apt-daily-upgrade.timer
|
||||
@@ -0,0 +1,4 @@
|
||||
// {{ ansible_managed }}
|
||||
APT::Periodic::Update-Package-Lists "1";
|
||||
APT::Periodic::Unattended-Upgrade "1";
|
||||
APT::Periodic::AutocleanInterval "7";
|
||||
@@ -0,0 +1,30 @@
|
||||
// {{ ansible_managed }}
|
||||
// Replaces the origins of 50unattended-upgrades; apt list options append otherwise.
|
||||
#clear Unattended-Upgrade::Allowed-Origins;
|
||||
#clear Unattended-Upgrade::Origins-Pattern;
|
||||
{% set patterns = unattended_upgrades.origins_pattern[ansible_distribution] | default([]) %}
|
||||
{% if patterns %}
|
||||
Unattended-Upgrade::Origins-Pattern {
|
||||
{% for origin in patterns %}
|
||||
"{{ origin }}";
|
||||
{% endfor %}
|
||||
};
|
||||
{% endif %}
|
||||
{% set allowed = unattended_upgrades.allowed_origins[ansible_distribution] | default([]) %}
|
||||
{% if allowed %}
|
||||
Unattended-Upgrade::Allowed-Origins {
|
||||
{% for origin in allowed %}
|
||||
"{{ origin }}";
|
||||
{% endfor %}
|
||||
};
|
||||
{% endif %}
|
||||
|
||||
// No automatic reboot, the owner schedules those.
|
||||
Unattended-Upgrade::Automatic-Reboot "false";
|
||||
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
|
||||
Unattended-Upgrade::Remove-New-Unused-Dependencies "true";
|
||||
Unattended-Upgrade::Remove-Unused-Dependencies "false";
|
||||
{% if unattended_upgrades.mail %}
|
||||
Unattended-Upgrade::Mail "{{ unattended_upgrades.mail }}";
|
||||
Unattended-Upgrade::MailReport "{{ unattended_upgrades.mail_report }}";
|
||||
{% endif %}
|
||||
Reference in New Issue
Block a user