commit 13eace9ce9eb46635156f262a9fcef18fa5984b4 Author: pyrschtjag Date: Fri Oct 2 21:34:01 2026 +0400 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c5298c --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.retry +.cache/ +__pycache__/ +*.pyc +.DS_Store +Thumbs.db diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..ebb12d7 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,11 @@ +[defaults] +inventory = ../inventory/ +roles_path = roles/ +host_key_checking = False +forks = 8 +vault_password_file = ../inventory/.vault_pass +deprecation_warnings=False + +[inventory] +enable_plugins = community.proxmox.proxmox, host_list, yaml, ini +cache = True diff --git a/playbooks/asf.yml b/playbooks/asf.yml new file mode 100644 index 0000000..9376718 --- /dev/null +++ b/playbooks/asf.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: asf + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - asf diff --git a/playbooks/bootstrap.yml b/playbooks/bootstrap.yml new file mode 100644 index 0000000..8d26ab5 --- /dev/null +++ b/playbooks/bootstrap.yml @@ -0,0 +1,12 @@ +--- +- name: bootstrap ssh keys via pct on all proxmox LXC containers + hosts: proxmox_all_lxc + gather_facts: false + roles: + - authorized-key + +- name: router-specific pct-only network bootstrap (before ssh is reachable) + hosts: router + gather_facts: false + roles: + - ifupdown2 diff --git a/playbooks/byparr.yml b/playbooks/byparr.yml new file mode 100644 index 0000000..eca7535 --- /dev/null +++ b/playbooks/byparr.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: byparr + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - byparr diff --git a/playbooks/coturn.yml b/playbooks/coturn.yml new file mode 100644 index 0000000..85afb05 --- /dev/null +++ b/playbooks/coturn.yml @@ -0,0 +1,15 @@ +--- +- name: configure over ssh + hosts: coturn + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - coturn + - certbot diff --git a/playbooks/dev.yml b/playbooks/dev.yml new file mode 100644 index 0000000..6e92fe2 --- /dev/null +++ b/playbooks/dev.yml @@ -0,0 +1,27 @@ +--- +- name: configure over ssh + hosts: dev + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: >- + -o UserKnownHostsFile=/dev/null + -o StrictHostKeyChecking=no + -o PreferredAuthentications=publickey,password + -o PubkeyAuthentication=yes + roles: + - authorized-key + - sshd + - sysctl + - hostname + - resolv + - nftables + - nginx + - certbot + - placeholder + - xray-core + - logrotate + - telemt + - netutils diff --git a/playbooks/dev_shin.yml b/playbooks/dev_shin.yml new file mode 100644 index 0000000..c3427c9 --- /dev/null +++ b/playbooks/dev_shin.yml @@ -0,0 +1,27 @@ +--- +- name: configure over ssh + hosts: dev_shin + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: >- + -o UserKnownHostsFile=/dev/null + -o StrictHostKeyChecking=no + -o PreferredAuthentications=publickey,password + -o PubkeyAuthentication=yes + roles: + - authorized-key + - sshd + - sysctl + - hostname + - resolv + - nftables + - nginx + - certbot + - placeholder + - xray-core + - logrotate + - telemt + - netutils diff --git a/playbooks/firebat.yml b/playbooks/firebat.yml new file mode 100644 index 0000000..0a4f8b8 --- /dev/null +++ b/playbooks/firebat.yml @@ -0,0 +1,11 @@ +--- +- name: configure over ssh + hosts: firebat + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - zfs diff --git a/playbooks/gitea.yml b/playbooks/gitea.yml new file mode 100644 index 0000000..324b6f8 --- /dev/null +++ b/playbooks/gitea.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: gitea + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - gitea diff --git a/playbooks/lampa.yml b/playbooks/lampa.yml new file mode 100644 index 0000000..832c3a9 --- /dev/null +++ b/playbooks/lampa.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: lampa + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - lampa diff --git a/playbooks/liqueur.yml b/playbooks/liqueur.yml new file mode 100644 index 0000000..3f8dbbf --- /dev/null +++ b/playbooks/liqueur.yml @@ -0,0 +1,26 @@ +--- +- name: configure over ssh + hosts: liqueur + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: >- + -o UserKnownHostsFile=/dev/null + -o StrictHostKeyChecking=no + -o PreferredAuthentications=publickey,password + -o PubkeyAuthentication=yes + roles: + - authorized-key + - sshd + - sysctl + - hostname + - resolv + - nftables + - nginx + - certbot + - stunnel4 + - openvpn + - haproxy + - netutils diff --git a/playbooks/nfs.yml b/playbooks/nfs.yml new file mode 100644 index 0000000..192fc20 --- /dev/null +++ b/playbooks/nfs.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: nfs + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - nfs diff --git a/playbooks/nginx.yml b/playbooks/nginx.yml new file mode 100644 index 0000000..7fe5cb0 --- /dev/null +++ b/playbooks/nginx.yml @@ -0,0 +1,15 @@ +--- +- name: configure over ssh + hosts: nginx + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - nginx + - certbot diff --git a/playbooks/ntfy.yml b/playbooks/ntfy.yml new file mode 100644 index 0000000..b1b017f --- /dev/null +++ b/playbooks/ntfy.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: ntfy + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - ntfy diff --git a/playbooks/pgsql.yml b/playbooks/pgsql.yml new file mode 100644 index 0000000..7a6dc6d --- /dev/null +++ b/playbooks/pgsql.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: pgsql + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - pgsql diff --git a/playbooks/prosody.yml b/playbooks/prosody.yml new file mode 100644 index 0000000..2598ae3 --- /dev/null +++ b/playbooks/prosody.yml @@ -0,0 +1,15 @@ +--- +- name: configure over ssh + hosts: prosody + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - prosody + - certbot diff --git a/playbooks/prowlarr.yml b/playbooks/prowlarr.yml new file mode 100644 index 0000000..ee4a3f9 --- /dev/null +++ b/playbooks/prowlarr.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: prowlarr + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - prowlarr diff --git a/playbooks/ps3netsrv.yml b/playbooks/ps3netsrv.yml new file mode 100644 index 0000000..faf2d0a --- /dev/null +++ b/playbooks/ps3netsrv.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: ps3netsrv + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - ps3netsrv diff --git a/playbooks/radicale.yml b/playbooks/radicale.yml new file mode 100644 index 0000000..ec4d822 --- /dev/null +++ b/playbooks/radicale.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: radicale + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - radicale diff --git a/playbooks/router.yml b/playbooks/router.yml new file mode 100644 index 0000000..fa618fe --- /dev/null +++ b/playbooks/router.yml @@ -0,0 +1,28 @@ +--- +- name: configure over ssh + hosts: router + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: >- + -o UserKnownHostsFile=/dev/null + -o StrictHostKeyChecking=no + -o PreferredAuthentications=publickey,password + -o PubkeyAuthentication=yes + roles: + - sshd + - timezone + - locales + - sysctl + - stunnel4 + - openvpn + - xray-core + - logrotate + - dnsmasq + - xray-lists + - unbound + - resolv + - nftables + - netutils diff --git a/playbooks/rtorrent.yml b/playbooks/rtorrent.yml new file mode 100644 index 0000000..53566eb --- /dev/null +++ b/playbooks/rtorrent.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: rtorrent + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - rtorrent diff --git a/playbooks/runner.yml b/playbooks/runner.yml new file mode 100644 index 0000000..c1d9254 --- /dev/null +++ b/playbooks/runner.yml @@ -0,0 +1,10 @@ +--- +- name: deploy rasy-rsa + hosts: localhost + connection: local + become: true + roles: + - sshd + - timezone + - locales + - easy-rsa diff --git a/playbooks/slskd.yml b/playbooks/slskd.yml new file mode 100644 index 0000000..6e266aa --- /dev/null +++ b/playbooks/slskd.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: slskd + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - slskd diff --git a/playbooks/smb-legacy.yml b/playbooks/smb-legacy.yml new file mode 100644 index 0000000..96d339b --- /dev/null +++ b/playbooks/smb-legacy.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: smb-legacy + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - samba diff --git a/playbooks/torrserver.yml b/playbooks/torrserver.yml new file mode 100644 index 0000000..3f00c59 --- /dev/null +++ b/playbooks/torrserver.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: torrserver + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - torrserver diff --git a/playbooks/valheim.yml b/playbooks/valheim.yml new file mode 100644 index 0000000..f396352 --- /dev/null +++ b/playbooks/valheim.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: valheim + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - valheim diff --git a/playbooks/vaultwarden.yml b/playbooks/vaultwarden.yml new file mode 100644 index 0000000..034194d --- /dev/null +++ b/playbooks/vaultwarden.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: vaultwarden + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - vaultwarden diff --git a/playbooks/vector.yml b/playbooks/vector.yml new file mode 100644 index 0000000..cbb19b3 --- /dev/null +++ b/playbooks/vector.yml @@ -0,0 +1,27 @@ +--- +- name: configure over ssh + hosts: vector + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: >- + -o UserKnownHostsFile=/dev/null + -o StrictHostKeyChecking=no + -o PreferredAuthentications=publickey,password + -o PubkeyAuthentication=yes + roles: + - authorized-key + - sshd + - sysctl + - hostname + - resolv + - nftables + - nginx + - certbot + - placeholder + - xray-core + - logrotate + - telemt + - netutils diff --git a/playbooks/zabbix-server.yml b/playbooks/zabbix-server.yml new file mode 100644 index 0000000..e7a0c66 --- /dev/null +++ b/playbooks/zabbix-server.yml @@ -0,0 +1,14 @@ +--- +- name: configure over ssh + hosts: zabbix + vars: + ansible_connection: ssh + ansible_host: "{{ ip }}" + ansible_user: root + ansible_ssh_private_key_file: ~/.ssh/id_ed25519 + ansible_ssh_common_args: '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + roles: + - sshd + - timezone + - locales + - zabbix-server diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..f440506 --- /dev/null +++ b/requirements.yml @@ -0,0 +1,2 @@ +collections: + - name: community.proxmox diff --git a/roles/asf/files/asf.service b/roles/asf/files/asf.service new file mode 100644 index 0000000..26a5194 --- /dev/null +++ b/roles/asf/files/asf.service @@ -0,0 +1,50 @@ +[Unit] +Description=ArchiSteamFarm Service +Documentation=https://github.com/JustArchiNET/ArchiSteamFarm/wiki +After=network.target + +[Service] +Environment="DOTNET_CLI_TELEMETRY_OPTOUT=true" +Environment="DOTNET_EnableDiagnostics=0" +Environment="DOTNET_NOLOGO=true" +EnvironmentFile=-/etc/asf/asf +WorkingDirectory=/var/lib/asf +ExecStart=/opt/asf/ArchiSteamFarm --path /var/lib/asf --no-restart --service --system-required +Restart=on-success +RestartSec=1s +RuntimeDirectory=asf +SyslogIdentifier=asf +User=asf +Group=asf +CapabilityBoundingSet= +DevicePolicy=closed +LockPersonality=yes +NoNewPrivileges=yes +PrivateDevices=yes +PrivateIPC=yes +PrivateMounts=yes +PrivateUsers=yes +ProcSubset=pid +ProtectClock=yes +ProtectControlGroups=yes +ProtectHome=read-only +ProtectHostname=yes +ProtectKernelLogs=yes +ProtectKernelModules=yes +ProtectKernelTunables=yes +ProtectProc=invisible +ProtectSystem=strict +ReadWritePaths=/var/lib/asf /tmp +RemoveIPC=yes +RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX +RestrictNamespaces=yes +RestrictRealtime=yes +RestrictSUIDSGID=yes +SecureBits=noroot-locked +SystemCallArchitectures=native +SystemCallFilter=@system-service mincore +SystemCallFilter=~@privileged +UMask=0077 + +[Install] +WantedBy=multi-user.target diff --git a/roles/asf/files/asf/ASF.json b/roles/asf/files/asf/ASF.json new file mode 100644 index 0000000..f2f7212 --- /dev/null +++ b/roles/asf/files/asf/ASF.json @@ -0,0 +1,3 @@ +{ + "Headless": true +} \ No newline at end of file diff --git a/roles/asf/files/asf/IPC.config b/roles/asf/files/asf/IPC.config new file mode 100644 index 0000000..11b1a4f --- /dev/null +++ b/roles/asf/files/asf/IPC.config @@ -0,0 +1,14 @@ +{ + "Kestrel": { + "Endpoints": { + "HTTP4": { + "Url": "http://*:1242" + } + }, + "KnownNetworks": [ + "10.0.0.0/8", + "192.168.0.0/16" + ], + "PathBase": "/" + } +} diff --git a/roles/asf/handlers/main.yml b/roles/asf/handlers/main.yml new file mode 100644 index 0000000..7c7c43e --- /dev/null +++ b/roles/asf/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart asf + ansible.builtin.systemd_service: + name: asf + state: restarted + enabled: true + daemon_reload: true diff --git a/roles/asf/tasks/main.yml b/roles/asf/tasks/main.yml new file mode 100644 index 0000000..a4bfb05 --- /dev/null +++ b/roles/asf/tasks/main.yml @@ -0,0 +1,147 @@ +--- +- name: create asf group + ansible.builtin.group: + name: asf + system: true + state: present + +- name: create asf user + ansible.builtin.user: + name: asf + group: asf + system: true + shell: /usr/sbin/nologin + home: /var/lib/asf + create_home: true + state: present + +- name: install depenedencies + ansible.builtin.package: + name: + - unzip + - jq + - curl + state: latest + update_cache: true + +- name: get latest asf release info + ansible.builtin.uri: + url: https://api.github.com/repos/JustArchiNET/ArchiSteamFarm/releases/latest + return_content: yes + register: asf_release + run_once: true + check_mode: false + +- name: set current asf version + ansible.builtin.set_fact: + asf_version: "{{ asf_release.json.tag_name | regex_replace('^v', '') }}" + asf_asset_url: "{{ asf_release.json.assets | selectattr('name', 'equalto', 'ASF-linux-x64.zip') | map(attribute='browser_download_url') | first }}" + +- name: check asf installed version + ansible.builtin.command: su - asf -s /bin/bash -c "curl -s http://127.0.0.1:1242/Api/ASF | jq -r '.Result.Version'" + register: asf_current_version + changed_when: false + failed_when: false + +- name: display asf version info + ansible.builtin.debug: + msg: "latest version: {{ asf_version }}, installed version: {{ asf_current_version.stdout | default('not installed', true) }}" + +- name: ensure asf directory exists + ansible.builtin.file: + path: /opt/asf + state: directory + owner: root + group: root + mode: "0755" + +- name: update asf + ansible.builtin.unarchive: + src: "{{ asf_asset_url }}" + dest: /opt/asf + remote_src: yes + owner: root + group: root + when: asf_version != (asf_current_version.stdout | default('')) + notify: restart asf + +- name: make asf binary executable + ansible.builtin.file: + path: /opt/asf/ArchiSteamFarm + mode: "0755" + +- name: deploy asf systemd service unit + ansible.builtin.copy: + src: asf.service + dest: /etc/systemd/system/asf.service + mode: "0644" + notify: restart asf + +- name: ensure asf config directory exists + ansible.builtin.file: + path: /etc/asf + state: directory + owner: root + group: root + mode: "0755" + +- name: deploy asf configs + ansible.builtin.copy: + src: "{{ inventory_hostname }}/{{ item }}" + dest: "/etc/asf/{{ item }}" + owner: asf + group: asf + mode: "0640" + loop: + - ASF.json + - IPC.config + notify: restart asf + +- name: ensure asf config directory exists + ansible.builtin.file: + path: /var/lib/asf/config + state: directory + owner: asf + group: asf + mode: "0755" + +- name: symlink asf configs + ansible.builtin.file: + src: "/etc/asf/{{ item }}" + dest: "/var/lib/asf/config/{{ item }}" + state: link + force: true + loop: + - ASF.json + - IPC.config + notify: restart asf + +- name: check if asf data directory is a mountpoint + ansible.builtin.command: mountpoint -q /var/lib/asf/config/ + register: vw_mountpoint + failed_when: false + changed_when: false + +- name: ensure asf data source directory exists + ansible.builtin.file: + path: /mnt/asf/data + state: directory + owner: asf + group: asf + mode: "0755" + +- name: bind mount asf data directory + ansible.posix.mount: + path: /var/lib/asf/config/ + src: /mnt/asf/data + fstype: none + opts: bind + state: mounted + notify: restart asf + +- name: set ownership on asf data directory + ansible.builtin.file: + path: /mnt/asf/data + owner: asf + group: asf + recurse: true diff --git a/roles/authorized-key/tasks/main.yml b/roles/authorized-key/tasks/main.yml new file mode 100644 index 0000000..57bdf1c --- /dev/null +++ b/roles/authorized-key/tasks/main.yml @@ -0,0 +1,15 @@ +--- +- name: ensure .ssh exists + ansible.builtin.file: + path: /root/.ssh + state: directory + mode: "0700" + owner: root + group: root + +- name: set authorized key + ansible.posix.authorized_key: + user: root + state: present + key: "{{ item }}" + loop: "{{ ssh_keys }}" diff --git a/roles/byparr/files/byparr.service b/roles/byparr/files/byparr.service new file mode 100644 index 0000000..7d180ff --- /dev/null +++ b/roles/byparr/files/byparr.service @@ -0,0 +1,30 @@ +[Unit] +Description=Byparr (FlareSolverr-compatible solver) +Documentation=https://github.com/ThePhaseless/Byparr +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=byparr +Group=byparr +WorkingDirectory=/opt/byparr +Environment=HOME=/var/lib/byparr +Environment=PYTHONDONTWRITEBYTECODE=1 +EnvironmentFile=-/etc/byparr/byparr.env +ExecStart=/opt/byparr/.venv/bin/python main.py +Restart=on-failure +RestartSec=5 + +NoNewPrivileges=yes +PrivateTmp=yes +ProtectSystem=strict +ReadWritePaths=/var/lib/byparr +ProtectKernelTunables=yes +ProtectKernelModules=yes +ProtectControlGroups=yes +RestrictSUIDSGID=yes +LockPersonality=yes + +[Install] +WantedBy=multi-user.target diff --git a/roles/byparr/handlers/main.yml b/roles/byparr/handlers/main.yml new file mode 100644 index 0000000..2d13773 --- /dev/null +++ b/roles/byparr/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart byparr + ansible.builtin.systemd: + name: byparr + state: restarted + enabled: true + daemon_reload: true diff --git a/roles/byparr/tasks/main.yml b/roles/byparr/tasks/main.yml new file mode 100644 index 0000000..817afa3 --- /dev/null +++ b/roles/byparr/tasks/main.yml @@ -0,0 +1,93 @@ +--- +- name: create byparr group + ansible.builtin.group: + name: byparr + system: true + state: present + +- name: create byparr user + ansible.builtin.user: + name: byparr + group: byparr + system: true + shell: /usr/sbin/nologin + home: /var/lib/byparr + create_home: true + state: present + +- name: install dependencies + ansible.builtin.apt: + name: + - git + - curl + - ca-certificates + - xvfb + - libgtk-3-0 + - libasound2 + state: present + update_cache: true + +- name: install uv + ansible.builtin.shell: > + curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR=/usr/local/bin UV_NO_MODIFY_PATH=1 sh + args: + executable: /bin/bash + creates: /usr/local/bin/uv + +- name: ensure byparr directory exists + ansible.builtin.file: + path: "/opt/byparr" + state: directory + owner: "root" + group: "root" + mode: "0755" + +- name: clone byparr + ansible.builtin.git: + repo: https://github.com/ThePhaseless/Byparr + dest: /opt/byparr + version: "{{ byparr_version | default('main') }}" + force: true + register: byparr_repo + notify: restart byparr + +- name: check if byparr venv exists + ansible.builtin.stat: + path: /opt/byparr/.venv/bin/python + register: byparr_venv + +- name: sync byparr dependencies + ansible.builtin.command: /usr/local/bin/uv sync --frozen --no-dev + args: + chdir: /opt/byparr + environment: + UV_PROJECT_ENVIRONMENT: /opt/byparr/.venv + UV_PYTHON_INSTALL_DIR: /opt/byparr/python + when: byparr_repo.changed or not byparr_venv.stat.exists + notify: restart byparr + +- name: ensure byparr config directory exists + ansible.builtin.file: + path: "/etc/byparr" + state: directory + owner: "root" + group: "root" + mode: "0755" + +- name: deploy byparr environment + ansible.builtin.template: + src: byparr.env.j2 + dest: /etc/byparr/byparr.env + owner: root + group: byparr + mode: "0640" + notify: restart byparr + +- name: deploy byparr systemd unit + ansible.builtin.copy: + src: byparr.service + dest: /etc/systemd/system/byparr.service + owner: root + group: root + mode: "0644" + notify: restart byparr diff --git a/roles/byparr/templates/byparr.env.j2 b/roles/byparr/templates/byparr.env.j2 new file mode 100644 index 0000000..fb5871e --- /dev/null +++ b/roles/byparr/templates/byparr.env.j2 @@ -0,0 +1,3 @@ +{% for key, value in (byparr_env | default({})).items() %} +{{ key }}={{ value }} +{% endfor %} diff --git a/roles/certbot/tasks/main.yml b/roles/certbot/tasks/main.yml new file mode 100644 index 0000000..fa06a6d --- /dev/null +++ b/roles/certbot/tasks/main.yml @@ -0,0 +1,74 @@ +--- +- name: install certbot and dnsutils + ansible.builtin.apt: + name: + - certbot + - dnsutils + state: present + update_cache: true + +- name: install certbot cloudflare plugin + ansible.builtin.apt: + name: python3-certbot-dns-cloudflare + state: present + when: >- + dnsmasq | selectattr('cert_method', 'defined') + | selectattr('cert_method', 'equalto', 'cloudflare_dns') + | list | length > 0 + +- name: resolve certificate domain + ansible.builtin.command: + cmd: "dig +short A {{ item.name }}" + loop: "{{ dnsmasq }}" + loop_control: + label: "{{ item.name }}" + register: dns_check + changed_when: false + check_mode: false + when: item.cert | default(false) + +- name: fail if a domain does not point at this server + ansible.builtin.fail: + msg: "{{ item.item.name }} does not resolve to {{ ip }}" + loop: "{{ dns_check.results }}" + loop_control: + label: "{{ item.item.name }}" + when: + - item.item.cert | default(false) + - item.item.cert_method | default('standalone') != 'cloudflare_dns' + - (ip | default(ansible_host)) not in item.stdout_lines + +- name: create cloudflare secret + ansible.builtin.copy: + content: "dns_cloudflare_api_token = {{ item.cloudflare_token }}\n" + dest: "/etc/letsencrypt/cloudflare-{{ item.name }}.ini" + mode: '0600' + loop: "{{ dnsmasq }}" + loop_control: + label: "{{ item.name }}" + when: + - item.cert | default(false) + - item.cert_method | default('standalone') == 'cloudflare_dns' + no_log: true + +- name: issue certificate if missing + ansible.builtin.command: + cmd: >- + certbot certonly --non-interactive --agree-tos --register-unsafely-without-email + {% if item.cert_method | default('standalone') == 'cloudflare_dns' %} + --dns-cloudflare + --dns-cloudflare-credentials /etc/letsencrypt/cloudflare-{{ item.name }}.ini + --dns-cloudflare-propagation-seconds 60 + {% else %} + --standalone + {% if item.pre_hook is defined %}--pre-hook "{{ item.pre_hook }}"{% endif %} + {% if item.post_hook is defined %}--post-hook "{{ item.post_hook }}"{% endif %} + {% endif %} + {% if item.deploy_hook is defined %}--deploy-hook "{{ item.deploy_hook }}"{% endif %} + -d {{ item.name }} + {% if item.cert_wildcard | default(false) %}-d '*.{{ item.name }}'{% endif %} + creates: "/etc/letsencrypt/live/{{ item.name }}/fullchain.pem" + loop: "{{ dnsmasq }}" + loop_control: + label: "{{ item.name }}" + when: item.cert | default(false) diff --git a/roles/coturn/files/coturn b/roles/coturn/files/coturn new file mode 100644 index 0000000..7f7159c --- /dev/null +++ b/roles/coturn/files/coturn @@ -0,0 +1 @@ +TURNSERVER_ENABLED=1 diff --git a/roles/coturn/handlers/main.yml b/roles/coturn/handlers/main.yml new file mode 100644 index 0000000..c1ba33c --- /dev/null +++ b/roles/coturn/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart coturn + ansible.builtin.systemd_service: + name: coturn + state: restarted + enabled: true diff --git a/roles/coturn/tasks/main.yml b/roles/coturn/tasks/main.yml new file mode 100644 index 0000000..3130dcc --- /dev/null +++ b/roles/coturn/tasks/main.yml @@ -0,0 +1,32 @@ +--- +- name: install coturn + ansible.builtin.apt: + name: coturn + state: latest + update_cache: true + notify: restart coturn + +- name: ensure /var/lib/coturn/certs exists + ansible.builtin.file: + path: /var/lib/turn/certs + owner: "turnserver" + group: "turnserver" + state: directory + +- name: enable coturn daemon + ansible.builtin.copy: + src: coturn + dest: /etc/default/coturn + owner: root + group: root + mode: "0644" + notify: restart coturn + +- name: deploy coturn config + ansible.builtin.template: + src: "{{ inventory_hostname }}/turnserver.conf.j2" + dest: /etc/turnserver.conf + owner: root + group: turnserver + mode: "0640" + notify: restart coturn diff --git a/roles/coturn/templates/coturn/turnserver.conf.j2 b/roles/coturn/templates/coturn/turnserver.conf.j2 new file mode 100644 index 0000000..d0b9523 --- /dev/null +++ b/roles/coturn/templates/coturn/turnserver.conf.j2 @@ -0,0 +1,29 @@ +listening-ip={{ ip }} +external-ip={{ hostvars['liqueur'].ip }}/{{ ip }} +listening-port=3478 +tls-listening-port=5349 +verbose +min-port=49152 +max-port=65535 +fingerprint +use-auth-secret +static-auth-secret={{ turn_external_secret }} +realm=oyacoi.ru +cert=/var/lib/turn/certs/fullchain.pem +pkey=/var/lib/turn/certs/privkey.pem +prod +no-multicast-peers +no-cli +no-tlsv1 +no-tlsv1_1 +no-rfc5780 +no-stun-backward-compatibility +response-origin-only-with-rfc5780 +relay-ip={{ ip }} +denied-peer-ip=10.0.0.0-10.255.255.255 +denied-peer-ip=172.16.0.0-172.31.255.255 +denied-peer-ip=192.168.0.0-192.168.255.255 +denied-peer-ip=0.0.0.0-0.255.255.255 +denied-peer-ip=100.64.0.0-100.127.255.255 +denied-peer-ip=169.254.0.0-169.254.255.255 +allowed-peer-ip={{ hostvars['prosody'].ip }} diff --git a/roles/dnsmasq/handlers/main.yml b/roles/dnsmasq/handlers/main.yml new file mode 100644 index 0000000..a16ea6c --- /dev/null +++ b/roles/dnsmasq/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart dnsmasq + ansible.builtin.service: + name: dnsmasq + state: restarted + enables: true diff --git a/roles/dnsmasq/tasks/main.yml b/roles/dnsmasq/tasks/main.yml new file mode 100644 index 0000000..865bc67 --- /dev/null +++ b/roles/dnsmasq/tasks/main.yml @@ -0,0 +1,33 @@ +--- +- name: install dnsmasq + ansible.builtin.apt: + name: dnsmasq + state: latest + update_cache: true + notify: restart dnsmasq + +- name: ensure dnsmasq.d directory exists + ansible.builtin.file: + path: /etc/dnsmasq.d + state: directory + mode: "0755" + +- name: deploy dnsmasq hook + ansible.builtin.copy: + dest: /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate + content: | + make_resolv_conf() { + : + } + owner: root + group: root + mode: "0755" + notify: restart dnsmasq + +- name: deploy dnsmasq rule + ansible.builtin.template: + src: "{{ item }}" + dest: "/etc/dnsmasq.d/{{ item | basename | regex_replace('\\.j2$', '') }}" + mode: "0644" + loop: "{{ query('ansible.builtin.fileglob', role_path + '/templates/' + inventory_hostname + '/*.conf.j2') }}" + notify: restart dnsmasq diff --git a/roles/dnsmasq/templates/router/10-upstream.conf.j2 b/roles/dnsmasq/templates/router/10-upstream.conf.j2 new file mode 100644 index 0000000..a9e3c93 --- /dev/null +++ b/roles/dnsmasq/templates/router/10-upstream.conf.j2 @@ -0,0 +1,14 @@ +interface=lo +interface=br-eth0 +interface=eth0.2 +interface=eth0.3 +interface=eth0.4 +interface=eth0.10 +interface=eth0.11 +interface=eth0.12 +bind-dynamic +no-resolv +server=127.0.0.1#5353 +#server=1.1.1.1 +domain=lan +local=/lan/ diff --git a/roles/dnsmasq/templates/router/20-custom-domains.conf.j2 b/roles/dnsmasq/templates/router/20-custom-domains.conf.j2 new file mode 100644 index 0000000..6788c87 --- /dev/null +++ b/roles/dnsmasq/templates/router/20-custom-domains.conf.j2 @@ -0,0 +1,10 @@ +server=/dev.oyacoi.ru/9.9.9.9 +server=/vector.oyacoi.ru/9.9.9.9 +server=/.themoviedb.org/9.9.9.9 +server=/.tmdb.org/9.9.9.9 +server=/tmdb-image-prod.b-cdn.net/9.9.9.9 +server=/infolada.ru/217.113.115.150 +server=/infolada.ru/217.113.114.100 +server=/start.infolada.ru/217.113.115.150 +server=/start.infolada.ru/217.113.114.100 +conf-file=/var/lib/xray-lists/generated/nftsets.conf diff --git a/roles/dnsmasq/templates/router/20-dhcp.conf.j2 b/roles/dnsmasq/templates/router/20-dhcp.conf.j2 new file mode 100644 index 0000000..18712aa --- /dev/null +++ b/roles/dnsmasq/templates/router/20-dhcp.conf.j2 @@ -0,0 +1,3 @@ +dhcp-range=interface:eth0.3,10.3.0.200,10.3.0.254,255.255.255.0,2h +dhcp-option=interface:eth0.3,option:router,10.3.0.1 +dhcp-option=interface:eth0.3,option:dns-server,10.3.0.1 diff --git a/roles/dnsmasq/templates/router/20-dns-optimizations.conf.j2 b/roles/dnsmasq/templates/router/20-dns-optimizations.conf.j2 new file mode 100644 index 0000000..fc6a38f --- /dev/null +++ b/roles/dnsmasq/templates/router/20-dns-optimizations.conf.j2 @@ -0,0 +1,4 @@ +filterwin2k +domain-needed +bogus-priv +cache-size=0 diff --git a/roles/dnsmasq/templates/router/90-dhcp-host.conf.j2 b/roles/dnsmasq/templates/router/90-dhcp-host.conf.j2 new file mode 100644 index 0000000..f24c621 --- /dev/null +++ b/roles/dnsmasq/templates/router/90-dhcp-host.conf.j2 @@ -0,0 +1,13 @@ +#jinja2: trim_blocks: True, lstrip_blocks: True +{% for item in dnsmasq_managed_group | sort %} +{% set client = hostvars[item] %} +{% set ip = client.ip | default(client.ansible_host | default(none)) %} +{% if client['dhcp-host'] is defined and client['dhcp-host'] and ip %} +{% set entries = client['dhcp-host'] if (client['dhcp-host'] is iterable and client['dhcp-host'] is not string) else [client['dhcp-host']] %} +{% for entry in entries %} +{% if entry.mac %} +dhcp-host={{ entry.mac }},{{ ip }},{{ item }} +{% endif %} +{% endfor %} +{% endif %} +{% endfor %} diff --git a/roles/dnsmasq/templates/router/90-domains.conf.j2 b/roles/dnsmasq/templates/router/90-domains.conf.j2 new file mode 100644 index 0000000..bfb9fbd --- /dev/null +++ b/roles/dnsmasq/templates/router/90-domains.conf.j2 @@ -0,0 +1,9 @@ +#jinja2: trim_blocks: True, lstrip_blocks: True +{% for item in dnsmasq_managed_group | sort %} +{% for entry in hostvars[item].dnsmasq | default([]) %} +{% set ip = entry.ip | default(hostvars[entry.ip_from].ip if entry.ip_from is defined else none) %} +{% if ip %} +host-record={{ entry.name }},{{ ip }} +{% endif %} +{% endfor %} +{% endfor %} diff --git a/roles/dnsmasq/templates/router/90-local.conf.j2 b/roles/dnsmasq/templates/router/90-local.conf.j2 new file mode 100644 index 0000000..2b7fd4d --- /dev/null +++ b/roles/dnsmasq/templates/router/90-local.conf.j2 @@ -0,0 +1,8 @@ +#jinja2: trim_blocks: True, lstrip_blocks: True +{% for item in dnsmasq_managed_group | sort %} +{% set client = hostvars[item] %} +{% set ip = client.ip | default(client.ansible_host | default(none)) %} +{% if ip %} +host-record={{ item }},{{ item }}.lan,{{ ip }} +{% endif %} +{% endfor %} diff --git a/roles/easy-rsa/tasks/main.yml b/roles/easy-rsa/tasks/main.yml new file mode 100644 index 0000000..f95c4ac --- /dev/null +++ b/roles/easy-rsa/tasks/main.yml @@ -0,0 +1,140 @@ +--- +- name: get latest easy-rsa release info + ansible.builtin.uri: + url: https://api.github.com/repos/OpenVPN/easy-rsa/releases/latest + return_content: true + register: easyrsa_release + run_once: true + check_mode: false + +- name: set current easy-rsa version + ansible.builtin.set_fact: + easyrsa_version: "{{ easyrsa_release.json.tag_name | replace('v', '') }}" + easyrsa_asset_url: "{{ easyrsa_release.json.assets | selectattr('name', 'search', 'EasyRSA.*\\.tgz') | map(attribute='browser_download_url') | first }}" + +- name: check easy-rsa installed version + ansible.builtin.shell: > + /opt/easy-rsa/easyrsa version 2>&1 | grep -oP 'Version\s*:\s*\K[\d.]+' + register: easyrsa_current_version + changed_when: false + failed_when: false + +- name: display easy-rsa version info + ansible.builtin.debug: + msg: "latest version: {{ easyrsa_version }}, installed version: {{ easyrsa_current_version.stdout | default('not installed', true) }}" + +- name: ensure easy-rsa directory exists + ansible.builtin.file: + path: /opt/easy-rsa + state: directory + mode: "0755" + check_mode: false + +- name: update easy-rsa + ansible.builtin.unarchive: + src: "{{ easyrsa_asset_url }}" + dest: /opt/easy-rsa + remote_src: true + extra_opts: + - --strip-components=1 + when: easyrsa_version not in (easyrsa_current_version.stdout | default('')) + +- name: prepare list of client certificates + ansible.builtin.set_fact: + cert_list: "{{ cert_list | default([]) + [ {'instance': item.0.name, 'pki_dir': item.0.pki_dir, 'client': item.1} ] }}" + loop: "{{ openvpn_instances | subelements('clients') }}" + +- name: ensure local pki directories exists + ansible.builtin.file: + path: "{{ item.pki_dir }}" + state: directory + mode: '0700' + loop: "{{ openvpn_instances }}" + +- name: init pki if missing + ansible.builtin.command: + cmd: /opt/easy-rsa/easyrsa --batch init-pki + creates: "{{ item.pki_dir }}/private" + environment: + EASYRSA_PKI: "{{ item.pki_dir }}" + loop: "{{ openvpn_instances }}" + +- name: build ca if missing + ansible.builtin.command: + cmd: /opt/easy-rsa/easyrsa --batch build-ca nopass + creates: "{{ item.pki_dir }}/ca.crt" + environment: + EASYRSA_PKI: "{{ item.pki_dir }}" + EASYRSA_REQ_CN: "CA-{{ item.name }}" + loop: "{{ openvpn_instances }}" + +- name: build server cert if missing + ansible.builtin.command: + cmd: /opt/easy-rsa/easyrsa --batch build-server-full server nopass + creates: "{{ item.pki_dir }}/issued/server.crt" + environment: + EASYRSA_PKI: "{{ item.pki_dir }}" + loop: "{{ openvpn_instances }}" + +- name: generate dh params if missing + ansible.builtin.command: + cmd: /opt/easy-rsa/easyrsa gen-dh + creates: "{{ item.pki_dir }}/dh.pem" + environment: + EASYRSA_PKI: "{{ item.pki_dir }}" + loop: "{{ openvpn_instances }}" + +- name: check client certificates validity + ansible.builtin.command: + cmd: "openssl x509 -checkend 2592000 -in {{ item.pki_dir }}/issued/{{ item.client.name }}.crt" + register: cert_check + failed_when: false + changed_when: false + loop: "{{ cert_list }}" + +- name: remove old cert file before reissue + ansible.builtin.file: + path: "{{ item.item.pki_dir }}/issued/{{ item.item.client.name }}.crt" + state: absent + loop: "{{ cert_check.results }}" + when: item.rc != 0 + +- name: remove old req file before reissue + ansible.builtin.file: + path: "{{ item.item.pki_dir }}/reqs/{{ item.item.client.name }}.req" + state: absent + loop: "{{ cert_check.results }}" + when: item.rc != 0 + +- name: remove old key file before reissue + ansible.builtin.file: + path: "{{ item.item.pki_dir }}/private/{{ item.item.client.name }}.key" + state: absent + loop: "{{ cert_check.results }}" + when: item.rc != 0 + +- name: issue or renew client certificates + ansible.builtin.command: + cmd: /opt/easy-rsa/easyrsa --batch build-client-full "{{ item.item.client.name }}" nopass + environment: + EASYRSA_PKI: "{{ item.item.pki_dir }}" + when: item.rc != 0 + loop: "{{ cert_check.results }}" + +- name: ensure local output directory exists + ansible.builtin.file: + path: "{{ openvpn_client_bundle_dir }}/{{ item.0.name }}" + state: directory + mode: '0700' + loop: "{{ openvpn_instances | subelements('clients') }}" + delegate_to: localhost + become: false + +- name: render standalone client bundles + ansible.builtin.template: + src: "{{ role_path }}/templates/client-certs/{{ item.0.name }}.conf.j2" + dest: "{{ openvpn_client_bundle_dir }}/{{ item.0.name }}/{{ item.1.name }}.ovpn" + mode: '0600' + loop: "{{ openvpn_instances | subelements('clients') }}" + delegate_to: localhost + become: false diff --git a/roles/easy-rsa/templates/client-certs/tap0.conf.j2 b/roles/easy-rsa/templates/client-certs/tap0.conf.j2 new file mode 100644 index 0000000..1c16be1 --- /dev/null +++ b/roles/easy-rsa/templates/client-certs/tap0.conf.j2 @@ -0,0 +1,26 @@ +client +dev tap0 +proto tcp +remote 127.0.0.1 1195 +resolv-retry infinite +nobind +persist-key +persist-tun +remote-cert-tls server +auth SHA256 +cipher AES-256-GCM +verb 3 +{% if item.1.ip is defined %} +route-metric {{ item.1.route_metric | default(50) }} +script-security 2 +up "C:\\Windows\\System32\\netsh.exe interface ip set address name="OpenVPN TAP-Windows6" static {{ item.1.ip }} 255.255.255.0" +{% endif %} + +{{ lookup('file', item.0.pki_dir + '/ca.crt') }} + + +{{ lookup('file', item.0.pki_dir + '/issued/' + item.1.name + '.crt') }} + + +{{ lookup('file', item.0.pki_dir + '/private/' + item.1.name + '.key') }} + diff --git a/roles/easy-rsa/templates/client-certs/tun0.conf.j2 b/roles/easy-rsa/templates/client-certs/tun0.conf.j2 new file mode 100644 index 0000000..63beee8 --- /dev/null +++ b/roles/easy-rsa/templates/client-certs/tun0.conf.j2 @@ -0,0 +1,21 @@ +client +dev tun0 +proto tcp +remote 127.0.0.1 1194 +resolv-retry infinite +nobind +persist-key +persist-tun +remote-cert-tls server +auth SHA256 +cipher AES-256-GCM +verb 3 + +{{ lookup('file', item.0.pki_dir + '/ca.crt') }} + + +{{ lookup('file', item.0.pki_dir + '/issued/' + item.1.name + '.crt') }} + + +{{ lookup('file', item.0.pki_dir + '/private/' + item.1.name + '.key') }} + diff --git a/roles/gitea/files/gitea.service b/roles/gitea/files/gitea.service new file mode 100644 index 0000000..686ac21 --- /dev/null +++ b/roles/gitea/files/gitea.service @@ -0,0 +1,17 @@ +[Unit] +Description=Gitea (Git with a cup of tea) +After=network.target + +[Service] +LimitNOFILE=524288:524288 +RestartSec=2s +Type=simple +User=git +Group=git +WorkingDirectory=/var/lib/gitea/ +ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini +Restart=always +Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea + +[Install] +WantedBy=multi-user.target diff --git a/roles/gitea/handlers/main.yml b/roles/gitea/handlers/main.yml new file mode 100644 index 0000000..e57d3d3 --- /dev/null +++ b/roles/gitea/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart gitea + ansible.builtin.systemd: + name: gitea + state: restarted + enabled: true + daemon_reload: true diff --git a/roles/gitea/tasks/main.yml b/roles/gitea/tasks/main.yml new file mode 100644 index 0000000..84922be --- /dev/null +++ b/roles/gitea/tasks/main.yml @@ -0,0 +1,123 @@ +--- +- name: create git group + ansible.builtin.group: + name: git + system: true + state: present + +- name: create git user + ansible.builtin.user: + name: git + group: git + system: true + shell: /bin/bash + home: /home/git + create_home: true + comment: "Git Version Control" + state: present + +- name: install git + ansible.builtin.apt: + name: git + state: latest + update_cache: true + +- name: get latest gitea release info + ansible.builtin.uri: + url: https://api.github.com/repos/go-gitea/gitea/releases/latest + return_content: true + headers: + Accept: "application/vnd.github+json" + register: gitea_latest_release + run_once: true + delegate_to: localhost + vars: + ansible_connection: local + failed_when: false + +- name: set gitea version fact + ansible.builtin.set_fact: + gitea_version: "{{ gitea_latest_release.json.tag_name | regex_replace('^v', '') }}" + when: + - gitea_latest_release is succeeded + - gitea_latest_release.json is defined + - gitea_latest_release.json.tag_name is defined + +- name: ensure gitea directory exists + ansible.builtin.file: + path: /etc/gitea + state: directory + owner: git + group: root + mode: 0750 + +- name: download gitea sha256 checksum + ansible.builtin.uri: + url: "https://dl.gitea.com/gitea/{{ gitea_version }}/gitea-{{ gitea_version }}-linux-amd64.sha256" + return_content: true + register: gitea_checksum + failed_when: false + +- name: download gitea binary + ansible.builtin.get_url: + url: "https://dl.gitea.com/gitea/{{ gitea_version }}/gitea-{{ gitea_version }}-linux-amd64" + dest: /usr/local/bin/gitea + mode: '0755' + owner: root + group: root + checksum: "{{ ('sha256:' ~ gitea_checksum.content.split()[0]) if gitea_checksum is succeeded and gitea_checksum.content is defined else omit }}" + notify: restart gitea + +- name: deploy gitea config + ansible.builtin.template: + src: "{{ inventory_hostname }}/app.ini.j2" + dest: "/etc/gitea/app.ini" + owner: root + group: git + mode: '0640' + notify: restart gitea + +- name: deploy gitea systemd unit + ansible.builtin.copy: + src: gitea.service + dest: /etc/systemd/system/gitea.service + owner: root + group: root + mode: '0644' + notify: restart gitea + +- name: check if gitea data directory is a mountpoint + ansible.builtin.command: mountpoint -q /var/lib/gitea + register: vw_mountpoint + failed_when: false + changed_when: false + +- name: remove default gitea data directory + ansible.builtin.file: + path: /var/lib/gitea + state: absent + when: vw_mountpoint.rc != 0 + +- name: ensure gitea data directory exists + ansible.builtin.file: + path: /mnt/gitea/data + state: directory + owner: git + group: git + mode: "0755" + +- name: bind mount gitea data directory + ansible.posix.mount: + path: /var/lib/gitea + src: /mnt/gitea/data + fstype: none + opts: bind + state: mounted + notify: restart gitea + +- name: set ownership on gitea data directory + ansible.builtin.file: + path: /mnt/gitea/data + owner: git + group: git + recurse: true diff --git a/roles/gitea/templates/gitea/app.ini.j2 b/roles/gitea/templates/gitea/app.ini.j2 new file mode 100644 index 0000000..5ef0e90 --- /dev/null +++ b/roles/gitea/templates/gitea/app.ini.j2 @@ -0,0 +1,76 @@ +APP_NAME = Gitea: Git with a cup of tea +RUN_USER = git +WORK_PATH = /var/lib/gitea +RUN_MODE = prod + +[database] +DB_TYPE = postgres +HOST = {{ hostvars['pgsql'].ip }}:5432 +NAME = gitea +USER = gitea_user +PASSWD = `{{ database_password }}` +SCHEMA = public +SSL_MODE = disable +PATH = /var/lib/gitea/data/gitea.db +LOG_SQL = false + +[repository] +ROOT = /var/lib/gitea/data/gitea-repositories + +[server] +SSH_DOMAIN = gitea.lan +DOMAIN = gitea.oyacoi.ru +HTTP_PORT = 3000 +ROOT_URL = http://gitea.oyacoi.ru/ +APP_DATA_PATH = /var/lib/gitea/data +DISABLE_SSH = false +SSH_PORT = 22 +LFS_START_SERVER = true +LFS_JWT_SECRET = {{ lfs_jwt_secret }} + +[lfs] +PATH = /var/lib/gitea/data/lfs + +[mailer] +ENABLED = false + +[service] +REGISTER_EMAIL_CONFIRM = false +ENABLE_NOTIFY_MAIL = false +DISABLE_REGISTRATION = true +ALLOW_ONLY_EXTERNAL_REGISTRATION = false +ENABLE_CAPTCHA = false +REQUIRE_SIGNIN_VIEW = false +DEFAULT_KEEP_EMAIL_PRIVATE = false +DEFAULT_ALLOW_CREATE_ORGANIZATION = true +DEFAULT_ENABLE_TIMETRACKING = true +NO_REPLY_ADDRESS = noreply.localhost + +[openid] +ENABLE_OPENID_SIGNIN = false +ENABLE_OPENID_SIGNUP = false + +[cron.update_checker] +ENABLED = false + +[session] +PROVIDER = file + +[log] +MODE = console +LEVEL = info +ROOT_PATH = /var/lib/gitea/log + +[repository.pull-request] +DEFAULT_MERGE_STYLE = merge + +[repository.signing] +DEFAULT_TRUST_MODEL = committer + +[security] +INSTALL_LOCK = true +INTERNAL_TOKEN = {{ internal_token }} +PASSWORD_HASH_ALGO = pbkdf2 + +[oauth2] +JWT_SECRET = {{ jwt_secret }} diff --git a/roles/haproxy/handlers/main.yml b/roles/haproxy/handlers/main.yml new file mode 100644 index 0000000..ebc484f --- /dev/null +++ b/roles/haproxy/handlers/main.yml @@ -0,0 +1,13 @@ +--- +- name: validate haproxy config + ansible.builtin.command: haproxy -c -f /etc/haproxy/haproxy.cfg + changed_when: false + listen: restart haproxy + +- name: restart haproxy systemd service unit + ansible.builtin.systemd_service: + name: haproxy + state: restarted + enabled: true + daemon_reload: true + listen: restart haproxy diff --git a/roles/haproxy/tasks/main.yml b/roles/haproxy/tasks/main.yml new file mode 100644 index 0000000..1fe68de --- /dev/null +++ b/roles/haproxy/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- name: install haproxy + ansible.builtin.apt: + name: haproxy + state: latest + update_cache: true + notify: restart haproxy + +- name: deploy haproxy config + ansible.builtin.template: + src: "{{ inventory_hostname }}/haproxy.cfg.j2" + dest: "/etc/haproxy/haproxy.cfg" + owner: root + group: root + mode: "0644" + loop: "{{ query('fileglob', role_path + '/templates/' + inventory_hostname + '/*.cfg.j2') }}" + notify: restart haproxy diff --git a/roles/haproxy/templates/liqueur/haproxy.cfg.j2 b/roles/haproxy/templates/liqueur/haproxy.cfg.j2 new file mode 100644 index 0000000..461012e --- /dev/null +++ b/roles/haproxy/templates/liqueur/haproxy.cfg.j2 @@ -0,0 +1,85 @@ +global + log /dev/log local2 + chroot /var/lib/haproxy + maxconn 4000 + user haproxy + group haproxy + daemon + stats socket /var/lib/haproxy/stats mode 660 level admin + +defaults + log global + mode tcp + option tcplog + option dontlognull + retries 3 + timeout connect 5s + timeout client 1h + timeout server 1h + timeout check 10s + +frontend http_frontend + bind 127.0.0.1:10080 accept-proxy + mode http + option httplog + acl host_dttx hdr_end(host) -m end dttx.ru + use_backend dttx_http_srv if host_dttx + default_backend oyacoi_http_srv + +backend oyacoi_http_srv + mode http + server oyacoi_srv {{ hostvars['nginx']['ip'] }}:81 send-proxy-v2 + +backend dttx_http_srv + mode http + server dttx_srv {{ hostvars['rbpi4']['ip'] }}:81 send-proxy-v2 + +frontend https_frontend + bind 127.0.0.1:10443 accept-proxy + mode tcp + option tcplog + tcp-request inspect-delay 5s + tcp-request content accept if { req_ssl_hello_type 1 } + acl host_dttx req_ssl_sni -m end dttx.ru + acl host_telemt req_ssl_sni -m end regionculture.ru + use_backend dttx_https_srv if host_dttx + use_backend telemt_https_srv if host_telemt + default_backend oyacoi_https_srv + +backend oyacoi_https_srv + mode tcp + server nginx_srv {{ hostvars['nginx']['ip'] }}:444 send-proxy-v2 + +backend dttx_https_srv + mode tcp + server dttx_srv {{ hostvars['rbpi4']['ip'] }}:444 send-proxy-v2 + +backend telemt_https_srv + mode tcp + option tcp-check + server telemt_srv {{ hostvars['vector']['ip'] }}:443 check + server telemt_srv_backup {{ hostvars['dev']['ip'] }}:443 check backup + +listen xmpp_c2s + bind {{ hostvars['liqueur']['ip'] }}:5222 + server prosody_srv {{ hostvars['prosody']['ip'] }}:5222 + +listen xmpp_legacy_ssl + bind {{ hostvars['liqueur']['ip'] }}:5223 + server prosody_srv {{ hostvars['prosody']['ip'] }}:5223 + +listen xmpp_s2s + bind {{ hostvars['liqueur']['ip'] }}:5269 + server prosody_srv {{ hostvars['prosody']['ip'] }}:5269 + +listen prosody_proxy65 + bind {{ hostvars['liqueur']['ip'] }}:5000 + server prosody_srv {{ hostvars['prosody']['ip'] }}:5000 + +listen prosody_components + bind {{ hostvars['liqueur']['ip'] }}:5270 + server prosody_srv {{ hostvars['prosody']['ip'] }}:5270 + +listen prosody_bosh_http + bind {{ hostvars['liqueur']['ip'] }}:5280 + server prosody_srv {{ hostvars['prosody']['ip'] }}:5280 diff --git a/roles/hostname/tasks/main.yml b/roles/hostname/tasks/main.yml new file mode 100644 index 0000000..5fab7ab --- /dev/null +++ b/roles/hostname/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- name: set hostname + ansible.builtin.hostname: + name: "{{ hostname }}" diff --git a/roles/ifupdown2/files/router/interfaces b/roles/ifupdown2/files/router/interfaces new file mode 100644 index 0000000..39baf10 --- /dev/null +++ b/roles/ifupdown2/files/router/interfaces @@ -0,0 +1,50 @@ +auto lo +iface lo inet loopback + post-up ip rule add fwmark 0x1 lookup 100 2>/dev/null || true + post-up ip route add local 0.0.0.0/0 dev lo table 100 2>/dev/null || true + pre-down ip route del local 0.0.0.0/0 dev lo table 100 2>/dev/null || true + pre-down ip rule del fwmark 0x1 lookup 100 2>/dev/null || true + +auto br-eth0 +iface br-eth0 inet static + address 10.1.0.1/24 + bridge_ports eth0 tap0 + bridge_stp off + pre-up ip tuntap add dev tap0 mode tap || true + post-down ip tuntap del dev tap0 mode tap || true + +auto eth0 +iface eth0 inet manual + +auto eth0.2 +iface eth0.2 inet static + address 10.2.0.1/24 + vlan-raw-device eth0 + +auto eth0.3 +iface eth0.3 inet static + address 10.3.0.1/24 + vlan-raw-device eth0 + +auto eth0.4 +iface eth0.4 inet static + address 10.4.0.1/24 + vlan-raw-device eth0 + +auto eth0.10 +iface eth0.10 inet static + address 10.10.0.1/24 + vlan-raw-device eth0 + +auto eth0.11 +iface eth0.11 inet static + address 10.11.0.1/24 + vlan-raw-device eth0 + +auto eth0.12 +iface eth0.12 inet static + address 10.12.0.1/24 + vlan-raw-device eth0 + +auto eth1 +iface eth1 inet dhcp diff --git a/roles/ifupdown2/tasks/main.yml b/roles/ifupdown2/tasks/main.yml new file mode 100644 index 0000000..d726bbc --- /dev/null +++ b/roles/ifupdown2/tasks/main.yml @@ -0,0 +1,33 @@ +--- +- name: ensure rt_tables.d directory exists + ansible.builtin.file: + path: /etc/iproute2/rt_tables.d + state: directory + mode: "0755" + register: rt_tables_dir + +- name: deploy ifupdown interfaces + ansible.builtin.copy: + src: "{{ inventory_hostname }}/interfaces" + dest: /etc/network/interfaces + owner: root + group: root + mode: "0644" + register: interfaces_conf + +- name: reload ifupdown2 + command: ifreload -a + when: interfaces_conf.changed + +- name: install bridge-utils + ansible.builtin.package: + name: bridge-utils + state: present + register: bridge_utils_install + when: (ifupdown2_need_bridge_utils | default(false)) == true + +- name: reload ifupdown2 + ansible.builtin.command: ifreload -a + when: + - bridge_utils_install.changed or rt_tables_dir.changed + - ifupdown2_need_bridge_utils | default(false) diff --git a/roles/lampa/handlers/main.yml b/roles/lampa/handlers/main.yml new file mode 100644 index 0000000..c43229e --- /dev/null +++ b/roles/lampa/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart lampa + ansible.builtin.systemd: + name: lampac + state: restarted + enabled: true + daemon_reload: true diff --git a/roles/lampa/tasks/main.yml b/roles/lampa/tasks/main.yml new file mode 100644 index 0000000..a7bb574 --- /dev/null +++ b/roles/lampa/tasks/main.yml @@ -0,0 +1,108 @@ +--- +- name: install dependencies + ansible.builtin.apt: + name: + - curl + - sudo + state: present + update_cache: true + +- name: get latest lampac release info + ansible.builtin.uri: + url: https://api.github.com/repos/lampac-nextgen/lampac/releases/latest + return_content: true + register: lampa_release + check_mode: false + +- name: set latest lampac version + ansible.builtin.set_fact: + lampa_version: "{{ lampa_release.json.tag_name | regex_replace('^v', '') }}" + +- name: download lampac installer + ansible.builtin.get_url: + url: https://raw.githubusercontent.com/lampac-nextgen/lampac/main/install.sh + dest: /usr/local/sbin/lampac-install.sh + owner: root + group: root + mode: "0755" + force: true + +- name: check lampac installed version + ansible.builtin.shell: > + /usr/local/sbin/lampac-install.sh --version | grep -oP 'Installed Version:\s*\K[\d.]+' + args: + executable: /bin/bash + register: lampa_current_version + changed_when: false + failed_when: false + check_mode: false + +- name: set lampac installed version + ansible.builtin.set_fact: + lampa_installed_version: "{{ lampa_current_version.stdout | trim }}" + +- name: display lampac version info + ansible.builtin.debug: + msg: "latest: {{ lampa_version }}, installed: {{ lampa_installed_version | default('not installed', true) }}" + +- name: install lampac + ansible.builtin.command: /usr/local/sbin/lampac-install.sh --tag v{{ lampa_version }} + when: lampa_installed_version == '' + +- name: update lampac + ansible.builtin.command: /usr/local/sbin/lampac-install.sh --update --force --tag v{{ lampa_version }} + when: + - lampa_installed_version != '' + - lampa_installed_version is version(lampa_version, '<') + notify: restart lampa + +- name: ensure lampa database directory is a mountpoint + ansible.builtin.command: mountpoint -q /opt/lampac/database + register: vw_mountpoint + failed_when: false + changed_when: false + +- name: stop lampa before relocating database + ansible.builtin.systemd: + name: lampac + state: stopped + when: vw_mountpoint.rc != 0 + +- name: remove default lampa database directory + ansible.builtin.file: + path: /opt/lampac/database + state: absent + when: vw_mountpoint.rc != 0 + +- name: ensure lampa database source directory exists + ansible.builtin.file: + path: /mnt/lampa/database + state: directory + owner: lampac + group: lampac + mode: "0755" + +- name: bind mount lampa database directory + ansible.posix.mount: + path: /opt/lampac/database + src: /mnt/lampa/database/ + fstype: none + opts: bind + state: mounted + notify: restart lampa + +- name: set lampa database directory ownership + ansible.builtin.file: + path: /mnt/lampa/database + owner: lampac + group: lampac + recurse: true + +- name: deploy lampac config + ansible.builtin.template: + src: "{{ inventory_hostname }}/init.conf.j2" + dest: /opt/lampac/init.conf + owner: lampac + group: lampac + mode: "0640" + notify: restart lampa diff --git a/roles/lampa/templates/lampa/init.conf.j2 b/roles/lampa/templates/lampa/init.conf.j2 new file mode 100644 index 0000000..679871e --- /dev/null +++ b/roles/lampa/templates/lampa/init.conf.j2 @@ -0,0 +1,23 @@ +{ + "lowMemoryMode": true, + "listen": { "ip": "any", "port": 9118, "version": true }, + "BaseModule": { + "LoadModules": ["LampaWeb", "Sync", "TimeCode", "Storage", "SyncEvents"] + }, + "chromium": { "enable": false }, + "firefox": { "enable": false }, + "rch": { "enable": false }, + "LampaWeb": { + "initPlugins": { + "online": false, + "sisi": false, + "torrserver": false, + "jacred": false, + "tmdbProxy": false, + "cubProxy": false, + "sync": true, + "bookmark": false, + "timecode": false + } + } +} diff --git a/roles/locales/tasks/main.yml b/roles/locales/tasks/main.yml new file mode 100644 index 0000000..211dfdd --- /dev/null +++ b/roles/locales/tasks/main.yml @@ -0,0 +1,14 @@ +--- +- name: generate locales + community.general.locale_gen: + name: "{{ item }}" + state: present + loop: "{{ locales_list }}" + +- name: configure default locale + ansible.builtin.copy: + dest: /etc/locale.conf + content: LANG={{ locale_default }} + owner: root + group: root + mode: "0644" diff --git a/roles/logrotate/files/dev/xraycore b/roles/logrotate/files/dev/xraycore new file mode 100644 index 0000000..4775ebb --- /dev/null +++ b/roles/logrotate/files/dev/xraycore @@ -0,0 +1,9 @@ +/var/log/xray-core/*.log { + daily + rotate 4 + compress + delaycompress + missingok + notifempty + copytruncate +} diff --git a/roles/logrotate/files/dev_shin/xraycore b/roles/logrotate/files/dev_shin/xraycore new file mode 100644 index 0000000..4775ebb --- /dev/null +++ b/roles/logrotate/files/dev_shin/xraycore @@ -0,0 +1,9 @@ +/var/log/xray-core/*.log { + daily + rotate 4 + compress + delaycompress + missingok + notifempty + copytruncate +} diff --git a/roles/logrotate/files/router/xraycore b/roles/logrotate/files/router/xraycore new file mode 100644 index 0000000..4775ebb --- /dev/null +++ b/roles/logrotate/files/router/xraycore @@ -0,0 +1,9 @@ +/var/log/xray-core/*.log { + daily + rotate 4 + compress + delaycompress + missingok + notifempty + copytruncate +} diff --git a/roles/logrotate/files/vector/xraycore b/roles/logrotate/files/vector/xraycore new file mode 100644 index 0000000..4775ebb --- /dev/null +++ b/roles/logrotate/files/vector/xraycore @@ -0,0 +1,9 @@ +/var/log/xray-core/*.log { + daily + rotate 4 + compress + delaycompress + missingok + notifempty + copytruncate +} diff --git a/roles/logrotate/tasks/main.yml b/roles/logrotate/tasks/main.yml new file mode 100644 index 0000000..40e6db9 --- /dev/null +++ b/roles/logrotate/tasks/main.yml @@ -0,0 +1,9 @@ +--- +- name: deploy logrotate config + ansible.builtin.copy: + src: "{{ item }}" + dest: "/etc/logrotate.d/{{ item | basename }}" + owner: root + group: root + mode: "0644" + loop: "{{ query('ansible.builtin.fileglob', role_path + '/files/' + inventory_hostname + '/*') }}" diff --git a/roles/netutils/tasks/main.yml b/roles/netutils/tasks/main.yml new file mode 100644 index 0000000..b41562d --- /dev/null +++ b/roles/netutils/tasks/main.yml @@ -0,0 +1,15 @@ +--- +- name: install network tools + ansible.builtin.apt: + name: + - tcpdump + - iperf3 + - mtr-tiny + - bind9-dnsutils + - ethtool + - conntrack + - iftop + - socat + - nmap + state: latest + update_cache: true diff --git a/roles/nfs/handlers/main.yml b/roles/nfs/handlers/main.yml new file mode 100644 index 0000000..a9c8959 --- /dev/null +++ b/roles/nfs/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart nfs + ansible.builtin.service: + name: nfs-kernel-server + state: restarted + enabled: true diff --git a/roles/nfs/tasks/main.yml b/roles/nfs/tasks/main.yml new file mode 100644 index 0000000..df33a4f --- /dev/null +++ b/roles/nfs/tasks/main.yml @@ -0,0 +1,31 @@ +--- +- name: install nfs-kernel-server + ansible.builtin.apt: + name: nfs-kernel-server + state: latest + update_cache: true + notify: restart nfs + +- name: deploy exports + ansible.builtin.template: + src: "{{ inventory_hostname }}/exports" + dest: /etc/exports + mode: "0755" + notify: restart nfs + +- name: disable nfs3 + community.general.ini_file: + path: /etc/nfs.conf + section: nfsd + option: "{{ item.key }}" + value: "{{ item.value }}" + no_extra_spaces: true + mode: 0755 + backup: true + loop: + - { key: vers3, value: "n" } + - { key: vers4, value: "y" } + - { key: "vers4.0", value: "y" } + - { key: "vers4.1", value: "y" } + - { key: "vers4.2", value: "y" } + notify: restart nfs diff --git a/roles/nfs/templates/nfs/exports b/roles/nfs/templates/nfs/exports new file mode 100644 index 0000000..ddd8975 --- /dev/null +++ b/roles/nfs/templates/nfs/exports @@ -0,0 +1,2 @@ +/mnt/media1 10.1.0.0/24(rw,sync,no_subtree_check,all_squash,anonuid=100000,anongid=101000) +/mnt/media2 10.1.0.0/24(rw,sync,no_subtree_check,all_squash,anonuid=100000,anongid=101000) diff --git a/roles/nftables/handlers/main.yml b/roles/nftables/handlers/main.yml new file mode 100644 index 0000000..49b2239 --- /dev/null +++ b/roles/nftables/handlers/main.yml @@ -0,0 +1,18 @@ +--- +- name: check nftables config + ansible.builtin.command: nft -c -f /etc/nftables.conf + changed_when: false + listen: restart nftables + +- name: enable and start nftables + ansible.builtin.systemd: + name: nftables + state: started + enabled: true + listen: restart nftables + +- name: reload nftables + ansible.builtin.systemd: + name: nftables + state: reloaded + listen: restart nftables diff --git a/roles/nftables/tasks/main.yml b/roles/nftables/tasks/main.yml new file mode 100644 index 0000000..7927c12 --- /dev/null +++ b/roles/nftables/tasks/main.yml @@ -0,0 +1,41 @@ +--- +- name: install nftables + ansible.builtin.apt: + name: nftables + state: latest + update_cache: true + +- name: ensure nftables.d directory exists + ansible.builtin.file: + path: /etc/nftables.d + state: directory + mode: "0755" + when: nftables_bootstrap_files | default([]) | length > 0 + +- name: bootstrap empty config files + ansible.builtin.copy: + dest: "/etc/nftables.d/{{ item }}" + content: "" + force: false + mode: "0644" + loop: "{{ nftables_bootstrap_files | default([]) }}" + +- name: deploy nftables rules + ansible.builtin.template: + src: "{{ item }}" + dest: "/etc/nftables.d/{{ item | basename | regex_replace('\\.j2$', '') }}" + owner: root + group: root + mode: '0644' + loop: "{{ query('ansible.builtin.fileglob', role_path + '/templates/' + inventory_hostname + '/*.nft.j2') }}" + notify: restart nftables + +- name: deploy nftables config + ansible.builtin.template: + src: "{{ item }}" + dest: "/etc/{{ item | basename | regex_replace('\\.j2$', '') }}" + owner: root + group: root + mode: "0644" + loop: "{{ query('ansible.builtin.fileglob', role_path + '/templates/' + inventory_hostname + '/*.conf.j2') }}" + notify: restart nftables diff --git a/roles/nftables/templates/dev/nftables.conf.j2 b/roles/nftables/templates/dev/nftables.conf.j2 new file mode 100644 index 0000000..f5a4622 --- /dev/null +++ b/roles/nftables/templates/dev/nftables.conf.j2 @@ -0,0 +1,22 @@ +#!/usr/sbin/nft -f +flush ruleset +table inet filter { + chain input { + type filter hook input priority filter; + policy drop; + iif "lo" accept + ct state established,related accept + ct state invalid drop + tcp dport 22 counter accept comment "ssh" + tcp dport 80 counter accept comment "http" + tcp dport 443 counter accept comment "https" + } + chain forward { + type filter hook forward priority filter; + policy drop; + } + chain output { + type filter hook output priority filter; + policy accept; + } +} diff --git a/roles/nftables/templates/dev_shin/nftables.conf.j2 b/roles/nftables/templates/dev_shin/nftables.conf.j2 new file mode 100644 index 0000000..f5a4622 --- /dev/null +++ b/roles/nftables/templates/dev_shin/nftables.conf.j2 @@ -0,0 +1,22 @@ +#!/usr/sbin/nft -f +flush ruleset +table inet filter { + chain input { + type filter hook input priority filter; + policy drop; + iif "lo" accept + ct state established,related accept + ct state invalid drop + tcp dport 22 counter accept comment "ssh" + tcp dport 80 counter accept comment "http" + tcp dport 443 counter accept comment "https" + } + chain forward { + type filter hook forward priority filter; + policy drop; + } + chain output { + type filter hook output priority filter; + policy accept; + } +} diff --git a/roles/nftables/templates/liqueur/nftables.conf.j2 b/roles/nftables/templates/liqueur/nftables.conf.j2 new file mode 100644 index 0000000..78b703e --- /dev/null +++ b/roles/nftables/templates/liqueur/nftables.conf.j2 @@ -0,0 +1,50 @@ +#!/usr/sbin/nft -f +flush ruleset +table inet filter { + chain input { + type filter hook input priority filter; + policy drop; + iif "lo" accept + ct state established,related accept + ct state invalid drop + tcp dport 22 counter accept comment "ssh" + tcp dport 80 counter accept comment "http" + tcp dport 443 counter accept comment "https" + tcp dport { 5222, 5223, 5269, 5000, 5270, 5280 } counter accept comment "xmpp" + } + chain forward { + type filter hook forward priority filter; + policy drop; + ct state established,related accept + ip daddr {{ hostvars['coturn']['ip'] }} udp dport { 3478, 5349, 49152-65535 } counter accept + ip daddr {{ hostvars['coturn']['ip'] }} tcp dport { 3478, 5349 } counter accept + ip daddr {{ hostvars['valheim']['ip'] }} udp dport 2456 counter accept + ip daddr {{ hostvars['valheim']['ip'] }} udp dport 2457 counter accept + ip daddr {{ hostvars['rbpi4']['ip'] }} udp dport 21116 counter accept + ip daddr {{ hostvars['rbpi4']['ip'] }} tcp dport 21114-21119 counter accept + iifname tun0 ip saddr {{ hostvars['workuter']['ip'] }} oifname tun0 ip daddr {{ hostvars['xiawrt']['ip'] }} tcp dport 22 counter accept + iifname tun0 ip saddr {{ hostvars['workuter']['ip'] }} oifname tun0 ip daddr {{ hostvars['rbpi4']['ip'] }} tcp dport 22 counter accept + iifname tun0 ip saddr {{ hostvars['oyacoi-odcm']['ip'] }} oifname tun0 ip daddr {{ hostvars['xiawrt']['ip'] }} tcp dport 22 counter accept + iifname tun0 ip saddr {{ hostvars['oyacoi-odcm']['ip'] }} oifname tun0 ip daddr {{ hostvars['rbpi4']['ip'] }} tcp dport 22 counter accept + } + chain output { + type filter hook output priority filter; + policy accept; + } +} +table ip nat { + chain prerouting { + type nat hook prerouting priority dstnat; + policy accept; + ip daddr {{ ip }} udp dport { 3478, 5349, 49152-65535 } counter dnat to {{ hostvars['coturn']['ip'] }} + ip daddr {{ ip }} tcp dport { 3478, 5349 } counter dnat to {{ hostvars['coturn']['ip'] }} + ip daddr {{ ip }} udp dport 2456 counter dnat to {{ hostvars['valheim']['ip'] }} + ip daddr {{ ip }} udp dport 2457 counter dnat to {{ hostvars['valheim']['ip'] }} + ip daddr {{ ip }} udp dport 21116 counter dnat to {{ hostvars['rbpi4']['ip'] }} + ip daddr {{ ip }} tcp dport 21114-21119 counter dnat to {{ hostvars['rbpi4']['ip'] }} + } + chain postrouting { + type nat hook postrouting priority srcnat; + policy accept; + } +} diff --git a/roles/nftables/templates/router/10-sets.nft.j2 b/roles/nftables/templates/router/10-sets.nft.j2 new file mode 100644 index 0000000..761f079 --- /dev/null +++ b/roles/nftables/templates/router/10-sets.nft.j2 @@ -0,0 +1,6 @@ +set private_ip { + type ipv4_addr + flags interval + auto-merge + elements = { 10.0.0.0/8, 100.64.0.0/10, 127.0.0.0/8, 169.254.0.0/16, 172.16.0.0/12, 192.0.0.0/24, 192.0.2.0/24, 192.88.99.0/24, 192.168.0.0/16, 198.18.0.0/15, 198.51.100.0/24, 203.0.113.0/24, 224.0.0.0/4, 240.0.0.0/4 } +} diff --git a/roles/nftables/templates/router/20-sets.nft.j2 b/roles/nftables/templates/router/20-sets.nft.j2 new file mode 100644 index 0000000..d9c9e96 --- /dev/null +++ b/roles/nftables/templates/router/20-sets.nft.j2 @@ -0,0 +1,15 @@ +#jinja2: trim_blocks: True, lstrip_blocks: True +{%- for id, item in xray_ip_sets.items() -%} +set {{ id }}_ip { + type ipv4_addr + flags interval + auto-merge + include "{{ xray_lists_global.output_dir }}/{{ id }}_ip.elements.nft" +} +{% endfor -%} +{%- for id, item in xray_domain_sets.items() -%} +set {{ id }}_dom { + type ipv4_addr + flags interval +} +{% endfor -%} diff --git a/roles/nftables/templates/router/30-nat.nft.j2 b/roles/nftables/templates/router/30-nat.nft.j2 new file mode 100644 index 0000000..eb7623c --- /dev/null +++ b/roles/nftables/templates/router/30-nat.nft.j2 @@ -0,0 +1,8 @@ +chain postrouting { + type nat hook postrouting priority srcnat; policy accept; + oifname eth1 masquerade +} +chain prerouting { + type nat hook prerouting priority dstnat; policy accept; + include "/etc/nftables.d/90-dstnat.nft" +} diff --git a/roles/nftables/templates/router/35-mangle.nft.j2 b/roles/nftables/templates/router/35-mangle.nft.j2 new file mode 100644 index 0000000..7d034c5 --- /dev/null +++ b/roles/nftables/templates/router/35-mangle.nft.j2 @@ -0,0 +1,5 @@ +chain prerouting { + type filter hook prerouting priority -150; policy accept; + iifname "tun0" ct mark set 0x2 comment "tun0 -> mart 0x2" + iifname != { "tun0", "lo" } ct mark 0x2 meta mark set ct mark comment "mark 0x2 -> tun0" +} diff --git a/roles/nftables/templates/router/40-filter.nft.j2 b/roles/nftables/templates/router/40-filter.nft.j2 new file mode 100644 index 0000000..4447a98 --- /dev/null +++ b/roles/nftables/templates/router/40-filter.nft.j2 @@ -0,0 +1,34 @@ +flowtable ft { + hook ingress priority filter + devices = { eth0, eth1 } +} +chain input { + type filter hook input priority filter; policy drop; + ct state established,related accept + ct state invalid drop + iif lo accept + meta mark 0x00000001 accept + iifname br-eth0 tcp dport 22 accept + iifname eth0.11 tcp dport 22 accept + iifname tun0 tcp dport 22 accept + iifname { br-eth0, eth0.2, eth0.3, eth0.4, eth0.10, eth0.11, eth0.12 } tcp dport 61219 accept + iifname { br-eth0, eth0.2, eth0.3, eth0.4, eth0.10, eth0.11, eth0.12 } udp dport 61219 accept + iifname { br-eth0, eth0.2, eth0.3, eth0.4, eth0.10, eth0.11, eth0.12 } udp dport 53 accept + iifname { br-eth0, eth0.2, eth0.3, eth0.4, eth0.10, eth0.11, eth0.12 } tcp dport 53 accept + iifname eth0.3 udp dport 67 accept + iifname eth1 udp dport 68 accept + include "/etc/nftables.d/90-input.nft" +} +chain forward { + type filter hook forward priority filter; policy drop; + ct state established,related accept + ct state invalid drop + iifname { br-eth0, eth0.2, eth0.3, eth0.4, eth0.10, eth0.11, eth0.12 } oifname eth1 ct state new flow add @ft + iifname { br-eth0, eth0.2, eth0.3, eth0.4, eth0.10, eth0.11, eth0.12 } oifname eth1 accept + tcp flags syn tcp option maxseg size set rt mtu + include "/etc/nftables.d/90-forward.nft" +} +chain output { + type route hook output priority filter; policy accept; + include "/etc/nftables.d/90-output.nft" +} diff --git a/roles/nftables/templates/router/50-proxy.nft.j2 b/roles/nftables/templates/router/50-proxy.nft.j2 new file mode 100644 index 0000000..4d6e794 --- /dev/null +++ b/roles/nftables/templates/router/50-proxy.nft.j2 @@ -0,0 +1,11 @@ +chain proxy_prerouting { + type filter hook prerouting priority filter - 50; policy accept; + fib daddr type local accept + meta mark 0x00000001 iif "lo" meta l4proto { tcp, udp } tproxy ip to :61219 counter accept + include "/etc/nftables.d/90-proxy-prerouting.nft" +} +chain proxy_output { + type route hook output priority mangle; policy accept; + meta mark != 0 return + include "/etc/nftables.d/90-proxy-output.nft" +} diff --git a/roles/nftables/templates/router/90-dstnat.nft.j2 b/roles/nftables/templates/router/90-dstnat.nft.j2 new file mode 100644 index 0000000..e5f9a58 --- /dev/null +++ b/roles/nftables/templates/router/90-dstnat.nft.j2 @@ -0,0 +1,19 @@ +#jinja2: trim_blocks: True, lstrip_blocks: True +{% for item in nft_managed_group | sort %} +{% set client = hostvars[item] %} +{% if 'nft_dst' in client and client.nft_dst is not none %} +{% set target_ip = client.ip %} +{% for client in client.nft_dst %} +{% set ports = client.port if (client.port is iterable and client.port is not string) else [client.port] %} +{% set protos = client.proto if (client.proto is iterable and client.proto is not string) else [client.proto] %} +{% set ifaces = client.iface if (client.iface is iterable and client.iface is not string) else [client.iface] %} +{% for proto in protos %} +{% for port in ports %} +{% for iface in ifaces %} +iifname "{{ iface }}" {{ proto }} dport {{ port }} counter dnat ip to {{ target_ip }}:{{ port }} comment "{{ iface }} -> {{ item }}" +{% endfor %} +{% endfor %} +{% endfor %} +{% endfor %} +{% endif %} +{% endfor %} diff --git a/roles/nftables/templates/router/90-forward.nft.j2 b/roles/nftables/templates/router/90-forward.nft.j2 new file mode 100644 index 0000000..2c699b5 --- /dev/null +++ b/roles/nftables/templates/router/90-forward.nft.j2 @@ -0,0 +1,47 @@ +#jinja2: trim_blocks: True, lstrip_blocks: True +{% for item in nft_managed_group | sort %} +{% set client = hostvars[item] %} +{% if 'nft_to' in client and client.nft_to is not none %} +{% set rules = client.nft_to if (client.nft_to is iterable and client.nft_to is not string) else [client.nft_to] %} +{% for rule in rules %} +{% set rule = rule if rule is mapping else {'to': rule} %} +{% set dests = rule.to if (rule.to is iterable and rule.to is not string) else [rule.to] %} +{% set protos = rule.proto if (rule.proto is iterable and rule.proto is not string) else [rule.proto | default(none)] %} +{% set ports = rule.port if (rule.port is iterable and rule.port is not string) else [rule.port | default(none)] %} +{% for dest in dests %} +{% if dest.startswith('zone:') %} +{% set oif = dest.split(':')[1] %} +{% set daddr = none %} +{% set dest_name = oif %} +{% else %} +{% set oif = hostvars[dest].iface %} +{% set daddr = hostvars[dest].ip %} +{% set dest_name = dest %} +{% endif %} +{% for proto in protos %} +{% for port in ports %} +iifname "{{ client.iface }}" ip saddr {{ client.ip }} oifname "{{ oif }}" {% if daddr %}ip daddr {{ daddr }} {% endif %}{% if proto and port %}{{ proto }} dport {{ port }} {% endif %}counter accept comment "{{ item }} -> {{ dest_name }}" +{% endfor %} +{% endfor %} +{% endfor %} +{% endfor %} +{% endif %} +{% endfor %} +{% for item in nft_managed_group | sort %} +{% set client = hostvars[item] %} +{% if 'nft_from' in client and client.nft_from is not none %} +{% set rules = client.nft_from if (client.nft_from is iterable and client.nft_from is not string) else [client.nft_from] %} +{% for rule in rules %} +{% set ifaces = rule.iface if (rule.iface is iterable and rule.iface is not string) else [rule.iface] %} +{% set protos = rule.proto if (rule.proto is iterable and rule.proto is not string) else [rule.proto | default(none)] %} +{% set ports = rule.port if (rule.port is iterable and rule.port is not string) else [rule.port | default(none)] %} +{% for iface in ifaces %} +{% for proto in protos %} +{% for port in ports %} +iifname "{{ iface }}" oifname "{{ client.iface }}" ip daddr {{ client.ip }} {% if proto and port %}{{ proto }} dport {{ port }} {% endif %}counter accept comment "{{ iface }} -> {{ item }}" +{% endfor %} +{% endfor %} +{% endfor %} +{% endfor %} +{% endif %} +{% endfor %} diff --git a/roles/nftables/templates/router/90-input.nft.j2 b/roles/nftables/templates/router/90-input.nft.j2 new file mode 100644 index 0000000..208c5db --- /dev/null +++ b/roles/nftables/templates/router/90-input.nft.j2 @@ -0,0 +1,16 @@ +#jinja2: trim_blocks: True, lstrip_blocks: True +{% for item in nft_managed_group | sort %} +{% set client = hostvars[item] %} +{% if 'nft_input' in client and client.nft_input is not none %} +{% set rules = client.nft_input if (client.nft_input is iterable and client.nft_input is not string) else [client.nft_input] %} +{% for rule in rules %} +{% set protos = rule.proto if (rule.proto is iterable and rule.proto is not string) else [rule.proto | default(none)] %} +{% set ports = rule.port if (rule.port is iterable and rule.port is not string) else [rule.port | default(none)] %} +{% for proto in protos %} +{% for port in ports %} +iifname "{{ client.iface }}" ip saddr {{ client.ip }} {% if proto and port %}{{ proto }} dport {{ port }} {% endif %}counter accept comment "{{ item }} -> router" +{% endfor %} +{% endfor %} +{% endfor %} +{% endif %} +{% endfor %} diff --git a/roles/nftables/templates/router/90-proxy-output.nft.j2 b/roles/nftables/templates/router/90-proxy-output.nft.j2 new file mode 100644 index 0000000..fe1b334 --- /dev/null +++ b/roles/nftables/templates/router/90-proxy-output.nft.j2 @@ -0,0 +1,11 @@ +#jinja2: trim_blocks: True, lstrip_blocks: True +{% macro set_daddr(rule) %} +{%- if rule in (xray_ip_sets | default([])) or rule in (xray_static_sets | default([])) -%} +{{ rule }}_ip +{%- elif rule in (xray_domain_sets | default([])) -%} +{{ rule }}_dom +{%- endif -%} +{% endmacro %} +{% for rule in output_rules | default([]) | sort %} +ip daddr @{{ set_daddr(rule) }} meta mark set {{ xray_fwmark }} counter accept comment "router -> tproxy" +{% endfor %} diff --git a/roles/nftables/templates/router/90-proxy-prerouting.nft.j2 b/roles/nftables/templates/router/90-proxy-prerouting.nft.j2 new file mode 100644 index 0000000..1b95013 --- /dev/null +++ b/roles/nftables/templates/router/90-proxy-prerouting.nft.j2 @@ -0,0 +1,28 @@ +#jinja2: trim_blocks: True, lstrip_blocks: True +{% macro set_daddr(name) -%} +{%- if name == 'all' -%} +0.0.0.0/0 +{%- elif name in (xray_ip_sets | default([])) or name in (xray_static_sets | default([])) -%} +@{{ name }}_ip +{%- elif name in (xray_domain_sets | default([])) -%} +@{{ name }}_dom +{%- else -%} +invalid_xray_set_{{ name }} +{%- endif -%} +{%- endmacro -%} +{% for item in xray_managed_group | default([]) | sort %} +{% set client = hostvars[item] %} +{% if client.xray_policy is defined %} +{% set src_ip = client.ip %} +{% for rule in client.xray_policy %} +{% set target_set = rule.bypass | default(rule.proxy) %} +{% if rule.bypass is defined %} +meta l4proto tcp ip saddr {{ src_ip }} ip daddr {{ set_daddr(target_set) }} counter accept comment "{{ item }} -> accept" +meta l4proto udp ip saddr {{ src_ip }} ip daddr {{ set_daddr(target_set) }} counter accept comment "{{ item }} -> accept" +{% elif rule.proxy is defined %} +meta l4proto tcp ip saddr {{ src_ip }} ip daddr {{ set_daddr(target_set) }} tproxy ip to :{{ xray_tproxy_port }} meta mark set {{ xray_fwmark }} counter accept comment "{{ item }} -> trpoxy" +meta l4proto udp ip saddr {{ src_ip }} ip daddr {{ set_daddr(target_set) }} tproxy ip to :{{ xray_tproxy_port }} meta mark set {{ xray_fwmark }} counter accept comment "{{ item }} -> tproxy" +{% endif %} +{% endfor %} +{% endif %} +{% endfor %} diff --git a/roles/nftables/templates/router/nftables.conf.j2 b/roles/nftables/templates/router/nftables.conf.j2 new file mode 100644 index 0000000..4957adc --- /dev/null +++ b/roles/nftables/templates/router/nftables.conf.j2 @@ -0,0 +1,14 @@ +#!/usr/sbin/nft -f +flush ruleset +table inet filter { + include "/etc/nftables.d/10-sets.nft" + include "/etc/nftables.d/20-sets.nft" + include "/etc/nftables.d/40-filter.nft" + include "/etc/nftables.d/50-proxy.nft" +} +table inet mangle { + include "/etc/nftables.d/35-mangle.nft" +} +table ip nat { + include "/etc/nftables.d/30-nat.nft" +} diff --git a/roles/nftables/templates/vector/nftables.conf.j2 b/roles/nftables/templates/vector/nftables.conf.j2 new file mode 100644 index 0000000..f5a4622 --- /dev/null +++ b/roles/nftables/templates/vector/nftables.conf.j2 @@ -0,0 +1,22 @@ +#!/usr/sbin/nft -f +flush ruleset +table inet filter { + chain input { + type filter hook input priority filter; + policy drop; + iif "lo" accept + ct state established,related accept + ct state invalid drop + tcp dport 22 counter accept comment "ssh" + tcp dport 80 counter accept comment "http" + tcp dport 443 counter accept comment "https" + } + chain forward { + type filter hook forward priority filter; + policy drop; + } + chain output { + type filter hook output priority filter; + policy accept; + } +} diff --git a/roles/nginx/handlers/main.yml b/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..4f21afe --- /dev/null +++ b/roles/nginx/handlers/main.yml @@ -0,0 +1,12 @@ +--- +- name: check nginx config + ansible.builtin.command: nginx -t + changed_when: false + listen: restart nginx + +- name: restart nginx systemd service unit + ansible.builtin.systemd_service: + name: nginx + state: restarted + enabled: true + listen: restart nginx diff --git a/roles/nginx/tasks/main.yml b/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..43088d0 --- /dev/null +++ b/roles/nginx/tasks/main.yml @@ -0,0 +1,102 @@ +- name: install dependencies + ansible.builtin.apt: + name: + - curl + - gnupg2 + - ca-certificates + - lsb-release + - debian-archive-keyring + state: present + update_cache: true + +- name: ensure nginx keyring exists + ansible.builtin.stat: + path: /usr/share/keyrings/nginx-archive-keyring.gpg + register: nginx_keyring + +- name: download nginx gpg key + ansible.builtin.get_url: + url: https://nginx.org/keys/nginx_signing.key + dest: /tmp/nginx_signing.key + mode: '0644' + when: not nginx_keyring.stat.exists + +- name: dearmor nginx gpg key + ansible.builtin.command: + cmd: gpg --dearmor --yes -o /usr/share/keyrings/nginx-archive-keyring.gpg /tmp/nginx_signing.key + when: not nginx_keyring.stat.exists + +- name: ensure gnupg directory exists + ansible.builtin.file: + path: /root/.gnupg + state: directory + mode: '0700' + owner: root + group: root + +- name: verify nginx signing key fingerprint + ansible.builtin.command: + cmd: gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg + register: nginx_key_check + changed_when: false + check_mode: false + +- name: check nginx signing key fingerprint + ansible.builtin.fail: + msg: "nginx signing key fingerprint mismatch! Got: {{ nginx_key_check.stdout }}" + when: "'573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62' not in nginx_key_check.stdout" + +- name: add nginx apt repository + ansible.builtin.copy: + dest: /etc/apt/sources.list.d/nginx.list + content: >- + deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] + https://nginx.org/packages/{{ 'mainline/' if (nginx_use_mainline | default(false)) else '' }}debian + {{ ansible_facts['distribution_release'] }} nginx + owner: root + group: root + mode: "0644" + register: nginx_repo_file + +- name: set up repository pinning for nginx + ansible.builtin.copy: + dest: /etc/apt/preferences.d/99nginx + content: | + Package: * + Pin: origin nginx.org + Pin: release o=nginx + Pin-Priority: 900 + owner: root + group: root + mode: "0644" + +- name: install nginx + ansible.builtin.apt: + name: nginx + state: latest + update_cache: true + +- name: remove default config + ansible.builtin.file: + path: /etc/nginx/conf.d/default.conf + state: absent + notify: restart nginx + +- name: deploy nginx config + ansible.builtin.template: + src: "{{ inventory_hostname }}/nginx.conf.j2" + dest: "/etc/nginx/nginx.conf" + owner: root + group: root + mode: '0644' + notify: restart nginx + +- name: deploy nginx conf.d config + ansible.builtin.template: + src: "{{ item }}" + dest: "/etc/nginx/conf.d/{{ item | basename | regex_replace('\\.j2$', '') }}" + owner: root + group: root + mode: '0644' + loop: "{{ query('ansible.builtin.fileglob', role_path + '/templates/' + inventory_hostname + '/conf.d/*.conf.j2') }}" + notify: restart nginx diff --git a/roles/nginx/templates/dev/conf.d/placeholder.conf.j2 b/roles/nginx/templates/dev/conf.d/placeholder.conf.j2 new file mode 100644 index 0000000..241101b --- /dev/null +++ b/roles/nginx/templates/dev/conf.d/placeholder.conf.j2 @@ -0,0 +1,26 @@ +{% for item in dnsmasq %} +{% set short_name = item.name.split('.')[0] %} +server { + listen 127.0.0.1:{{ item.backend_port }} ssl ipv6only=off reuseport; + server_name {{ item.name }}; + index index.html; + root {{ placeholders[placeholder].root }}; + http2 on; + ssl_certificate /etc/letsencrypt/live/{{ item.name }}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/{{ item.name }}/privkey.pem; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; + client_header_timeout 5m; + keepalive_timeout 5m; + access_log /var/log/nginx/{{ short_name }}_access.log; + error_log /var/log/nginx/{{ short_name }}_error.log; + location {{ xray_xhttp_path }} { + client_max_body_size 0; + grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + client_body_timeout 5m; + grpc_read_timeout 315; + grpc_send_timeout 5m; + grpc_pass {{ item.socket }}; + } +} +{% endfor %} diff --git a/roles/nginx/templates/dev/nginx.conf.j2 b/roles/nginx/templates/dev/nginx.conf.j2 new file mode 100644 index 0000000..c36d514 --- /dev/null +++ b/roles/nginx/templates/dev/nginx.conf.j2 @@ -0,0 +1,42 @@ +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log notice; +pid /run/nginx.pid; +events { + worker_connections 1024; +} +stream { + log_format proxy '$remote_addr [$time_local] $protocol $status $bytes_sent $bytes_received $session_time "$upstream_addr" "$ssl_preread_server_name"'; + access_log /var/log/nginx/stream-access.log proxy; + map $ssl_preread_server_name $backend_name { +{% if telemt_host is defined %} + {{ telemt_host }} {{ telemt_host.split('.')[0] }}_backend; +{% endif %} +{% for item in dnsmasq %} + {{ item.name }} {{ item.name.split('.')[0] }}_backend; +{% endfor %} + default ""; + } +{% if telemt_host is defined %} + upstream {{ telemt_host.split('.')[0] }}_backend { server 127.0.0.1:{{ telemt_backend_port }}; } +{% endif %} +{% for item in dnsmasq %} + upstream {{ item.name.split('.')[0] }}_backend { server 127.0.0.1:{{ item.backend_port }}; } +{% endfor %} + server { + listen 443; + ssl_preread on; + proxy_pass $backend_name; + } +} +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + log_format main '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"'; + access_log /var/log/nginx/access.log main; + sendfile on; + #tcp_nopush on; + keepalive_timeout 65; + #gzip on; + include /etc/nginx/conf.d/*.conf; +} diff --git a/roles/nginx/templates/dev_shin/conf.d/placeholder.conf.j2 b/roles/nginx/templates/dev_shin/conf.d/placeholder.conf.j2 new file mode 100644 index 0000000..241101b --- /dev/null +++ b/roles/nginx/templates/dev_shin/conf.d/placeholder.conf.j2 @@ -0,0 +1,26 @@ +{% for item in dnsmasq %} +{% set short_name = item.name.split('.')[0] %} +server { + listen 127.0.0.1:{{ item.backend_port }} ssl ipv6only=off reuseport; + server_name {{ item.name }}; + index index.html; + root {{ placeholders[placeholder].root }}; + http2 on; + ssl_certificate /etc/letsencrypt/live/{{ item.name }}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/{{ item.name }}/privkey.pem; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; + client_header_timeout 5m; + keepalive_timeout 5m; + access_log /var/log/nginx/{{ short_name }}_access.log; + error_log /var/log/nginx/{{ short_name }}_error.log; + location {{ xray_xhttp_path }} { + client_max_body_size 0; + grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + client_body_timeout 5m; + grpc_read_timeout 315; + grpc_send_timeout 5m; + grpc_pass {{ item.socket }}; + } +} +{% endfor %} diff --git a/roles/nginx/templates/dev_shin/nginx.conf.j2 b/roles/nginx/templates/dev_shin/nginx.conf.j2 new file mode 100644 index 0000000..c36d514 --- /dev/null +++ b/roles/nginx/templates/dev_shin/nginx.conf.j2 @@ -0,0 +1,42 @@ +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log notice; +pid /run/nginx.pid; +events { + worker_connections 1024; +} +stream { + log_format proxy '$remote_addr [$time_local] $protocol $status $bytes_sent $bytes_received $session_time "$upstream_addr" "$ssl_preread_server_name"'; + access_log /var/log/nginx/stream-access.log proxy; + map $ssl_preread_server_name $backend_name { +{% if telemt_host is defined %} + {{ telemt_host }} {{ telemt_host.split('.')[0] }}_backend; +{% endif %} +{% for item in dnsmasq %} + {{ item.name }} {{ item.name.split('.')[0] }}_backend; +{% endfor %} + default ""; + } +{% if telemt_host is defined %} + upstream {{ telemt_host.split('.')[0] }}_backend { server 127.0.0.1:{{ telemt_backend_port }}; } +{% endif %} +{% for item in dnsmasq %} + upstream {{ item.name.split('.')[0] }}_backend { server 127.0.0.1:{{ item.backend_port }}; } +{% endfor %} + server { + listen 443; + ssl_preread on; + proxy_pass $backend_name; + } +} +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + log_format main '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"'; + access_log /var/log/nginx/access.log main; + sendfile on; + #tcp_nopush on; + keepalive_timeout 65; + #gzip on; + include /etc/nginx/conf.d/*.conf; +} diff --git a/roles/nginx/templates/liqueur/nginx.conf.j2 b/roles/nginx/templates/liqueur/nginx.conf.j2 new file mode 100644 index 0000000..12a4e48 --- /dev/null +++ b/roles/nginx/templates/liqueur/nginx.conf.j2 @@ -0,0 +1,64 @@ +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log notice; +pid /run/nginx.pid; +events { + worker_connections 1024; +} +stream { + log_format proxy '$remote_addr [$time_local] $protocol $status $bytes_sent $bytes_received $session_time "$ssl_preread_server_name"'; + access_log /var/log/nginx/stream-access.log proxy; + upstream haproxy_http { + server 127.0.0.1:10080; + } + upstream haproxy_backend_pp { + server 127.0.0.1:19443; + } + upstream haproxy_backend_real { + server 127.0.0.1:10443; + } + upstream stunnel_tun0_pp { + server 127.0.0.1:28443; + } + upstream stunnel_tap0_pp { + server 127.0.0.1:28444; + } + upstream stunnel_tun0_backend { + server 127.0.0.1:8443; + } + upstream stunnel_tap0_backend { + server 127.0.0.1:8444; + } + map $ssl_preread_server_name $backend { + liqueur.oyacoi.ru stunnel_tun0_pp; + absinthe.oyacoi.ru stunnel_tap0_pp; + default haproxy_backend_pp; + } + server { + listen {{ ip }}:80; + proxy_pass haproxy_http; + proxy_protocol on; + } + server { + listen {{ ip }}:443; + proxy_pass $backend; + ssl_preread on; + proxy_protocol on; + } + server { + listen 127.0.0.1:19443 proxy_protocol; + set_real_ip_from 127.0.0.1; + proxy_pass haproxy_backend_real; + proxy_protocol on; + } + server { + listen 127.0.0.1:28443 proxy_protocol; + set_real_ip_from 127.0.0.1; + proxy_pass stunnel_tun0_backend; + } + server { + listen 127.0.0.1:28444 proxy_protocol; + set_real_ip_from 127.0.0.1; + proxy_pass stunnel_tap0_backend; + } +} diff --git a/roles/nginx/templates/nginx/conf.d/sites.conf.j2 b/roles/nginx/templates/nginx/conf.d/sites.conf.j2 new file mode 100644 index 0000000..d83ceb3 --- /dev/null +++ b/roles/nginx/templates/nginx/conf.d/sites.conf.j2 @@ -0,0 +1,62 @@ +#jinja2: trim_blocks: True, lstrip_blocks: True, keep_trailing_newline: True +{% for item in nginx_managed_group | default([]) | sort %} +{% set client = hostvars[item] %} +{% for item_dnsmasq in client.dnsmasq | default([]) %} +{% set short_name = item_dnsmasq.name.split('.')[0] %} +{% if item_dnsmasq.nginx_custom | default(false) %} +{% include "static/" ~ short_name ~ ".conf.j2" ignore missing %} +{% elif item_dnsmasq.upstream_port is defined and client.ip is defined %} +server { + listen 80; +{% if item_dnsmasq.proxy_protocol | default(false) %} + listen 81 proxy_protocol; + set_real_ip_from {{ hostvars["haproxy"]["ip"] }}; + real_ip_header proxy_protocol; +{% endif %} + server_name {{ item_dnsmasq.name }}; + access_log /var/log/nginx/{{ short_name }}_access.log; + error_log /var/log/nginx/{{ short_name }}_error.log; +{% for cidr in item_dnsmasq.nginx_allow | default([]) %} + allow {{ cidr }}; +{% endfor %} +{% if item_dnsmasq.nginx_allow is defined %} + deny all; +{% endif %} + location / { + return 301 https://$host$request_uri; + } +} +server { + listen 443 ssl; +{% if item_dnsmasq.proxy_protocol | default(false) %} + listen 444 ssl proxy_protocol; + set_real_ip_from {{ hostvars["haproxy"]["ip"] }}; + real_ip_header proxy_protocol; +{% endif %} + server_name {{ item_dnsmasq.name }}; + ssl_certificate /etc/letsencrypt/live/oyacoi.ru/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/oyacoi.ru/privkey.pem; + access_log /var/log/nginx/{{ short_name }}_access.log; + error_log /var/log/nginx/{{ short_name }}_error.log; +{% for cidr in item_dnsmasq.nginx_allow | default([]) %} + allow {{ cidr }}; +{% endfor %} +{% if item_dnsmasq.nginx_allow is defined %} + deny all; +{% endif %} + location / { + proxy_pass http://{{ client.ip }}:{{ item_dnsmasq.upstream_port }}; +{% if item_dnsmasq.ws | default(false) %} + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; +{% endif %} + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} +{% endif %} +{% endfor %} +{% endfor %} diff --git a/roles/nginx/templates/nginx/conf.d/static/ntfy.conf.j2 b/roles/nginx/templates/nginx/conf.d/static/ntfy.conf.j2 new file mode 100644 index 0000000..daf4ae0 --- /dev/null +++ b/roles/nginx/templates/nginx/conf.d/static/ntfy.conf.j2 @@ -0,0 +1,67 @@ +server { + listen 80; +{% if item_dnsmasq.proxy_protocol | default(false) %} + listen 81 proxy_protocol; + set_real_ip_from {{ hostvars['haproxy']['ip'] }}; + real_ip_header proxy_protocol; +{% endif %} + server_name {{ item_dnsmasq.name }}; + access_log /var/log/nginx/{{ short_name }}_access.log; + error_log /var/log/nginx/{{ short_name }}_error.log; +{% for cidr in item_dnsmasq.nginx_allow | default([]) %} + allow {{ cidr }}; +{% endfor %} +{% if item_dnsmasq.nginx_allow is defined %} + deny all; +{% endif %} + location / { + return 302 https://$http_host$request_uri$is_args$query_string; + proxy_pass http://{{ client.ip }}:{{ item_dnsmasq.upstream_port }}; + proxy_http_version 1.1; + proxy_set_header Host $http_host; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_connect_timeout 3m; + proxy_send_timeout 3m; + proxy_read_timeout 3m; + client_max_body_size 0; + } +} +server { + listen 443 ssl; +{% if item_dnsmasq.proxy_protocol | default(false) %} + listen 444 ssl proxy_protocol; + set_real_ip_from {{ hostvars['haproxy']['ip'] }}; + real_ip_header proxy_protocol; +{% endif %} + server_name {{ item_dnsmasq.name }}; + ssl_certificate /etc/letsencrypt/live/oyacoi.ru/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/oyacoi.ru/privkey.pem; + ssl_session_timeout 1d; + ssl_session_cache shared:MozSSL:10m; + ssl_session_tickets off; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; + ssl_prefer_server_ciphers off; + access_log /var/log/nginx/{{ short_name }}_access.log; + error_log /var/log/nginx/{{ short_name }}_error.log; +{% for cidr in item_dnsmasq.nginx_allow | default([]) %} + allow {{ cidr }}; +{% endfor %} +{% if item_dnsmasq.nginx_allow is defined %} + deny all; +{% endif %} + location / { + proxy_pass http://{{ client.ip }}:{{ item_dnsmasq.upstream_port }}; + proxy_http_version 1.1; + proxy_set_header Host $http_host; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_connect_timeout 3m; + proxy_send_timeout 3m; + proxy_read_timeout 3m; + client_max_body_size 0; + } +} diff --git a/roles/nginx/templates/nginx/conf.d/static/proxmox.conf.j2 b/roles/nginx/templates/nginx/conf.d/static/proxmox.conf.j2 new file mode 100644 index 0000000..4d8f0cd --- /dev/null +++ b/roles/nginx/templates/nginx/conf.d/static/proxmox.conf.j2 @@ -0,0 +1,51 @@ +server { + listen 80; +{% if item_dnsmasq.proxy_protocol | default(false) %} + listen 81 proxy_protocol; + set_real_ip_from {{ hostvars['haproxy']['ip'] }}; + real_ip_header proxy_protocol; +{% endif %} + server_name {{ item_dnsmasq.name }}; + access_log /var/log/nginx/{{ short_name }}_access.log; + error_log /var/log/nginx/{{ short_name }}_error.log; +{% for cidr in item_dnsmasq.nginx_allow | default([]) %} + allow {{ cidr }}; +{% endfor %} +{% if item_dnsmasq.nginx_allow is defined %} + deny all; +{% endif %} + location / { + return 301 https://$host$request_uri; + } +} +server { + listen 443 ssl; +{% if item_dnsmasq.proxy_protocol | default(false) %} + listen 444 ssl proxy_protocol; + set_real_ip_from {{ hostvars['haproxy']['ip'] }}; + real_ip_header proxy_protocol; +{% endif %} + server_name {{ item_dnsmasq.name }}; + ssl_certificate /etc/letsencrypt/live/oyacoi.ru/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/oyacoi.ru/privkey.pem; + access_log /var/log/nginx/{{ short_name }}_access.log; + error_log /var/log/nginx/{{ short_name }}_error.log; +{% for cidr in item_dnsmasq.nginx_allow | default([]) %} + allow {{ cidr }}; +{% endfor %} +{% if item_dnsmasq.nginx_allow is defined %} + deny all; +{% endif %} + location / { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_pass https://{{ client.ip }}:{{ item_dnsmasq.upstream_port }}; + proxy_buffering off; + client_max_body_size 0; + proxy_connect_timeout 3600s; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + send_timeout 3600s; + } +} diff --git a/roles/nginx/templates/nginx/conf.d/static/talk.conf.j2 b/roles/nginx/templates/nginx/conf.d/static/talk.conf.j2 new file mode 100644 index 0000000..dc2c1fd --- /dev/null +++ b/roles/nginx/templates/nginx/conf.d/static/talk.conf.j2 @@ -0,0 +1,46 @@ +server { + listen 443 ssl; +{% if item_dnsmasq.proxy_protocol | default(false) %} + listen 444 ssl proxy_protocol; + set_real_ip_from {{ hostvars['haproxy']['ip'] }}; + real_ip_header proxy_protocol; +{% endif %} + server_name {{ item_dnsmasq.name }}; + ssl_certificate /etc/letsencrypt/live/oyacoi.ru/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/oyacoi.ru/privkey.pem; + access_log /var/log/nginx/{{ short_name }}_access.log; + error_log /var/log/nginx/{{ short_name }}_error.log; + set $prosody_url "http://{{ client.ip }}:{{ item_dnsmasq.upstream_port }}"; +{% for cidr in item_dnsmasq.nginx_allow | default([]) %} + allow {{ cidr }}; +{% endfor %} +{% if item_dnsmasq.nginx_allow is defined %} + deny all; +{% endif %} + location /xmpp-websocket { + proxy_pass $prosody_url/xmpp-websocket; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_read_timeout 900s; + } + location /http-bind { + proxy_pass $prosody_url/http-bind; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_buffering off; + tcp_nodelay on; + } + location /.well-known/host-meta { + proxy_pass $prosody_url/.well-known/host-meta; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + location / { + return 444; + } +} diff --git a/roles/nginx/templates/nginx/conf.d/static/torrserver.conf.j2 b/roles/nginx/templates/nginx/conf.d/static/torrserver.conf.j2 new file mode 100644 index 0000000..8df8888 --- /dev/null +++ b/roles/nginx/templates/nginx/conf.d/static/torrserver.conf.j2 @@ -0,0 +1,43 @@ +server { + listen 80; + server_name {{ item_dnsmasq.name }}; + access_log /var/log/nginx/{{ short_name }}_access.log; + error_log /var/log/nginx/{{ short_name }}_error.log; +{% for cidr in item_dnsmasq.nginx_allow | default([]) %} + allow {{ cidr }}; +{% endfor %} +{% if item_dnsmasq.nginx_allow is defined %} + deny all; +{% endif %} + location / { + return 301 https://$host$request_uri; + } +} +server { + listen 443 ssl; + server_name {{ item_dnsmasq.name }}; + ssl_certificate /etc/letsencrypt/live/oyacoi.ru/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/oyacoi.ru/privkey.pem; + access_log /var/log/nginx/{{ short_name }}_access.log; + error_log /var/log/nginx/{{ short_name }}_error.log; +{% for cidr in item_dnsmasq.nginx_allow | default([]) %} + allow {{ cidr }}; +{% endfor %} +{% if item_dnsmasq.nginx_allow is defined %} + deny all; +{% endif %} + location / { + proxy_pass http://{{ client.ip }}:{{ item_dnsmasq.upstream_port }}; + proxy_buffering off; + proxy_request_buffering off; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} diff --git a/roles/nginx/templates/nginx/conf.d/static/upload.conf.j2 b/roles/nginx/templates/nginx/conf.d/static/upload.conf.j2 new file mode 100644 index 0000000..6157f6d --- /dev/null +++ b/roles/nginx/templates/nginx/conf.d/static/upload.conf.j2 @@ -0,0 +1,32 @@ +server { + listen 443 ssl; +{% if item_dnsmasq.proxy_protocol | default(false) %} + listen 444 ssl proxy_protocol; + set_real_ip_from {{ hostvars['haproxy']['ip'] }}; + real_ip_header proxy_protocol; +{% endif %} + server_name {{ item_dnsmasq.name }}; + ssl_certificate /etc/letsencrypt/live/oyacoi.ru/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/oyacoi.ru/privkey.pem; + access_log /var/log/nginx/{{ short_name }}_access.log; + error_log /var/log/nginx/{{ short_name }}_error.log; +{% for cidr in item_dnsmasq.nginx_allow | default([]) %} + allow {{ cidr }}; +{% endfor %} +{% if item_dnsmasq.nginx_allow is defined %} + deny all; +{% endif %} + location / { + proxy_pass http://{{ client.ip }}:{{ item_dnsmasq.upstream_port }}; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto https; + client_max_body_size 1024M; + proxy_request_buffering off; + proxy_buffering off; + proxy_connect_timeout 90s; + proxy_send_timeout 300s; + proxy_read_timeout 300s; + } +} diff --git a/roles/nginx/templates/nginx/nginx.conf.j2 b/roles/nginx/templates/nginx/nginx.conf.j2 new file mode 100644 index 0000000..6777ef1 --- /dev/null +++ b/roles/nginx/templates/nginx/nginx.conf.j2 @@ -0,0 +1,20 @@ +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log notice; +pid /run/nginx.pid; +events { + worker_connections 1024; +} +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + access_log /var/log/nginx/access.log main; + sendfile on; + #tcp_nopush on; + keepalive_timeout 65; + #gzip on; + include /etc/nginx/conf.d/*.conf; +} diff --git a/roles/nginx/templates/vector/conf.d/placeholder.conf.j2 b/roles/nginx/templates/vector/conf.d/placeholder.conf.j2 new file mode 100644 index 0000000..0c6fa81 --- /dev/null +++ b/roles/nginx/templates/vector/conf.d/placeholder.conf.j2 @@ -0,0 +1,26 @@ +{% for item in dnsmasq %} +{% set short_name = item.name.split('.')[0] %} +server { + listen 127.0.0.1:{{ item.backend_port }} ssl ipv6only=off reuseport; + server_name {{ item.name }}; + index index.html; + root /var/www/html/dist/; + http2 on; + ssl_certificate /etc/letsencrypt/live/{{ item.name }}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/{{ item.name }}/privkey.pem; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; + client_header_timeout 5m; + keepalive_timeout 5m; + access_log /var/log/nginx/{{ short_name }}_access.log; + error_log /var/log/nginx/{{ short_name }}_error.log; + location {{ xray_xhttp_path }} { + client_max_body_size 0; + grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + client_body_timeout 5m; + grpc_read_timeout 315; + grpc_send_timeout 5m; + grpc_pass {{ item.socket }}; + } +} +{% endfor %} diff --git a/roles/nginx/templates/vector/nginx.conf.j2 b/roles/nginx/templates/vector/nginx.conf.j2 new file mode 100644 index 0000000..c36d514 --- /dev/null +++ b/roles/nginx/templates/vector/nginx.conf.j2 @@ -0,0 +1,42 @@ +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log notice; +pid /run/nginx.pid; +events { + worker_connections 1024; +} +stream { + log_format proxy '$remote_addr [$time_local] $protocol $status $bytes_sent $bytes_received $session_time "$upstream_addr" "$ssl_preread_server_name"'; + access_log /var/log/nginx/stream-access.log proxy; + map $ssl_preread_server_name $backend_name { +{% if telemt_host is defined %} + {{ telemt_host }} {{ telemt_host.split('.')[0] }}_backend; +{% endif %} +{% for item in dnsmasq %} + {{ item.name }} {{ item.name.split('.')[0] }}_backend; +{% endfor %} + default ""; + } +{% if telemt_host is defined %} + upstream {{ telemt_host.split('.')[0] }}_backend { server 127.0.0.1:{{ telemt_backend_port }}; } +{% endif %} +{% for item in dnsmasq %} + upstream {{ item.name.split('.')[0] }}_backend { server 127.0.0.1:{{ item.backend_port }}; } +{% endfor %} + server { + listen 443; + ssl_preread on; + proxy_pass $backend_name; + } +} +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + log_format main '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" "$http_x_forwarded_for"'; + access_log /var/log/nginx/access.log main; + sendfile on; + #tcp_nopush on; + keepalive_timeout 65; + #gzip on; + include /etc/nginx/conf.d/*.conf; +} diff --git a/roles/ntfy/handlers/main.yml b/roles/ntfy/handlers/main.yml new file mode 100644 index 0000000..af83745 --- /dev/null +++ b/roles/ntfy/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart ntfy + ansible.builtin.systemd: + name: ntfy + state: restarted + enabled: true diff --git a/roles/ntfy/tasks/main.yml b/roles/ntfy/tasks/main.yml new file mode 100644 index 0000000..5a0aaf3 --- /dev/null +++ b/roles/ntfy/tasks/main.yml @@ -0,0 +1,25 @@ +--- +- name: install ntfy + ansible.builtin.apt: + name: ntfy + state: latest + update_cache: true + notify: restart ntfy + +- name: set ntfy data directory ownership + ansible.builtin.file: + path: /var/lib/ntfy + state: directory + owner: _ntfy + group: _ntfy + mode: '0750' + recurse: true + +- name: deploy ntfy config + ansible.builtin.template: + src: "{{ inventory_hostname }}/server.yml.j2" + dest: "/etc/ntfy/server.yml" + owner: root + group: root + mode: '0644' + notify: restart ntfy diff --git a/roles/ntfy/templates/ntfy/server.yml.j2 b/roles/ntfy/templates/ntfy/server.yml.j2 new file mode 100644 index 0000000..602a12a --- /dev/null +++ b/roles/ntfy/templates/ntfy/server.yml.j2 @@ -0,0 +1,24 @@ +base-url: "https://{{ dnsmasq[0].name }}" +database-url: "postgres://ntfy:{{ database_password | urlencode }}@{{ hostvars['pgsql'].ip }}:5432/ntfy" +listen-http: ":2586" +cache-duration: "24h" +attachment-cache-dir: "/var/lib/ntfy/" +attachment-total-size-limit: "500M" +attachment-file-size-limit: "15M" +attachment-expiry-duration: "12h" +auth-default-access: "deny-all" +auth-users: +{% for user in ntfy_auth_users %} + - "{{ user.name }}:{{ user.hash }}:{{ user.role }}" +{% endfor %} +auth-tokens: +{% for token in ntfy_auth_tokens %} + - "{{ token.name }}:{{ token.token }}" +{% endfor %} +auth-access: +{% for access in ntfy_auth_access %} + - "{{ access.name }}:{{ access.topic }}:{{ access.access }}" +{% endfor %} +enable-login: true +behind-proxy: true +web-root: disable diff --git a/roles/openvpn/files/liqueur/ccd/liqueur/matr10 b/roles/openvpn/files/liqueur/ccd/liqueur/matr10 new file mode 100644 index 0000000..ba2bf1d --- /dev/null +++ b/roles/openvpn/files/liqueur/ccd/liqueur/matr10 @@ -0,0 +1 @@ +iroute 192.168.1.0 255.255.255.0 diff --git a/roles/openvpn/files/liqueur/ccd/liqueur/mur89 b/roles/openvpn/files/liqueur/ccd/liqueur/mur89 new file mode 100644 index 0000000..433dbb4 --- /dev/null +++ b/roles/openvpn/files/liqueur/ccd/liqueur/mur89 @@ -0,0 +1,7 @@ +iroute 10.1.0.0 255.255.255.0 +iroute 10.2.0.0 255.255.255.0 +iroute 10.3.0.0 255.255.255.0 +iroute 10.4.0.0 255.255.255.0 +iroute 10.10.0.0 255.255.255.0 +iroute 10.11.0.0 255.255.255.0 +iroute 10.12.0.0 255.255.255.0 diff --git a/roles/openvpn/tasks/main.yml b/roles/openvpn/tasks/main.yml new file mode 100644 index 0000000..af79ff6 --- /dev/null +++ b/roles/openvpn/tasks/main.yml @@ -0,0 +1,43 @@ +--- +- name: install openvpn + ansible.builtin.apt: + name: openvpn + state: latest + update_cache: true + +- name: deploy ccd files + ansible.builtin.copy: + src: "{{ role_path }}/files/{{ inventory_hostname }}/ccd/" + dest: /etc/openvpn/ccd/ + owner: root + group: root + mode: "0644" + when: (openvpn_need_ccd | default(false)) == true + +- name: deploy openvpn config + ansible.builtin.template: + src: "{{ item }}" + dest: "/etc/openvpn/{{ item | basename | regex_replace('\\.j2$', '') }}" + owner: root + group: root + mode: "0600" + loop: "{{ query('ansible.builtin.fileglob', role_path + '/templates/' + inventory_hostname + '/*.conf.j2') }}" + register: openvpn_configs + +- name: deploy openvpn scripts + ansible.builtin.template: + src: "{{ item }}" + dest: "/etc/openvpn/{{ item | basename | regex_replace('\\.j2$', '') }}" + owner: root + group: root + mode: "0755" + loop: "{{ query('ansible.builtin.fileglob', role_path + '/templates/' + inventory_hostname + '/*.sh.j2') }}" + +- name: restart openvpn + ansible.builtin.systemd_service: + name: "openvpn@{{ item.item | basename | regex_replace('\\.conf\\.j2$', '') }}" + state: restarted + enabled: true + daemon_reload: true + loop: "{{ openvpn_configs.results }}" + when: item.changed diff --git a/roles/openvpn/templates/liqueur/absinthe.conf.j2 b/roles/openvpn/templates/liqueur/absinthe.conf.j2 new file mode 100644 index 0000000..341b1ce --- /dev/null +++ b/roles/openvpn/templates/liqueur/absinthe.conf.j2 @@ -0,0 +1,30 @@ +port 1195 +proto tcp +dev tap0 +dev-type tap +server-bridge nogw +client-to-client +keepalive 10 60 +cipher AES-256-GCM +auth SHA256 +persist-key +persist-tun +status openvpn-tap0-status.log +verb 6 +tun-mtu 1500 +mssfix 1300 +script-security 2 +up /etc/openvpn/tap0-up.sh +down /etc/openvpn/tap0-down.sh + +{{ lookup('file', hostvars["localhost"]["easyrsa_dir"] + '/pki/tap0/ca.crt') }} + + +{{ lookup('file', hostvars["localhost"]["easyrsa_dir"] + '/pki/tap0/issued/server.crt') }} + + +{{ lookup('file', hostvars["localhost"]["easyrsa_dir"] + '/pki/tap0/private/server.key') }} + + +{{ lookup('file', hostvars["localhost"]["easyrsa_dir"] + '/pki/tap0/dh.pem') }} + diff --git a/roles/openvpn/templates/liqueur/liqueur.conf.j2 b/roles/openvpn/templates/liqueur/liqueur.conf.j2 new file mode 100644 index 0000000..7966f13 --- /dev/null +++ b/roles/openvpn/templates/liqueur/liqueur.conf.j2 @@ -0,0 +1,44 @@ +port 1194 +proto tcp +dev tun0 +server 172.168.0.0 255.255.255.0 +topology subnet +ifconfig-pool-persist ipp.txt +route 10.1.0.0 255.255.255.0 +route 10.2.0.0 255.255.255.0 +route 10.3.0.0 255.255.255.0 +route 10.4.0.0 255.255.255.0 +route 10.10.0.0 255.255.255.0 +route 10.11.0.0 255.255.255.0 +route 10.12.0.0 255.255.255.0 +route 192.168.1.0 255.255.255.0 +push "route 192.168.1.0 255.255.255.0" +push "route 10.1.0.0 255.255.255.0" +push "route 10.2.0.0 255.255.255.0" +push "route 10.3.0.0 255.255.255.0" +push "route 10.4.0.0 255.255.255.0" +push "route 10.10.0.0 255.255.255.0" +push "route 10.11.0.0 255.255.255.0" +push "route 10.12.0.0 255.255.255.0" +client-config-dir /etc/openvpn/ccd/liqueur +keepalive 10 60 +cipher AES-256-GCM +auth SHA256 +persist-key +persist-tun +status openvpn-tun0-status.log +verb 3 +tun-mtu 1500 +mssfix 1300 + +{{ lookup('file', hostvars["localhost"]["easyrsa_dir"] + '/pki/tun0/ca.crt') }} + + +{{ lookup('file', hostvars["localhost"]["easyrsa_dir"] + '/pki/tun0/issued/server.crt') }} + + +{{ lookup('file', hostvars["localhost"]["easyrsa_dir"] + '/pki/tun0/private/server.key') }} + + +{{ lookup('file', hostvars["localhost"]["easyrsa_dir"] + '/pki/tun0/dh.pem') }} + diff --git a/roles/openvpn/templates/liqueur/tap0-down.sh.j2 b/roles/openvpn/templates/liqueur/tap0-down.sh.j2 new file mode 100644 index 0000000..4fd2d2b --- /dev/null +++ b/roles/openvpn/templates/liqueur/tap0-down.sh.j2 @@ -0,0 +1,2 @@ +#!/bin/sh +ip link set dev tap0 down diff --git a/roles/openvpn/templates/liqueur/tap0-up.sh.j2 b/roles/openvpn/templates/liqueur/tap0-up.sh.j2 new file mode 100644 index 0000000..598ce7d --- /dev/null +++ b/roles/openvpn/templates/liqueur/tap0-up.sh.j2 @@ -0,0 +1,2 @@ +#!/bin/sh +ip link set dev tap0 up diff --git a/roles/openvpn/templates/router/ltrefilov.conf.j2 b/roles/openvpn/templates/router/ltrefilov.conf.j2 new file mode 100644 index 0000000..d1500cf --- /dev/null +++ b/roles/openvpn/templates/router/ltrefilov.conf.j2 @@ -0,0 +1,24 @@ +client +dev tap0 +dev-type tap +proto tcp +remote 127.0.0.1 1195 +resolv-retry infinite +nobind +persist-key +persist-tun +remote-cert-tls server +auth SHA256 +cipher AES-256-GCM +tun-mtu 1500 +mssfix 1300 +verb 3 + +{{ lookup('file', hostvars["localhost"]["easyrsa_dir"] + '/pki/tap0/ca.crt') }} + + +{{ lookup('file', hostvars["localhost"]["easyrsa_dir"] + '/pki/tap0/issued/ltrefilov.crt') }} + + +{{ lookup('file', hostvars["localhost"]["easyrsa_dir"] + '/pki/tap0/private/ltrefilov.key') }} + diff --git a/roles/openvpn/templates/router/mur89.conf.j2 b/roles/openvpn/templates/router/mur89.conf.j2 new file mode 100644 index 0000000..95c6d46 --- /dev/null +++ b/roles/openvpn/templates/router/mur89.conf.j2 @@ -0,0 +1,24 @@ +client +dev tun0 +proto tcp +remote 127.0.0.1 1194 +resolv-retry infinite +nobind +persist-key +persist-tun +remote-cert-tls server +auth SHA256 +cipher AES-256-GCM +verb 3 +script-security 2 +up /etc/openvpn/tun0-up.sh +down /etc/openvpn/tun0-down.sh + +{{ lookup('file', hostvars["localhost"]["easyrsa_dir"] + '/pki/tun0/ca.crt') }} + + +{{ lookup('file', hostvars["localhost"]["easyrsa_dir"] + '/pki/tun0/issued/mur89.crt') }} + + +{{ lookup('file', hostvars["localhost"]["easyrsa_dir"] + '/pki/tun0/private/mur89.key') }} + diff --git a/roles/openvpn/templates/router/tun0-down.sh.j2 b/roles/openvpn/templates/router/tun0-down.sh.j2 new file mode 100644 index 0000000..ec1e0b4 --- /dev/null +++ b/roles/openvpn/templates/router/tun0-down.sh.j2 @@ -0,0 +1,3 @@ +#!/bin/sh +ip route del default dev tun0 table 201 2>/dev/null || true +ip rule del fwmark 0x2 table 201 2>/dev/null || true diff --git a/roles/openvpn/templates/router/tun0-up.sh.j2 b/roles/openvpn/templates/router/tun0-up.sh.j2 new file mode 100644 index 0000000..ee8f6cc --- /dev/null +++ b/roles/openvpn/templates/router/tun0-up.sh.j2 @@ -0,0 +1,3 @@ +#!/bin/sh +ip rule add fwmark 0x2 table 201 2>/dev/null || true +ip route add default dev tun0 table 201 2>/dev/null || true diff --git a/roles/pgsql/handlers/main.yml b/roles/pgsql/handlers/main.yml new file mode 100644 index 0000000..431ce9e --- /dev/null +++ b/roles/pgsql/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart postgresql + ansible.builtin.systemd_service: + name: postgresql@17-main + state: restarted + enabled: true diff --git a/roles/pgsql/tasks/main.yml b/roles/pgsql/tasks/main.yml new file mode 100644 index 0000000..22b8158 --- /dev/null +++ b/roles/pgsql/tasks/main.yml @@ -0,0 +1,68 @@ +--- +- name: install postgresql + ansible.builtin.apt: + name: "{{ item }}" + state: latest + update_cache: true + loop: + - postgresql + - postgresql-contrib + notify: restart postgresql + +- name: ensure postgresql data directory is a mountpoint + ansible.builtin.command: mountpoint -q /var/lib/postgresql + register: vw_mountpoint + failed_when: false + changed_when: false + +- name: stop postgresql before relocating data + ansible.builtin.systemd: + name: postgresql + state: stopped + when: vw_mountpoint.rc != 0 + +- name: remove default postgresql data directory + ansible.builtin.file: + path: /var/lib/postgresql/ + state: absent + when: vw_mountpoint.rc != 0 + +- name: ensure postgres data source directory exists + ansible.builtin.file: + path: /mnt/pgsql/data + state: directory + owner: postgres + group: postgres + mode: "0755" + +- name: bind mount postgres data directory + ansible.posix.mount: + path: /var/lib/postgresql + src: /mnt/pgsql/data + fstype: none + opts: bind + state: mounted + notify: restart postgresql + +- name: set postgres data directory ownership + ansible.builtin.file: + path: /mnt/pgsql/data + owner: postgres + group: postgres + recurse: true + +- name: configure postgres + ansible.builtin.lineinfile: + path: /etc/postgresql/17/main/postgresql.conf + regexp: "^#?listen_addresses\\s*=" + line: "listen_addresses = '*'" + state: present + notify: restart postgresql + +- name: configure pg_hba + ansible.builtin.lineinfile: + path: /etc/postgresql/17/main/pg_hba.conf + line: "host all all {{ hostvars[item].ip }}/32 scram-sha-256" + state: present + loop: "{{ db_clients | default([]) }}" + notify: restart postgresql diff --git a/roles/placeholder/tasks/main.yml b/roles/placeholder/tasks/main.yml new file mode 100644 index 0000000..8bcb4f0 --- /dev/null +++ b/roles/placeholder/tasks/main.yml @@ -0,0 +1,58 @@ +--- +- name: install depenedencies + apt: + name: + - git + - sudo + state: latest + update_cache: true + +- name: ensure ansible remote tmp directory exists + file: + path: /tmp/.ansible-www-data + state: directory + owner: www-data + group: www-data + mode: 0700 + +- name: check if git repo exists + stat: + path: /var/www/html/.git + register: html_git + +- name: check current git remote + command: git -C /var/www/html remote get-url origin + become: yes + become_user: www-data + register: current_remote + changed_when: false + when: html_git.stat.exists + vars: + ansible_remote_tmp: /tmp/.ansible-www-data + +- name: remove irrelevant html directory + file: + path: /var/www/html + state: absent + when: > + html_git.stat.exists and + current_remote.stdout | default('') != placeholders[placeholder].url + +- name: ensure html exists + file: + path: /var/www/html + state: directory + owner: www-data + group: www-data + mode: '0755' + +- name: clone placeholder + git: + repo: "{{ placeholders[placeholder].url }}" + dest: /var/www/html + version: master + force: yes + become: yes + become_user: www-data + vars: + ansible_remote_tmp: /tmp/.ansible-www-data diff --git a/roles/prosody/handlers/main.yml b/roles/prosody/handlers/main.yml new file mode 100644 index 0000000..c4514ec --- /dev/null +++ b/roles/prosody/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart prosody + ansible.builtin.systemd_service: + name: prosody + state: restarted + enabled: true diff --git a/roles/prosody/tasks/main.yml b/roles/prosody/tasks/main.yml new file mode 100644 index 0000000..2033d43 --- /dev/null +++ b/roles/prosody/tasks/main.yml @@ -0,0 +1,66 @@ +--- +- name: install prosody + ansible.builtin.apt: + name: + - prosody + - lua-dbi-postgresql + - prosody-modules + state: present + update_cache: yes + notify: + - restart prosody + +- name: fetch wan ip + ansible.builtin.shell: ssh -o StrictHostKeyChecking=no root@{{ hostvars['router'].ip }} "ip -4 addr show eth1 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'" + delegate_to: localhost + register: router_wan_ip + changed_when: false + vars: + ansible_connection: local + +- name: ensure prosody data directory is a mountpoint + ansible.builtin.command: mountpoint -q /var/lib/prosody + register: vw_mountpoint + failed_when: false + changed_when: false + +- name: remove default prosody data directory + ansible.builtin.file: + path: /var/lib/prosody + state: absent + when: vw_mountpoint.rc != 0 + +- name: ensure prosody data source directory exists + ansible.builtin.file: + path: /mnt/prosody/data + state: directory + owner: prosody + group: prosody + mode: "0755" + +- name: bind mount prosody data directory + ansible.posix.mount: + path: /var/lib/prosody + src: /mnt/prosody/data + fstype: none + opts: bind + state: mounted + notify: restart prosody + +- name: set prosody data directory ownership + ansible.builtin.file: + path: /mnt/prosody/data + owner: prosody + group: prosody + recurse: true + +- name: deploy prosody config + ansible.builtin.template: + src: "{{ inventory_hostname }}/prosody.cfg.lua.j2" + dest: "/etc/prosody/prosody.cfg.lua" + owner: prosody + group: root + mode: '0640' + vars: + wan_ip: "{{ router_wan_ip.stdout }}" + notify: restart prosody diff --git a/roles/prosody/templates/prosody/prosody.cfg.lua.j2 b/roles/prosody/templates/prosody/prosody.cfg.lua.j2 new file mode 100644 index 0000000..7ab32a5 --- /dev/null +++ b/roles/prosody/templates/prosody/prosody.cfg.lua.j2 @@ -0,0 +1,137 @@ +pidfile = "/run/prosody/prosody.pid" +plugin_paths = { "/etc/prosody/prosody-modules" } +admins = { "pyrschtjag@talk.oyacoi.ru" } +http_check_client_ip = false +interfaces = { "*" } +http_interfaces = { "*" } +https_interfaces = { } +trusted_proxies = { "127.0.0.1", "{{ hostvars['haproxy'].ip }}" } +external_addresses = { "{{ wan_ip }}" } +consider_websocket_secure = true +certificates = "certs" +c2s_direct_tls_ports = { 5223 } +s2s_direct_tls_ports = { 5270 } +c2s_require_encryption = true +s2s_require_encryption = true +s2s_secure_auth = true +tls_profile = "intermediate" +contact_info = { + abuse = { "xmpp:pyrschtjag@talk.oyacoi.ru" }; + admin = { "xmpp:pyrschtjag@talk.oyacoi.ru" }; +} +modules_enabled = { + -- Core + "disco"; + "roster"; + "saslauth"; + "tls"; + "dialback"; + "s2s_auth_certs"; + "limits"; + "mam"; + "smacks"; + "carbons"; + "pep"; + "private"; + "s2s_bidi"; + "vcard4"; + "vcard_legacy"; + "bookmarks"; + "blocklist"; + "account_activity"; + "pubsub"; + "csi_simple"; + "cloud_notify"; + "cloud_notify_extensions"; + "throttle_presence"; + "register"; + "ping"; + "uptime"; + "version"; + "time"; + "server_contact_info"; + "admin_adhoc"; + "admin_shell"; + "bosh"; + "websocket"; + "http"; + "turn_external"; + "external_services"; + "sasl2"; + "sasl2_bind2"; +} +storage = "sql" +sql = { + driver = "PostgreSQL"; + database = "prosody"; + username = "prosody_user"; + password = "{{ database_password }}"; + host = "{{ hostvars['pgsql'].ip }}"; +} +archive_expires_after = "1y" +max_archive_query_results = 20 +network_settings = { + read_timeout = 840; +} +smacks_max_unacked_stanzas = 500 +smacks_hibernation_time = 300 +limits = { + c2s = { rate = "500kb/s" }; + s2sin = { rate = "50kb/s" }; +} +authentication = "internal_hashed" +allow_registration = false +turn_external_host = "turn.oyacoi.ru" +turn_external_secret = "{{ hostvars['coturn']['turn_external_secret'] }}" +external_services = { + { type = "stun", transport = "udp", host = "turn.oyacoi.ru", port = 3478 }, + { type = "stun", transport = "tcp", host = "turn.oyacoi.ru", port = 3478 }, + { type = "turn", transport = "udp", host = "turn.oyacoi.ru", port = 3478 }, + { type = "turn", transport = "tcp", host = "turn.oyacoi.ru", port = 3478 }, + { type = "stuns", transport = "tcp", host = "turn.oyacoi.ru", port = 5349 }, + { type = "turns", transport = "tcp", host = "turn.oyacoi.ru", port = 5349 } +} +log = { + info = "/var/log/prosody/prosody.log"; + error = "/var/log/prosody/prosody.err"; + { levels = { "error" }; to = "syslog"; }; +} +VirtualHost "talk.oyacoi.ru" + disco_items = { + { "conference.oyacoi.ru", "Chatrooms" }; + { "upload.oyacoi.ru", "File Storage" }; + { "proxy.oyacoi.ru", "File Transfer Relay" }; + { "pubsub.oyacoi.ru", "PubSub Service" }; + } + ssl = { + key = "/etc/prosody/certs/talk.oyacoi.ru.key"; + certificate = "/etc/prosody/certs/talk.oyacoi.ru.crt"; + } +Component "conference.oyacoi.ru" "muc" + modules_enabled = { "muc_mam", "muc_moderation" } + restrict_room_creation = "local" + muc_log_by_default = true + muc_log_expires_after = "1w" + ssl = { + key = "/etc/prosody/certs/conference.oyacoi.ru.key"; + certificate = "/etc/prosody/certs/conference.oyacoi.ru.crt"; + } +Component "upload.oyacoi.ru" "http_file_share" + http_path = { file_share = "/" } + http_external_url = "https://upload.oyacoi.ru/" + http_file_share_access = { "talk.oyacoi.ru" } + http_file_share_size_limit = 1024 * 1024 * 1024 + http_file_share_expires_after = "31 days" +Component "proxy.oyacoi.ru" "proxy65" + proxy65_address = "proxy.oyacoi.ru" + proxy65_acl = { "talk.oyacoi.ru" } + ssl = { + key = "/etc/prosody/certs/proxy.oyacoi.ru.key"; + certificate = "/etc/prosody/certs/proxy.oyacoi.ru.crt"; + } +Component "pubsub.oyacoi.ru" "pubsub" + public_subscriptions = true + ssl = { + key = "/etc/prosody/certs/pubsub.oyacoi.ru.key"; + certificate = "/etc/prosody/certs/pubsub.oyacoi.ru.crt"; + } diff --git a/roles/prowlarr/files/prowlarr.service b/roles/prowlarr/files/prowlarr.service new file mode 100644 index 0000000..5c3a6ab --- /dev/null +++ b/roles/prowlarr/files/prowlarr.service @@ -0,0 +1,18 @@ +[Unit] +Description=Prowlarr +Documentation=https://github.com/Prowlarr/Prowlarr/ +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=prowlarr +Group=prowlarr +ExecStart=/opt/prowlarr/Prowlarr /nobrowser /data=/var/lib/prowlarr/data +Restart=on-failure +RestartSec=5 +TimeoutStopSec=30 +UMask=0027 + +[Install] +WantedBy=multi-user.target diff --git a/roles/prowlarr/handlers/main.yml b/roles/prowlarr/handlers/main.yml new file mode 100644 index 0000000..a5c1c91 --- /dev/null +++ b/roles/prowlarr/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart prowlarr + ansible.builtin.systemd: + name: prowlarr + state: restarted + enabled: true + daemon_reload: true diff --git a/roles/prowlarr/tasks/main.yml b/roles/prowlarr/tasks/main.yml new file mode 100644 index 0000000..65c3c9f --- /dev/null +++ b/roles/prowlarr/tasks/main.yml @@ -0,0 +1,160 @@ +--- +- name: create prowlarr group + ansible.builtin.group: + name: prowlarr + system: true + state: present + +- name: create prowlarr user + ansible.builtin.user: + name: prowlarr + group: prowlarr + system: true + shell: /usr/sbin/nologin + home: /var/lib/prowlarr + create_home: true + state: present + +- name: get latest prowlarr release info + ansible.builtin.uri: + url: https://api.github.com/repos/Prowlarr/Prowlarr/releases/latest + return_content: yes + register: prowlarr_release + run_once: true + check_mode: false + +- name: set current prowlarr version + ansible.builtin.set_fact: + prowlarr_version: "{{ prowlarr_release.json.tag_name | regex_replace('^v', '') }}" + prowlarr_asset_url: "{{ prowlarr_release.json.assets | selectattr('name', 'search', '.linux-core-x64.tar.gz') | map(attribute='browser_download_url') | first }}" + +- name: check prowlarr installed version + ansible.builtin.shell: > + /opt/prowlarr/Prowlarr -? | head -n1 | grep -oP 'Version \K[\d.]+' + register: prowlarr_current_version + changed_when: false + failed_when: false + +- name: display prowlarr version info + ansible.builtin.debug: + msg: "latest version: {{ prowlarr_version }}, installed version: {{ prowlarr_current_version.stdout | default('not installed', true) }}" + +- name: ensure prowlarr directory exists + ansible.builtin.file: + path: /opt/prowlarr + state: directory + owner: root + group: root + mode: "0755" + +- name: update prowlarr + ansible.builtin.unarchive: + src: "{{ prowlarr_asset_url }}" + dest: /opt/prowlarr + remote_src: yes + owner: root + group: root + extra_opts: + - --strip-components=1 + when: prowlarr_version != (prowlarr_current_version.stdout | default('')) + notify: restart prowlarr + +- name: make prowlarr binary executable + ansible.builtin.file: + path: /opt/prowlarr/Prowlarr + mode: "0755" + +- name: deploy prowlarr systemd service unit + ansible.builtin.copy: + src: prowlarr.service + dest: /etc/systemd/system/prowlarr.service + mode: "0644" + notify: restart prowlarr + +- name: ensure prowlarr config directory exists + ansible.builtin.file: + path: /etc/prowlarr + state: directory + owner: root + group: root + mode: "0755" + +- name: stat prowlarr config in data dir + ansible.builtin.stat: + path: /var/lib/prowlarr/config.xml + register: prowlarr_config_stat + +- name: remove config.xml if it is not a symlink + ansible.builtin.file: + path: /var/lib/prowlarr/config.xml + state: absent + when: + - prowlarr_config_stat.stat.exists + - not prowlarr_config_stat.stat.islnk + +- name: check if prowlarr data directory is a mountpoint + ansible.builtin.command: mountpoint -q /var/lib/prowlarr/data + register: vw_mountpoint + failed_when: false + changed_when: false + +- name: ensure prowlarr data source directory exists + ansible.builtin.file: + path: /mnt/prowlarr/data + state: directory + owner: prowlarr + group: prowlarr + mode: "0755" + +- name: bind mount prowlarr data directory + ansible.posix.mount: + path: /var/lib/prowlarr/data + src: /mnt/prowlarr/data + fstype: none + opts: bind + state: mounted + notify: restart prowlarr + +- name: set prowlarr data directory ownership + ansible.builtin.file: + path: /mnt/prowlarr/data + owner: prowlarr + group: prowlarr + recurse: true + +- name: ensure prowlarr config directory exists + ansible.builtin.file: + path: /etc/prowlarr + state: directory + owner: root + group: root + mode: "0755" + +- name: deploy prowlarr config + ansible.builtin.template: + src: "{{ inventory_hostname }}/config.xml.j2" + dest: /etc/prowlarr/config.xml + owner: prowlarr + group: prowlarr + mode: "0640" + notify: restart prowlarr + +- name: stat prowlarr config in data dir + ansible.builtin.stat: + path: /var/lib/prowlarr/data/config.xml + register: prowlarr_config_stat + +- name: remove config.xml if it is not a symlink + ansible.builtin.file: + path: /var/lib/prowlarr/data/config.xml + state: absent + when: + - prowlarr_config_stat.stat.exists + - not prowlarr_config_stat.stat.islnk + +- name: symlink prowlarr config + ansible.builtin.file: + src: /etc/prowlarr/config.xml + dest: /var/lib/prowlarr/data/config.xml + state: link + notify: restart prowlarr diff --git a/roles/prowlarr/templates/prowlarr/config.xml.j2 b/roles/prowlarr/templates/prowlarr/config.xml.j2 new file mode 100644 index 0000000..ab5e4c4 --- /dev/null +++ b/roles/prowlarr/templates/prowlarr/config.xml.j2 @@ -0,0 +1,20 @@ + + * + 9696 + 6969 + False + True + {{ prowlarr_api_key }} + Forms + DisabledForLocalAddresses + {{ dnsmasq[0].name }} + master + info + + + + {{ hostvars["nginx"].ip }} + Prowlarr + False + False + \ No newline at end of file diff --git a/roles/ps3netsrv/handlers/main.yml b/roles/ps3netsrv/handlers/main.yml new file mode 100644 index 0000000..b60fc29 --- /dev/null +++ b/roles/ps3netsrv/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart ps3netsrv + ansible.builtin.systemd_service: + name: ps3netsrv + state: restarted + enabled: true + daemon_reload: true diff --git a/roles/ps3netsrv/tasks/main.yml b/roles/ps3netsrv/tasks/main.yml new file mode 100644 index 0000000..d05e1fb --- /dev/null +++ b/roles/ps3netsrv/tasks/main.yml @@ -0,0 +1,182 @@ +--- +- name: create ps3netsrv group + ansible.builtin.group: + name: ps3netsrv + system: true + state: present + +- name: create media group + ansible.builtin.group: + name: media + gid: 1000 + state: present + +- name: create ps3netsrv user + ansible.builtin.user: + name: ps3netsrv + group: ps3netsrv + groups: media + append: yes + system: true + shell: /usr/sbin/nologin + home: /var/lib/ps3netsrv + create_home: false + state: present + +- name: install depenedencies + ansible.builtin.package: + name: + - unzip + - binutils + state: latest + update_cache: true + +- name: get latest ps3netsrv release info + ansible.builtin.uri: + url: https://api.github.com/repos/aldostools/ps3netsrv/releases/latest + return_content: yes + register: ps3netsrv_release + run_once: true + check_mode: false + +- name: set current ps3netsrv version + ansible.builtin.set_fact: + ps3netsrv_version: "{{ ps3netsrv_release.json.tag_name | regex_replace('^v', '') }}" + ps3netsrv_asset_url: "{{ ps3netsrv_release.json.assets | selectattr('name', 'search', '_linux.zip') | map(attribute='browser_download_url') | first }}" + +- name: check ps3netsrv installed version + ansible.builtin.shell: > + strings "$(command -v ps3netsrv)" | grep -m1 -oE 'build [0-9]{8}' | awk '{print $2}' + register: ps3netsrv_current_version + changed_when: false + failed_when: false + +- name: display ps3netsrv version info + ansible.builtin.debug: + msg: "latest version: {{ ps3netsrv_version }}, installed version: {{ ps3netsrv_current_version.stdout | default('') | trim | default('not installed', true) }}" + +- name: install ps3netsrv from release archive + when: ps3netsrv_version != (ps3netsrv_current_version.stdout | default('') | trim) + block: + - name: create temp dir + ansible.builtin.tempfile: + state: directory + prefix: ps3netsrv_ + register: ps3netsrv_tmp + + - name: download and unpack release archive + ansible.builtin.unarchive: + src: "{{ ps3netsrv_asset_url }}" + dest: "{{ ps3netsrv_tmp.path }}" + remote_src: yes + + - name: find debian package + ansible.builtin.find: + paths: "{{ ps3netsrv_tmp.path }}" + patterns: "ps3netsrv_debian-latest_amd64.deb" + recurse: yes + register: ps3netsrv_deb + + - name: install ps3netsrv deb + ansible.builtin.apt: + deb: "{{ ps3netsrv_deb.files[0].path }}" + state: present + notify: restart ps3netsrv + + always: + - name: remove temp dir + ansible.builtin.file: + path: "{{ ps3netsrv_tmp.path }}" + state: absent + when: ps3netsrv_tmp.path is defined + +- name: deploy ps3netsrv systemd service unit + ansible.builtin.template: + src: "{{ inventory_hostname }}/ps3netsrv.service.j2" + dest: /etc/systemd/system/ps3netsrv.service + mode: "0644" + notify: restart ps3netsrv + +- name: ensure ps3netsrv directories exist + ansible.builtin.file: + path: "{{ ps3_dst }}/{{ item }}" + state: directory + mode: "2770" + loop: [GAMES, PKG, PS3ISO] + +- name: find extracted games + ansible.builtin.find: + paths: "{{ ps3_src }}" + patterns: PS3_GAME + file_type: directory + recurse: true + register: ps3_games + +- name: find pkg files + ansible.builtin.find: + paths: "{{ ps3_src }}" + patterns: '(?i).*\.pkg$' + use_regex: true + recurse: true + register: ps3_pkgs + +- name: find iso files + ansible.builtin.find: + paths: "{{ ps3_src }}" + patterns: '(?i).*\.iso$' + use_regex: true + recurse: true + register: ps3_isos + +- name: refuse to continue if library looks empty + ansible.builtin.assert: + that: ps3_games.matched > 0 or ps3_pkgs.matched > 0 or ps3_isos.matched > 0 + fail_msg: "{{ ps3_src }} is empty or inaccessible" + +- name: link games + ansible.builtin.file: + src: "{{ item | dirname }}" + dest: "{{ ps3_dst }}/GAMES/{{ item | dirname | basename }}" + state: link + loop: "{{ ps3_games.files | map(attribute='path') | list }}" + loop_control: + label: "{{ item | dirname | basename }}" + +- name: link pkg files + ansible.builtin.file: + src: "{{ item }}" + dest: "{{ ps3_dst }}/PKG/{{ item | dirname | basename }} - {{ item | basename }}" + state: link + loop: "{{ ps3_pkgs.files | map(attribute='path') | reject('search', '/PS3_GAME/') | list }}" + loop_control: + label: "{{ item | basename }}" + +- name: link iso files + ansible.builtin.file: + src: "{{ item }}" + dest: "{{ ps3_dst }}/PS3ISO/{{ item | basename }}" + state: link + loop: "{{ ps3_isos.files | map(attribute='path') | list }}" + loop_control: + label: "{{ item | basename }}" + +- name: find broken symlinks + ansible.builtin.command: + argv: + - find + - "{{ ps3_dst }}/GAMES" + - "{{ ps3_dst }}/PKG" + - "{{ ps3_dst }}/PS3ISO" + - -maxdepth + - "1" + - -xtype + - l + register: ps3_broken + changed_when: false + check_mode: false + +- name: remove broken symlinks + ansible.builtin.file: + path: "{{ item }}" + state: absent + loop: "{{ ps3_broken.stdout_lines }}" diff --git a/roles/ps3netsrv/templates/ps3netsrv/ps3netsrv.service.j2 b/roles/ps3netsrv/templates/ps3netsrv/ps3netsrv.service.j2 new file mode 100644 index 0000000..9a2522b --- /dev/null +++ b/roles/ps3netsrv/templates/ps3netsrv/ps3netsrv.service.j2 @@ -0,0 +1,15 @@ +[Unit] +Description=ps3netsrv +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=ps3netsrv +Group=ps3netsrv +ExecStart=ps3netsrv /mnt/media2/.ps3netsrv 38008 {{ hostvars["ps3"].ip }} +Restart=on-failure +RestartSec=5 + +[Install] +WantedBy=multi-user.target diff --git a/roles/radicale/files/radicale.service b/roles/radicale/files/radicale.service new file mode 100644 index 0000000..a09b185 --- /dev/null +++ b/roles/radicale/files/radicale.service @@ -0,0 +1,14 @@ +[Unit] +Description=A simple CalDAV and CardDAV server +After=network.target + +[Service] +Type=simple +User=radicale +Group=radicale +ExecStart=/usr/bin/python3 -m radicale --config /etc/radicale/config +Restart=on-failure +PrivateTmp=true + +[Install] +WantedBy=multi-user.target diff --git a/roles/radicale/handlers/main.yml b/roles/radicale/handlers/main.yml new file mode 100644 index 0000000..968cd15 --- /dev/null +++ b/roles/radicale/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart radicale + ansible.builtin.systemd: + name: radicale + state: restarted + enabled: true + daemon_reload: true diff --git a/roles/radicale/tasks/main.yml b/roles/radicale/tasks/main.yml new file mode 100644 index 0000000..d884eaa --- /dev/null +++ b/roles/radicale/tasks/main.yml @@ -0,0 +1,74 @@ +--- +- name: create radicale group + ansible.builtin.group: + name: radicale + system: true + state: present + +- name: create radicale user + ansible.builtin.user: + name: radicale + group: radicale + system: true + shell: /usr/sbin/nologin + home: /var/lib/radicale + create_home: true + state: present + +- name: install python3-radicale + ansible.builtin.apt: + name: python3-radicale + state: latest + update_cache: true + notify: restart radicale + +- name: ensure radicale data source directory exists + ansible.builtin.file: + path: /mnt/radicale/data + state: directory + owner: radicale + group: radicale + mode: "0755" + +- name: bind mount radicale data directory + ansible.posix.mount: + path: /var/lib/radicale + src: /mnt/radicale/data + fstype: none + opts: bind + state: mounted + notify: restart radicale + +- name: set radicale data directory ownership + ansible.builtin.file: + path: /mnt/radicale/data + owner: radicale + group: radicale + recurse: true + +- name: ensure radicalec config directory exists + ansible.builtin.file: + path: /etc/radicale + state: directory + owner: root + group: root + mode: "0755" + +- name: deploy radicale config + ansible.builtin.template: + src: "{{ item }}" + dest: "/etc/radicale/{{ item | basename | regex_replace('\\.j2$', '') }}" + owner: root + group: root + mode: "0644" + loop: "{{ query('ansible.builtin.fileglob', role_path + '/templates/' + inventory_hostname + '/*.j2') }}" + notify: restart radicale + +- name: deploy radicale.service + ansible.builtin.copy: + src: radicale.service + dest: /etc/systemd/system/radicale.service + owner: root + group: root + mode: '0644' + notify: restart radicale diff --git a/roles/radicale/templates/radicale/config.j2 b/roles/radicale/templates/radicale/config.j2 new file mode 100644 index 0000000..d943e12 --- /dev/null +++ b/roles/radicale/templates/radicale/config.j2 @@ -0,0 +1,14 @@ +[server] +hosts = 0.0.0.0:5232 +[encoding] +[auth] +type = htpasswd +htpasswd_filename = /etc/radicale/users +htpasswd_encryption = sha256 +[rights] +[storage] +[web] +[logging] +[headers] +[hook] +[reporting] diff --git a/roles/radicale/templates/radicale/users.j2 b/roles/radicale/templates/radicale/users.j2 new file mode 100644 index 0000000..add109e --- /dev/null +++ b/roles/radicale/templates/radicale/users.j2 @@ -0,0 +1,3 @@ +{% for item in radicale_users %} +{{ item.name }}:{{ item.password | password_hash('sha256') }} +{% endfor %} diff --git a/roles/resolv/tasks/main.yml b/roles/resolv/tasks/main.yml new file mode 100644 index 0000000..f6b3421 --- /dev/null +++ b/roles/resolv/tasks/main.yml @@ -0,0 +1,8 @@ +--- +- name: set namespaces + ansible.builtin.template: + src: templates/resolv.conf.j2 + dest: /etc/resolv.conf + owner: root + group: root + mode: '0644' diff --git a/roles/resolv/templates/resolv.conf.j2 b/roles/resolv/templates/resolv.conf.j2 new file mode 100644 index 0000000..9785fa2 --- /dev/null +++ b/roles/resolv/templates/resolv.conf.j2 @@ -0,0 +1,3 @@ +{% for item in nameservers %} +nameserver {{ item }} +{% endfor %} diff --git a/roles/rtorrent/files/rtorrent.service b/roles/rtorrent/files/rtorrent.service new file mode 100644 index 0000000..766686d --- /dev/null +++ b/roles/rtorrent/files/rtorrent.service @@ -0,0 +1,16 @@ +[Unit] +Description=rTorrent +After=network.target + +[Service] +Type=simple +User=rtorrent +Group=rtorrent +WorkingDirectory=/var/lib/rtorrent +ExecStart=/usr/bin/rtorrent -n -o import=/etc/rtorrent/.rtorrent.rc +Restart=on-failure +RestartSec=5 +LimitNOFILE=65536 + +[Install] +WantedBy=multi-user.target diff --git a/roles/rtorrent/handlers/main.yml b/roles/rtorrent/handlers/main.yml new file mode 100644 index 0000000..81284e0 --- /dev/null +++ b/roles/rtorrent/handlers/main.yml @@ -0,0 +1,19 @@ +--- +- name: restart rtorrent + ansible.builtin.systemd_service: + name: rtorrent + state: restarted + enabled: true + daemon_reload: true + +- name: restart apache + ansible.builtin.systemd: + name: apache2 + enabled: true + state: reloaded + +- name: restart php-fpm + ansible.builtin.systemd: + name: php{{ php_version.stdout }}-fpm + enabled: true + state: reloaded diff --git a/roles/rtorrent/tasks/main.yml b/roles/rtorrent/tasks/main.yml new file mode 100644 index 0000000..e6ed16d --- /dev/null +++ b/roles/rtorrent/tasks/main.yml @@ -0,0 +1,359 @@ +--- +- name: install dependencies + ansible.builtin.apt: + name: + - git + - apache2 + - php-fpm + - php-curl + - php-xml + - php-mbstring + - php-zip + - python3 + - python3-cloudscraper + - sox + - mediainfo + - ffmpeg + - zip + - unzip + - unrar-free + - curl + - sudo + state: present + update_cache: yes + notify: + - restart apache + - restart php-fpm + +- name: get current php-fpm version + ansible.builtin.shell: php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;' + register: php_version + changed_when: false + +- name: get latest dumptorrent release info + ansible.builtin.uri: + url: https://api.github.com/repos/tomcdj71/dumptorrent/releases/latest + return_content: yes + register: dumptorrent_release + run_once: true + check_mode: false + +- name: set current dumptorrent version + ansible.builtin.set_fact: + dumptorrent_version: "{{ dumptorrent_release.json.tag_name | regex_replace('^v', '') }}" + dumptorrent_asset_url: "{{ dumptorrent_release.json.assets | selectattr('name', 'search', 'ubuntu-latest_amd64.deb') | map(attribute='browser_download_url') | first }}" + +- name: check dumptorrent installed version + ansible.builtin.shell: dumptorrent -V | grep -oP '\d+\.\d+\.\d+' + register: dumptorrent_current_version + changed_when: false + failed_when: false + +- name: display dumptorrent version info + ansible.builtin.debug: + msg: "latest version: {{ dumptorrent_version }}, installed version: {{ dumptorrent_current_version.stdout | default('not installed', true) }}" + +- name: download and install dumptorrent + ansible.builtin.apt: + deb: "{{ dumptorrent_asset_url }}" + when: dumptorrent_version not in (dumptorrent_current_version.stdout | default('')) + +- name: create media group + ansible.builtin.group: + name: media + gid: 1000 + state: present + +- name: create rtorrent group + ansible.builtin.group: + name: rtorrent + system: true + state: present + +- name: create rtorrent user + ansible.builtin.user: + name: rtorrent + group: rtorrent + groups: media + append: yes + system: true + shell: /usr/sbin/nologin + home: /var/lib/rtorrent + create_home: true + state: present + +- name: add www-data to rtorrent group + ansible.builtin.user: + name: www-data + groups: rtorrent + append: yes + notify: restart apache + +- name: ensure rtorrent data directory exists + ansible.builtin.file: + path: /var/lib/rtorrent + owner: rtorrent + group: rtorrent + state: directory + mode: "0750" + +- name: ensure rtorrent run directory exists + ansible.builtin.file: + path: /var/run/rtorrent + owner: rtorrent + group: rtorrent + state: directory + mode: "0755" + +- name: ensure rtorrent log directory exists + ansible.builtin.file: + path: /var/log/rtorrent + owner: rtorrent + group: rtorrent + state: directory + mode: "0755" + +- name: install rtorrent + ansible.builtin.apt: + name: rtorrent + state: latest + update_cache: true + notify: restart rtorrent + +- name: fetch wan ip + ansible.builtin.shell: ssh -o StrictHostKeyChecking=no root@{{ hostvars['router'].ip }} "ip -4 addr show eth1 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'" + delegate_to: localhost + register: router_wan_ip + changed_when: false + vars: + ansible_connection: local + +- name: ensure rtorrent config directory exists + ansible.builtin.file: + path: /etc/rtorrent + owner: root + group: root + state: directory + mode: "0755" + +- name: deploy rtorrent config + ansible.builtin.template: + src: "{{ inventory_hostname }}/.rtorrent.rc.j2" + dest: "/etc/rtorrent/.rtorrent.rc" + owner: rtorrent + group: rtorrent + mode: "0640" + vars: + wan_ip: "{{ router_wan_ip.stdout }}" + notify: restart rtorrent + +- name: ensure rtorrent session directory is a mountpoint + ansible.builtin.command: mountpoint -q /var/lib/rtorrent/session + register: session_mountpoint + failed_when: false + changed_when: false + +- name: ensure rtorrent session source directory exists + ansible.builtin.file: + path: /mnt/rtorrent/session + state: directory + owner: rtorrent + group: rtorrent + mode: "0755" + +- name: bind mount rtorrent session directory + ansible.posix.mount: + path: /var/lib/rtorrent/session + src: /mnt/rtorrent/session + fstype: none + opts: bind + state: mounted + notify: restart rtorrent + +- name: set rtorrent session directory ownership + ansible.builtin.file: + path: /mnt/rtorrent/session + owner: rtorrent + group: rtorrent + recurse: true + +- name: ensure ansible remote tmp dir exists + ansible.builtin.file: + path: /tmp/.ansible-www-data + state: directory + owner: www-data + group: www-data + mode: "0700" + +- name: check current rutorrent git remote + ansible.builtin.command: git -C /var/www/html remote get-url origin + become: yes + become_user: www-data + register: current_remote + failed_when: false + changed_when: false + vars: + ansible_remote_tmp: /tmp/.ansible-www-data + +- name: get latest rutorrent release info + ansible.builtin.uri: + url: "https://api.github.com/repos/Novik/ruTorrent/releases/latest" + return_content: yes + register: rutorrent_release + run_once: true + check_mode: false + +- name: set current rutorrent version + ansible.builtin.set_fact: + rutorrent_version: "{{ rutorrent_release.json.tag_name | regex_replace('^v', '') }}" + +- name: check rutorrent installed version + ansible.builtin.command: grep -oP 'version:\s*"\K[^"]+' /var/www/html/js/webui.js + register: rutorrent_current_version + changed_when: false + failed_when: false + +- name: ensure html share directory is a mountpoint + ansible.builtin.command: mountpoint -q /var/www/html/share + register: share_mountpoint + failed_when: false + changed_when: false + +- name: unmount rutorrent share directory before update + ansible.posix.mount: + path: /var/www/html/share + state: unmounted + when: + - share_mountpoint.rc == 0 + - rutorrent_version not in (rutorrent_current_version.stdout | default('')) + +- name: remove irrelevant html directory + ansible.builtin.file: + path: /var/www/html + state: absent + when: + - current_remote.rc is defined + - current_remote.rc != 0 + - rutorrent_version not in (rutorrent_current_version.stdout | default('')) + +- name: display rutorrent version info + ansible.builtin.debug: + msg: "latest version: {{ rutorrent_version }}, installed version: {{ rutorrent_current_version.stdout | default('not installed', true) }}" + +- name: clone rutorrent + ansible.builtin.git: + repo: "https://github.com/Novik/ruTorrent.git" + dest: "/var/www/html" + version: "v{{ rutorrent_version }}" + force: yes + when: rutorrent_version not in (rutorrent_current_version.stdout | default('')) + +- name: set rutorrent directory ownership + ansible.builtin.file: + path: /var/www/html + owner: www-data + group: www-data + recurse: yes + when: rutorrent_version not in (rutorrent_current_version.stdout | default('')) + +- name: remove default share directory + ansible.builtin.file: + path: /var/www/html/share + state: absent + when: rutorrent_version not in (rutorrent_current_version.stdout | default('')) + +- name: ensure rutorrent share source directory exists + ansible.builtin.file: + path: /mnt/rutorrent/share + state: directory + owner: www-data + group: www-data + mode: "0755" + +- name: bind mount rutorrent share directory + ansible.posix.mount: + path: /var/www/html/share + src: /mnt/rtorrent/share + fstype: none + opts: bind + state: mounted + notify: restart apache + +- name: set rutorrent share subdirectories ownership + ansible.builtin.file: + path: "/mnt/rtorrent/share/{{ item }}" + owner: www-data + group: www-data + recurse: true + loop: + - settings + - torrents + - users + +- name: set rutorrent share tmp ownership + ansible.builtin.file: + path: /mnt/rtorrent/share/tmp + owner: rtorrent + group: rtorrent + recurse: true + +- name: deploy rutorrent config + ansible.builtin.template: + src: "{{ inventory_hostname }}/config.php.j2" + dest: "/var/www/html/conf/config.php" + owner: www-data + group: www-data + mode: "0644" + notify: restart apache + +- name: deploy rutorrent plugin config + ansible.builtin.template: + src: "{{ inventory_hostname }}/plugin.ini.j2" + dest: "/var/www/html/conf/plugin.ini" + owner: www-data + group: www-data + mode: "0644" + notify: restart apache + +- name: enable required apache modules + community.general.apache2_module: + name: "{{ item }}" + state: present + loop: + - proxy + - proxy_fcgi + - proxy_scgi + - rewrite + - setenvif + - headers + notify: restart apache + +- name: deploy rutorrent apache vhost + ansible.builtin.template: + src: "{{ inventory_hostname }}/rutorrent.conf.j2" + dest: "/etc/apache2/sites-available/rutorrent.conf" + owner: root + group: root + mode: '0644' + notify: restart apache + +- name: enable rutorrent site + ansible.builtin.command: a2ensite rutorrent + args: + creates: /etc/apache2/sites-enabled/rutorrent.conf + notify: restart apache + +- name: disable default apache site + ansible.builtin.command: a2dissite 000-default + args: + removes: /etc/apache2/sites-enabled/000-default.conf + notify: restart apache + +- name: deploy rtorrent service + ansible.builtin.copy: + src: rtorrent.service + dest: /etc/systemd/system/rtorrent.service + owner: root + group: root + mode: '0644' + notify: restart rtorrent diff --git a/roles/rtorrent/templates/rtorrent/.rtorrent.rc.j2 b/roles/rtorrent/templates/rtorrent/.rtorrent.rc.j2 new file mode 100644 index 0000000..40cb36a --- /dev/null +++ b/roles/rtorrent/templates/rtorrent/.rtorrent.rc.j2 @@ -0,0 +1,43 @@ +method.insert = cfg.basedir, private|const|string, (cat, "/var/lib/rtorrent/") +method.insert = cfg.download, private|const|string, (cat, "/mnt/media1/downloads/") +method.insert = cfg.session, private|const|string, (cat, (cfg.basedir), "session/") +method.insert = cfg.logs, private|const|string, (cat, "/var/log/rtorrent/") +method.insert = cfg.logfile, private|const|string, (cat, (cfg.logs), "rtorrent.log") +execute.throw = sh, -c, (cat,\ + "mkdir -p \"", (cfg.session), "\" ",\ + "\"", (cfg.logs), "\" ") +throttle.global_down.max_rate.set_kb = 8192 +throttle.global_up.max_rate.set_kb = 8192 +network.http.max_open.set = 50 +network.max_open_files.set = 600 +network.max_open_sockets.set = 300 +network.local_address.set = {{ wan_ip }} +network.port_range.set = 6890-6899 +network.port_random.set = yes +dht.mode.set = auto +protocol.pex.set = yes +protocol.encryption.set = allow_incoming,try_outgoing,enable_retry +system.daemon.set = true +#network.rpc.use_xmlrpc.set = true +#network.xmlrpc.dialect.set = 1.1 +network.scgi.open_local = /run/rtorrent/rpc.sock +execute.nothrow = chmod, 770, /run/rtorrent/rpc.sock +encoding.add = UTF-8 +system.umask.set = 0002 +session.path.set = (cat, (cfg.session)) +directory.default.set = (cat, (cfg.download)) +system.cwd.set = (directory.default) +schedule2 = w_apps, 10, 10, "load.start=/mnt/media1/.torrents/apps/*.torrent,d.directory.set=/mnt/media1/apps/,d.custom1.set=apps" +schedule2 = w_games, 11, 10, "load.start=/mnt/media1/.torrents/games/*.torrent,d.directory.set=/mnt/media1/games/,d.custom1.set=games" +schedule2 = w_movies, 12, 10, "load.start=/mnt/media1/.torrents/movies/*.torrent,d.directory.set=/mnt/media1/movies/,d.custom1.set=movies" +schedule2 = w_music, 13, 10, "load.start=/mnt/media1/.torrents/music/*.torrent,d.directory.set=/mnt/media1/music/,d.custom1.set=music" +schedule2 = w_shows, 14, 10, "load.start=/mnt/media1/.torrents/shows/*.torrent,d.directory.set=/mnt/media1/shows/,d.custom1.set=shows" +schedule2 = w_ps1, 15, 10, "load.start=/mnt/media1/.torrents/ps1/*.torrent,d.directory.set=/mnt/media1/ps1/,d.custom1.set=ps1" +schedule2 = w_ps2, 16, 10, "load.start=/mnt/media1/.torrents/ps2/*.torrent,d.directory.set=/mnt/media1/ps2/,d.custom1.set=ps2" +schedule2 = w_ps3, 17, 10, "load.start=/mnt/media1/.torrents/ps3/*.torrent,d.directory.set=/mnt/media2/ps3/,d.custom1.set=ps3" +schedule2 = w_psp, 18, 10, "load.start=/mnt/media1/.torrents/psp/*.torrent,d.directory.set=/mnt/media1/psp/,d.custom1.set=psp" +schedule2 = w_ds, 19, 10, "load.start=/mnt/media1/.torrents/ds/*.torrent,d.directory.set=/mnt/media1/ds/,d.custom1.set=ds" +log.open_file = "log", (cfg.logfile) +log.add_output = "critical", "log" +log.add_output = "error", "log" +log.add_output = "warn", "log" diff --git a/roles/rtorrent/templates/rtorrent/config.php.j2 b/roles/rtorrent/templates/rtorrent/config.php.j2 new file mode 100644 index 0000000..825a134 --- /dev/null +++ b/roles/rtorrent/templates/rtorrent/config.php.j2 @@ -0,0 +1,56 @@ + false, + 'proto' => 'http', + 'host' => 'PROXY_HOST_HERE', + 'port' => 3128 + ); + $rpcTimeOut = 5; + $rpcLogCalls = false; + $rpcLogFaults = true; + $phpUseGzip = false; + $phpGzipLevel = 2; + $schedule_rand = 10; + $do_diagnostic = true; + $al_diagnostic = true; + $log_file = $_ENV['RU_LOG_FILE'] ?? '/tmp/errors.log'; + $saveUploadedTorrents = true; + $overwriteUploadedTorrents = false; + $topDirectory = $_ENV['RU_TOP_DIR'] ?? '/'; + $forbidUserSettings = false; + $scgi_port = 0; + $scgi_host = "unix:///run/rtorrent/rpc.sock"; + $XMLRPCMountPoint = "/RPC2"; + $throttleMaxSpeed = 327625*1024; + $pathToExternals = array( + "php" => '/bin/php', + "curl" => '/bin/curl', + "gzip" => '/bin/gzip', + "id" => '/bin/id', + "stat" => '/bin/stat', + "python" => '/usr/bin/python3' + ); + $localHostedMode = false; + $cachedPluginLoading = false; + $pluginMinification = true; + $localhosts = array( + "::1", + "127.0.0.1", + "localhost", + ); + getenv("RU_LOCALHOSTS") && $localhosts[] = $_ENV['RU_LOCALHOSTS']; + $profilePath = $_ENV['RU_PROFILE_PATH'] ?? '../../share'; + $profileMask = $_ENV['RU_PROFILE_MASK'] ?? 0777; + $tempDirectory = '/var/www/html/share/tmp'; + $canUseXSendFile = false; + $locale = "UTF8"; + $enableCSRFCheck = false; + $enabledOrigins = array(); + $configLocalPath = dirname(__FILE__)."/config.local.php"; + if(is_file($configLocalPath) && is_readable($configLocalPath)) + require($configLocalPath); diff --git a/roles/rtorrent/templates/rtorrent/plugin.ini.j2 b/roles/rtorrent/templates/rtorrent/plugin.ini.j2 new file mode 100644 index 0000000..4105263 --- /dev/null +++ b/roles/rtorrent/templates/rtorrent/plugin.ini.j2 @@ -0,0 +1,13 @@ +[default] +enabled = user-defined +canChangeToolbar = yes +canChangeMenu = yes +canChangeOptions = yes +canChangeTabs = yes +canChangeColumns = yes +canChangeStatusBar = yes +canChangeCategory = yes +canBeShutdowned = yes + +[geoip] +enabled = no diff --git a/roles/rtorrent/templates/rtorrent/rutorrent.conf.j2 b/roles/rtorrent/templates/rtorrent/rutorrent.conf.j2 new file mode 100644 index 0000000..76d76dd --- /dev/null +++ b/roles/rtorrent/templates/rtorrent/rutorrent.conf.j2 @@ -0,0 +1,21 @@ + + ServerName {{ rutorrent_server_name | default(inventory_hostname) }} + DocumentRoot /var/www/html + + ErrorLog /var/log/apache2/rutorrent_error.log + CustomLog /var/log/apache2/rutorrent_access.log combined + + + Options -Indexes +FollowSymLinks + AllowOverride All + Require all granted + DirectoryIndex index.html + + + + SetHandler "proxy:unix:/run/php/php{{ php_version.stdout }}-fpm.sock|fcgi://localhost" + + + ProxyPass /RPC2 scgi://unix:/run/rtorrent/rpc.sock| + ProxyPassReverse /RPC2 scgi://unix:/run/rtorrent/rpc.sock| + diff --git a/roles/samba/handlers/main.yml b/roles/samba/handlers/main.yml new file mode 100644 index 0000000..f024563 --- /dev/null +++ b/roles/samba/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart samba + ansible.builtin.systemd: + name: smbd + state: restarted + enabled: true diff --git a/roles/samba/tasks/main.yml b/roles/samba/tasks/main.yml new file mode 100644 index 0000000..48525d3 --- /dev/null +++ b/roles/samba/tasks/main.yml @@ -0,0 +1,51 @@ +--- +- name: create media group + ansible.builtin.group: + name: media + gid: 1000 + state: present + +- name: install samba + ansible.builtin.apt: + name: samba + state: latest + update_cache: true + +- name: create samba users + ansible.builtin.user: + name: "{{ hostvars[item].smb_user }}" + shell: /usr/sbin/nologin + groups: media + append: true + create_home: false + state: present + loop: "{{ smb_managed_group | default([]) }}" + loop_control: + label: "{{ item }}" + when: > + hostvars[item].smb_user is defined and + hostvars[item].smb_container is defined and + inventory_hostname in hostvars[item].smb_container + +- name: set samba password for users + ansible.builtin.shell: | + printf '%s\n%s\n' "{{ hostvars[item].smb_password }}" "{{ hostvars[item].smb_password }}" | smbpasswd -s -a {{ hostvars[item].smb_user }} + loop: "{{ smb_managed_group | default([]) }}" + loop_control: + label: "{{ item }}" + when: > + hostvars[item].smb_user is defined and + hostvars[item].smb_password is defined and + hostvars[item].smb_container is defined and + inventory_hostname in hostvars[item].smb_container + changed_when: false + no_log: true + +- name: deploy samba config + ansible.builtin.template: + src: "{{ inventory_hostname }}/smb.conf.j2" + dest: "/etc/samba/smb.conf" + owner: root + group: root + mode: '0644' + notify: restart samba diff --git a/roles/samba/templates/smb-legacy/smb.conf.j2 b/roles/samba/templates/smb-legacy/smb.conf.j2 new file mode 100644 index 0000000..3728fa4 --- /dev/null +++ b/roles/samba/templates/smb-legacy/smb.conf.j2 @@ -0,0 +1,41 @@ +[global] + log file = /var/log/samba/%m.log + log level = 1 + max log size = 50 + smb ports = 445 139 + workgroup = WORKGROUP + server string = PS2 Samba Server + server role = standalone server + load printers = no + printing = bsd + printcap name = /dev/null + disable spoolss = yes + map to guest = Never + pam password change = yes + ntlm auth = yes + lanman auth = yes + server min protocol = NT1 + server signing = disabled + smb encrypt = disabled + create mask = 0664 + directory mask = 0775 + force group = media + socket options = TCP_NODELAY TCP_KEEPIDLE=20 IPTOS_LOWDELAY SO_KEEPALIVE + keepalive = 0 + large readwrite = yes + follow symlinks = yes + idmap config * : backend = tdb + idmap config * : range = 3000-7999 + +[PS2] + comment = PlayStation 2 + path = /mnt/media1/.ps2opl + browsable = yes + read only = no + guest ok = no +{% set users = smb_managed_group | default([]) | map('extract', hostvars) | selectattr('smb_user', 'defined') | selectattr('smb_container', 'defined') | selectattr('smb_container', 'contains', inventory_hostname) | map(attribute='smb_user') | list %} +{% if users | length > 0 %} + valid users = {{ users | join(' ') }} +{% endif %} + veto files = /._*/.apdisk/.AppleDouble/.DS_Store/.TemporaryItems/.Trashes/desktop.ini/ehthumbs.db/Network Trash Folder/Temporary Items/Thumbs.db/ + delete veto files = yes diff --git a/roles/slskd/files/slskd.service b/roles/slskd/files/slskd.service new file mode 100644 index 0000000..0226c95 --- /dev/null +++ b/roles/slskd/files/slskd.service @@ -0,0 +1,17 @@ +[Unit] +Description=slskd - Soulseek daemon +Documentation=https://github.com/slskd/slskd +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +WorkingDirectory=/opt/slskd +ExecStart=/opt/slskd/slskd --config /etc/slskd/slskd.yml --app-dir /var/lib/slskd +Restart=on-failure +RestartSec=5 +User=slskd +Group=slskd + +[Install] +WantedBy=multi-user.target diff --git a/roles/slskd/handlers/main.yml b/roles/slskd/handlers/main.yml new file mode 100644 index 0000000..ee782d3 --- /dev/null +++ b/roles/slskd/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart slskd + ansible.builtin.systemd_service: + name: slskd + state: restarted + enabled: true + daemon_reload: true diff --git a/roles/slskd/tasks/main.yml b/roles/slskd/tasks/main.yml new file mode 100644 index 0000000..acb6e47 --- /dev/null +++ b/roles/slskd/tasks/main.yml @@ -0,0 +1,135 @@ +--- +- name: create slskd group + ansible.builtin.group: + name: slskd + system: true + state: present + +- name: create media group + ansible.builtin.group: + name: media + gid: 1000 + state: present + +- name: create slskd user + ansible.builtin.user: + name: slskd + groups: slskd,media + system: true + shell: /usr/sbin/nologin + home: /var/lib/slskd + create_home: true + state: present + +- name: install unzip + ansible.builtin.package: + name: unzip + state: present + +- name: get latest slskd release info + ansible.builtin.uri: + url: https://api.github.com/repos/slskd/slskd/releases/latest + return_content: yes + register: slskd_release + run_once: true + check_mode: false + +- name: set current slskd version + ansible.builtin.set_fact: + slskd_version: "{{ slskd_release.json.tag_name | regex_replace('^v', '') }}" + slskd_asset_url: "{{ slskd_release.json.assets | selectattr('name', 'search', 'linux-x64.zip') | map(attribute='browser_download_url') | first }}" + +- name: check slskd installed version + ansible.builtin.shell: /opt/slskd/slskd --version | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1 + register: slskd_current_version + changed_when: false + failed_when: false + +- name: display slskd version info + ansible.builtin.debug: + msg: "latest version: {{ slskd_version }}, installed version: {{ slskd_current_version.stdout | default('not installed', true) }}" + +- name: ensure slskd directory exists + ansible.builtin.file: + path: /opt/slskd + state: directory + owner: root + group: root + mode: "0755" + +- name: update slskd + ansible.builtin.unarchive: + src: "{{ slskd_asset_url }}" + dest: /opt/slskd + remote_src: yes + owner: root + group: root + when: slskd_version not in (slskd_current_version.stdout | default('')) + notify: restart slskd + +- name: make slskd binary executable + ansible.builtin.file: + path: /opt/slskd/slskd + mode: "0755" + +- name: ensure slskd config directory exists + ansible.builtin.file: + path: /etc/slskd + state: directory + owner: root + group: root + mode: "0755" + +- name: deploy slskd config + ansible.builtin.template: + src: "{{ inventory_hostname }}/slskd.yml" + dest: /etc/slskd/slskd.yml + owner: root + group: slskd + mode: "0644" + notify: restart slskd + +- name: ensure slskd data directory is a mountpoint + ansible.builtin.command: mountpoint -q /var/lib/slskd + register: vw_mountpoint + failed_when: false + changed_when: false + +- name: remove default slskd data directory + ansible.builtin.file: + path: /var/lib/slskd + state: absent + when: vw_mountpoint.rc != 0 + +- name: ensure slskd data source directory exists + ansible.builtin.file: + path: /mnt/slskd/data + state: directory + owner: slskd + group: slskd + mode: "0755" + +- name: bind mount slskd data directory + ansible.posix.mount: + path: /var/lib/slskd + src: /mnt/slskd/data + fstype: none + opts: bind + state: mounted + notify: restart slskd + +- name: set slskd data directory ownership + ansible.builtin.file: + path: /mnt/slskd/data + owner: slskd + group: slskd + recurse: true + +- name: deploy slskd.service + ansible.builtin.copy: + src: slskd.service + dest: /etc/systemd/system/slskd.service + owner: root + group: root + mode: "0644" + notify: restart slskd diff --git a/roles/slskd/templates/slskd/slskd.yml b/roles/slskd/templates/slskd/slskd.yml new file mode 100644 index 0000000..6c8280f --- /dev/null +++ b/roles/slskd/templates/slskd/slskd.yml @@ -0,0 +1,30 @@ +directories: + incomplete: /mnt/media1/downloads + downloads: /mnt/media1/music +shares: + directories: + - /mnt/media1/music + filters: + - \.ini$ + - Thumbs.db$ + - \.DS_Store$ + cache: + storage_mode: memory + workers: 16 + retention: ~ +transfers: + upload: + slots: 1000 +web: + port: 5030 + https: + disabled: true + authentication: + disabled: true +soulseek: + address: vps.slsknet.org + port: 2271 + username: {{ slskd_username }} + password: {{ slskd_password }} + description: noname + picture: /var/lib/slskd/avatar.jpg diff --git a/roles/sshd/handlers/main.yml b/roles/sshd/handlers/main.yml new file mode 100644 index 0000000..feb0d0f --- /dev/null +++ b/roles/sshd/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart sshd + ansible.builtin.service: + name: sshd + state: restarted + enabled: true diff --git a/roles/sshd/tasks/main.yml b/roles/sshd/tasks/main.yml new file mode 100644 index 0000000..42feb2d --- /dev/null +++ b/roles/sshd/tasks/main.yml @@ -0,0 +1,16 @@ +--- +- name: disable password authentication + ansible.builtin.lineinfile: + path: /etc/ssh/sshd_config + regexp: '^#?PasswordAuthentication\s' + line: 'PasswordAuthentication no' + validate: '/usr/sbin/sshd -t -f %s' + notify: restart sshd + +- name: enable root authentication + ansible.builtin.lineinfile: + path: /etc/ssh/sshd_config + regexp: '^#?PermitRootLogin\s' + line: 'PermitRootLogin prohibit-password' + validate: '/usr/sbin/sshd -t -f %s' + notify: restart sshd diff --git a/roles/stunnel4/handlers/main.yml b/roles/stunnel4/handlers/main.yml new file mode 100644 index 0000000..c980e69 --- /dev/null +++ b/roles/stunnel4/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart stunnel4 + ansible.builtin.service: + name: stunnel4 + state: restarted + enabled: true diff --git a/roles/stunnel4/tasks/main.yml b/roles/stunnel4/tasks/main.yml new file mode 100644 index 0000000..c54d3e1 --- /dev/null +++ b/roles/stunnel4/tasks/main.yml @@ -0,0 +1,32 @@ +--- +- name: install stunnel4 + ansible.builtin.apt: + name: stunnel4 + state: latest + update_cache: true + +- name: ensure stunnel4 run directory exists + ansible.builtin.file: + path: /var/run/stunnel4 + owner: stunnel4 + group: stunnel4 + state: directory + mode: "0755" + +- name: ensure stunnel4 log directory exists + ansible.builtin.file: + path: /var/log/stunnel4 + state: directory + owner: stunnel4 + group: stunnel4 + mode: "0755" + +- name: deploy stunnel4 config + ansible.builtin.template: + src: "{{ item }}" + dest: "/etc/stunnel/{{ item | basename | regex_replace('\\.j2$', '') }}" + owner: root + group: root + mode: '0644' + loop: "{{ query('fileglob', role_path + '/templates/' + inventory_hostname + '/*.conf.j2') }}" + notify: restart stunnel4 diff --git a/roles/stunnel4/templates/liqueur/absinthe.conf.j2 b/roles/stunnel4/templates/liqueur/absinthe.conf.j2 new file mode 100644 index 0000000..e09dd04 --- /dev/null +++ b/roles/stunnel4/templates/liqueur/absinthe.conf.j2 @@ -0,0 +1,9 @@ +setuid = stunnel4 +setgid = stunnel4 +pid = /var/run/stunnel4/absinthe.pid +output = /var/log/stunnel4/absinthe.log +[openvpn] +cert = /etc/letsencrypt/live/absinthe.oyacoi.ru/fullchain.pem +key = /etc/letsencrypt/live/absinthe.oyacoi.ru/privkey.pem +accept = 127.0.0.1:8444 +connect = 127.0.0.1:1195 diff --git a/roles/stunnel4/templates/liqueur/liqueur.conf.j2 b/roles/stunnel4/templates/liqueur/liqueur.conf.j2 new file mode 100644 index 0000000..5850d90 --- /dev/null +++ b/roles/stunnel4/templates/liqueur/liqueur.conf.j2 @@ -0,0 +1,9 @@ +setuid = stunnel4 +setgid = stunnel4 +pid = /var/run/stunnel4/liqueur.pid +output = /var/log/stunnel4/liqueur.log +[openvpn] +cert = /etc/letsencrypt/live/liqueur.oyacoi.ru/fullchain.pem +key = /etc/letsencrypt/live/liqueur.oyacoi.ru/privkey.pem +accept = 127.0.0.1:8443 +connect = 127.0.0.1:1194 diff --git a/roles/stunnel4/templates/router/absinthe.conf.j2 b/roles/stunnel4/templates/router/absinthe.conf.j2 new file mode 100644 index 0000000..d2152b0 --- /dev/null +++ b/roles/stunnel4/templates/router/absinthe.conf.j2 @@ -0,0 +1,9 @@ +setuid = stunnel4 +setgid = stunnel4 +pid = /var/run/stunnel4/absinthe.pid +output = /var/log/stunnel4/absinthe.log +client = yes +[openvpn] +sni = absinthe.oyacoi.ru +accept = 127.0.0.1:1195 +connect = {{ hostvars['liqueur'].ip }}:443 diff --git a/roles/stunnel4/templates/router/liqueur.conf.j2 b/roles/stunnel4/templates/router/liqueur.conf.j2 new file mode 100644 index 0000000..a934923 --- /dev/null +++ b/roles/stunnel4/templates/router/liqueur.conf.j2 @@ -0,0 +1,9 @@ +setuid = stunnel4 +setgid = stunnel4 +pid = /var/run/stunnel4/liqueur.pid +output = /var/log/stunnel4/liqueur.log +client = yes +[openvpn] +sni = liqueur.oyacoi.ru +accept = 127.0.0.1:1194 +connect = {{ hostvars['liqueur'].ip }}:443 diff --git a/roles/sysctl/files/dev/99-custom.conf b/roles/sysctl/files/dev/99-custom.conf new file mode 100644 index 0000000..fcaff0d --- /dev/null +++ b/roles/sysctl/files/dev/99-custom.conf @@ -0,0 +1,5 @@ +net.ipv4.ip_forward = 1 +net.core.default_qdisc=fq +net.ipv4.tcp_congestion_control=bbr +net.ipv6.conf.default.disable_ipv6=1 +net.ipv6.conf.all.disable_ipv6=1 diff --git a/roles/sysctl/files/dev_shin/99-custom.conf b/roles/sysctl/files/dev_shin/99-custom.conf new file mode 100644 index 0000000..fcaff0d --- /dev/null +++ b/roles/sysctl/files/dev_shin/99-custom.conf @@ -0,0 +1,5 @@ +net.ipv4.ip_forward = 1 +net.core.default_qdisc=fq +net.ipv4.tcp_congestion_control=bbr +net.ipv6.conf.default.disable_ipv6=1 +net.ipv6.conf.all.disable_ipv6=1 diff --git a/roles/sysctl/files/liqueur/99-custom.conf b/roles/sysctl/files/liqueur/99-custom.conf new file mode 100644 index 0000000..493c88c --- /dev/null +++ b/roles/sysctl/files/liqueur/99-custom.conf @@ -0,0 +1,2 @@ +net.ipv4.ip_forward = 1 +net.ipv4.conf.all.route_localnet = 1 diff --git a/roles/sysctl/files/router/99-custom.conf b/roles/sysctl/files/router/99-custom.conf new file mode 100644 index 0000000..7d494f0 --- /dev/null +++ b/roles/sysctl/files/router/99-custom.conf @@ -0,0 +1,6 @@ +net.ipv4.ip_forward = 1 +net.ipv4.conf.lo.rp_filter = 0 +net.ipv4.conf.all.rp_filter = 0 +net.bridge.bridge-nf-call-iptables = 0 +net.bridge.bridge-nf-call-ip6tables = 0 +net.bridge.bridge-nf-call-arptables = 0 diff --git a/roles/sysctl/files/vector/99-custom.conf b/roles/sysctl/files/vector/99-custom.conf new file mode 100644 index 0000000..fcaff0d --- /dev/null +++ b/roles/sysctl/files/vector/99-custom.conf @@ -0,0 +1,5 @@ +net.ipv4.ip_forward = 1 +net.core.default_qdisc=fq +net.ipv4.tcp_congestion_control=bbr +net.ipv6.conf.default.disable_ipv6=1 +net.ipv6.conf.all.disable_ipv6=1 diff --git a/roles/sysctl/handlers/main.yml b/roles/sysctl/handlers/main.yml new file mode 100644 index 0000000..18ab735 --- /dev/null +++ b/roles/sysctl/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: reload sysctl + ansible.builtin.command: sysctl -p /etc/sysctl.d/*.conf diff --git a/roles/sysctl/tasks/main.yml b/roles/sysctl/tasks/main.yml new file mode 100644 index 0000000..2e5882f --- /dev/null +++ b/roles/sysctl/tasks/main.yml @@ -0,0 +1,8 @@ +- name: deploy sysctl config + ansible.builtin.copy: + src: "{{ inventory_hostname }}/" + dest: "/etc/sysctl.d/" + owner: root + group: root + mode: '0644' + notify: reload sysctl diff --git a/roles/telemt/files/telemt.service b/roles/telemt/files/telemt.service new file mode 100644 index 0000000..c08aef7 --- /dev/null +++ b/roles/telemt/files/telemt.service @@ -0,0 +1,38 @@ +[Unit] +Description=Telemt service +Documentation=https://github.com/telemt/telemt +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=telemt +Group=telemt +ExecStart=/opt/telemt/telemt /etc/telemt/config.toml +ExecReload=/bin/kill -HUP $MAINPID +PIDFile=/var/run/telemt.pid +Restart=always +RestartSec=5 +WorkingDirectory=/opt/telemt +LimitNOFILE=65535 +LimitNPROC=4096 +NoNewPrivileges=true +ProtectSystem=strict +ProtectHome=true +PrivateTmp=true +PrivateDevices=true +ProtectKernelTunables=true +ProtectKernelModules=true +ProtectControlGroups=true +RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX AF_NETLINK +RestrictNamespaces=true +RestrictRealtime=true +RestrictSUIDSGID=true +MemoryDenyWriteExecute=true +LockPersonality=true +AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_ADMIN +CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_NET_ADMIN +ReadWritePaths=/var/lib/telemt /var/run + +[Install] +WantedBy=multi-user.target diff --git a/roles/telemt/handlers/main.yml b/roles/telemt/handlers/main.yml new file mode 100644 index 0000000..51fa1c6 --- /dev/null +++ b/roles/telemt/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart telemt + ansible.builtin.systemd_service: + name: telemt + state: restarted + enabled: true + daemon_reload: true diff --git a/roles/telemt/tasks/main.yml b/roles/telemt/tasks/main.yml new file mode 100644 index 0000000..0efa884 --- /dev/null +++ b/roles/telemt/tasks/main.yml @@ -0,0 +1,85 @@ +--- +- name: create telemt group + ansible.builtin.group: + name: telemt + system: true + state: present + +- name: create telemt user + ansible.builtin.user: + name: telemt + group: telemt + system: true + shell: /usr/sbin/nologin + home: /var/lib/telemt + create_home: true + state: present + +- name: get latest telemt release info + ansible.builtin.uri: + url: https://api.github.com/repos/telemt/telemt/releases/latest + return_content: yes + register: telemt_release + run_once: true + check_mode: false + +- name: set current telemt version + ansible.builtin.set_fact: + telemt_version: "{{ telemt_release.json.tag_name | regex_replace('^v', '') }}" + telemt_asset_url: "{{ telemt_release.json.assets | selectattr('name', 'equalto', 'telemt-x86_64-v3-linux-gnu.tar.gz') | map(attribute='browser_download_url') | first }}" + +- name: check telemt installed version + ansible.builtin.command: /opt/telemt/telemt --version + register: telemt_current_version + changed_when: false + failed_when: false + +- name: display telemt version info + ansible.builtin.debug: + msg: "latest version: {{ telemt_version }}, installed version: {{ telemt_current_version.stdout | default('not installed', true) }}" + +- name: ensure telemt directory exists + ansible.builtin.file: + path: /opt/telemt + state: directory + owner: root + group: root + mode: "0755" + +- name: update telemt + ansible.builtin.unarchive: + src: "{{ telemt_asset_url }}" + dest: /opt/telemt + remote_src: yes + owner: telemt + group: telemt + when: telemt_version != (telemt_current_version.stdout | default('')) + notify: restart telemt + +- name: make telemt binary executable + ansible.builtin.file: + path: /opt/telemt/telemt + mode: "0755" + +- name: deploy telemt systemd service unit + ansible.builtin.copy: + src: telemt.service + dest: /etc/systemd/system/telemt.service + mode: 0644 + +- name: ensure telemt config directory exists + ansible.builtin.file: + path: /etc/telemt + state: directory + owner: root + group: root + mode: "0755" + +- name: render telemt config + ansible.builtin.template: + src: "{{ inventory_hostname }}/config.toml.j2" + dest: /etc/telemt/config.toml + owner: root + group: telemt + mode: "0644" + notify: restart telemt diff --git a/roles/telemt/templates/dev/config.toml.j2 b/roles/telemt/templates/dev/config.toml.j2 new file mode 100644 index 0000000..3dbb3eb --- /dev/null +++ b/roles/telemt/templates/dev/config.toml.j2 @@ -0,0 +1,67 @@ +show_link = ["user"] + +[general] +prefer_ipv6 = false +fast_mode = true +use_middle_proxy = false +log_level = "normal" +desync_all_full = false +update_every = 43200 +hardswap = false +me_pool_drain_ttl_secs = 90 +me_instadrain = false +me_pool_drain_threshold = 32 +me_pool_drain_soft_evict_grace_secs = 10 +me_pool_drain_soft_evict_per_writer = 2 +me_pool_drain_soft_evict_budget_per_core = 16 +me_pool_drain_soft_evict_cooldown_ms = 1000 +me_bind_stale_mode = "never" +me_pool_min_fresh_ratio = 0.8 +me_reinit_drain_timeout_secs = 90 +tg_connect = 10 +data_path = "/var/lib/telemt/data" + +[network] +ipv4 = true +ipv6 = false +prefer = 4 +multipath = false + +[general.modes] +classic = false +secure = false +tls = true + +[[server.listeners]] +ip = "127.0.0.1" +port = {{ telemt_backend_port }} + +[timeouts] +client_first_byte_idle_secs = 300 +client_handshake = 60 +client_keepalive = 60 +client_ack = 300 + +[censorship] +tls_domain = "{{ telemt_host }}" +mask = true +mask_port = 443 +fake_cert_len = 2048 +serverhello_compact = false +tls_full_cert_ttl_secs = 90 + +[access] +user_max_tcp_conns_global_each = 0 +replay_check_len = 65536 +replay_window_secs = 120 +ignore_time_skew = false + +[access.users] +{% for user,secret in telemt_users.items() %} +{{ user }} = "{{ secret }}" +{% endfor %} + +[[upstreams]] +type = "direct" +enabled = true +weight = 10 diff --git a/roles/telemt/templates/dev_shin/config.toml.j2 b/roles/telemt/templates/dev_shin/config.toml.j2 new file mode 100644 index 0000000..3dbb3eb --- /dev/null +++ b/roles/telemt/templates/dev_shin/config.toml.j2 @@ -0,0 +1,67 @@ +show_link = ["user"] + +[general] +prefer_ipv6 = false +fast_mode = true +use_middle_proxy = false +log_level = "normal" +desync_all_full = false +update_every = 43200 +hardswap = false +me_pool_drain_ttl_secs = 90 +me_instadrain = false +me_pool_drain_threshold = 32 +me_pool_drain_soft_evict_grace_secs = 10 +me_pool_drain_soft_evict_per_writer = 2 +me_pool_drain_soft_evict_budget_per_core = 16 +me_pool_drain_soft_evict_cooldown_ms = 1000 +me_bind_stale_mode = "never" +me_pool_min_fresh_ratio = 0.8 +me_reinit_drain_timeout_secs = 90 +tg_connect = 10 +data_path = "/var/lib/telemt/data" + +[network] +ipv4 = true +ipv6 = false +prefer = 4 +multipath = false + +[general.modes] +classic = false +secure = false +tls = true + +[[server.listeners]] +ip = "127.0.0.1" +port = {{ telemt_backend_port }} + +[timeouts] +client_first_byte_idle_secs = 300 +client_handshake = 60 +client_keepalive = 60 +client_ack = 300 + +[censorship] +tls_domain = "{{ telemt_host }}" +mask = true +mask_port = 443 +fake_cert_len = 2048 +serverhello_compact = false +tls_full_cert_ttl_secs = 90 + +[access] +user_max_tcp_conns_global_each = 0 +replay_check_len = 65536 +replay_window_secs = 120 +ignore_time_skew = false + +[access.users] +{% for user,secret in telemt_users.items() %} +{{ user }} = "{{ secret }}" +{% endfor %} + +[[upstreams]] +type = "direct" +enabled = true +weight = 10 diff --git a/roles/telemt/templates/vector/config.toml.j2 b/roles/telemt/templates/vector/config.toml.j2 new file mode 100644 index 0000000..3dbb3eb --- /dev/null +++ b/roles/telemt/templates/vector/config.toml.j2 @@ -0,0 +1,67 @@ +show_link = ["user"] + +[general] +prefer_ipv6 = false +fast_mode = true +use_middle_proxy = false +log_level = "normal" +desync_all_full = false +update_every = 43200 +hardswap = false +me_pool_drain_ttl_secs = 90 +me_instadrain = false +me_pool_drain_threshold = 32 +me_pool_drain_soft_evict_grace_secs = 10 +me_pool_drain_soft_evict_per_writer = 2 +me_pool_drain_soft_evict_budget_per_core = 16 +me_pool_drain_soft_evict_cooldown_ms = 1000 +me_bind_stale_mode = "never" +me_pool_min_fresh_ratio = 0.8 +me_reinit_drain_timeout_secs = 90 +tg_connect = 10 +data_path = "/var/lib/telemt/data" + +[network] +ipv4 = true +ipv6 = false +prefer = 4 +multipath = false + +[general.modes] +classic = false +secure = false +tls = true + +[[server.listeners]] +ip = "127.0.0.1" +port = {{ telemt_backend_port }} + +[timeouts] +client_first_byte_idle_secs = 300 +client_handshake = 60 +client_keepalive = 60 +client_ack = 300 + +[censorship] +tls_domain = "{{ telemt_host }}" +mask = true +mask_port = 443 +fake_cert_len = 2048 +serverhello_compact = false +tls_full_cert_ttl_secs = 90 + +[access] +user_max_tcp_conns_global_each = 0 +replay_check_len = 65536 +replay_window_secs = 120 +ignore_time_skew = false + +[access.users] +{% for user,secret in telemt_users.items() %} +{{ user }} = "{{ secret }}" +{% endfor %} + +[[upstreams]] +type = "direct" +enabled = true +weight = 10 diff --git a/roles/timezone/tasks/main.yml b/roles/timezone/tasks/main.yml new file mode 100644 index 0000000..5434831 --- /dev/null +++ b/roles/timezone/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- name: set timezone + community.general.timezone: + name: "{{ timezone_name }}" diff --git a/roles/torrserver/files/torrserver.service b/roles/torrserver/files/torrserver.service new file mode 100644 index 0000000..ca908eb --- /dev/null +++ b/roles/torrserver/files/torrserver.service @@ -0,0 +1,18 @@ +[Unit] +Description=TorrServer +Documentation=https://github.com/YouROK/TorrServer +After=network-online.target +Wants=network-online.target + +[Service] +Type=simple +User=torrserver +Group=torrserver +ExecStart=/opt/torrserver/TorrServer-linux-amd64 --path /var/lib/torrserver/data --logpath /var/lob/torrserver.log +Restart=on-failure +RestartSec=5 +TimeoutStopSec=30 +UMask=0027 + +[Install] +WantedBy=multi-user.target diff --git a/roles/torrserver/handlers/main.yml b/roles/torrserver/handlers/main.yml new file mode 100644 index 0000000..8ae8c6b --- /dev/null +++ b/roles/torrserver/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart torrserver + ansible.builtin.systemd: + name: torrserver + state: restarted + enabled: true + daemon_reload: true diff --git a/roles/torrserver/tasks/main.yml b/roles/torrserver/tasks/main.yml new file mode 100644 index 0000000..3611669 --- /dev/null +++ b/roles/torrserver/tasks/main.yml @@ -0,0 +1,158 @@ +--- +- name: create torrserver group + ansible.builtin.group: + name: torrserver + system: true + state: present + +- name: create torrserver user + ansible.builtin.user: + name: torrserver + group: torrserver + system: true + shell: /usr/sbin/nologin + home: /var/lib/torrserver + create_home: true + state: present + +- name: get latest torrserver release info + ansible.builtin.uri: + url: https://api.github.com/repos/YouROK/TorrServer/releases/latest + return_content: yes + register: torrserver_release + run_once: true + check_mode: false + +- name: set current torrserver version + ansible.builtin.set_fact: + torrserver_version: "{{ torrserver_release.json.tag_name | regex_replace('^v', '') }}" + torrserver_asset_url: "{{ torrserver_release.json.assets | selectattr('name', 'equalto', 'TorrServer-linux-amd64') | map(attribute='browser_download_url') | first }}" + +- name: check torrserver installed version + ansible.builtin.command: > + /opt/torrserver/TorrServer-linux-amd64 --version 2>/dev/null | grep -oP 'TorrServer \K.*' + register: torrserver_current_version + changed_when: false + failed_when: false + +- name: display torrserver version info + ansible.builtin.debug: + msg: "latest version: {{ torrserver_version }}, installed version: {{ torrserver_current_version.stdout | default('not installed', true) }}" + +- name: ensure torrserver directory exists + ansible.builtin.file: + path: /opt/torrserver + state: directory + owner: root + group: root + mode: "0755" + +- name: update torrserver + ansible.builtin.get_url: + url: "{{ torrserver_asset_url }}" + dest: /opt/torrserver/TorrServer-linux-amd64 + owner: root + group: root + mode: "0755" + when: torrserver_version != (torrserver_current_version.stdout | default('')) + notify: restart torrserver + +- name: make torrserver binary executable + ansible.builtin.file: + path: /opt/torrserver/TorrServer-linux-amd64 + mode: "0755" + +- name: deploy torrserver systemd service unit + ansible.builtin.copy: + src: torrserver.service + dest: /etc/systemd/system/torrserver.service + mode: "0644" + notify: restart torrserver + +- name: ensure torrserver config directory exists + ansible.builtin.file: + path: /etc/torrserver + state: directory + owner: root + group: root + mode: "0755" + +- name: stat torrserver config in data dir + ansible.builtin.stat: + path: /var/lib/torrserver/settings.json + register: torrserver_config_stat + +- name: remove settings.json if it is not a symlink + ansible.builtin.file: + path: /var/lib/torrserver/settings.json + state: absent + when: + - torrserver_config_stat.stat.exists + - not torrserver_config_stat.stat.islnk + +- name: check if torrserver data directory is a mountpoint + ansible.builtin.command: mountpoint -q /var/lib/torrserver/data + register: vw_mountpoint + failed_when: false + changed_when: false + +- name: ensure torrserver data source directory exists + ansible.builtin.file: + path: /mnt/torrserver/data + state: directory + owner: torrserver + group: torrserver + mode: "0755" + +- name: bind mount torrserver data directory + ansible.posix.mount: + path: /var/lib/torrserver/data + src: /mnt/torrserver/data + fstype: none + opts: bind + state: mounted + notify: restart torrserver + +- name: set torrserver data directory ownership + ansible.builtin.file: + path: /mnt/torrserver/data + owner: torrserver + group: torrserver + recurse: true + +- name: ensure torrserver config directory exists + ansible.builtin.file: + path: /etc/torrserver + state: directory + owner: root + group: root + mode: "0755" + +- name: deploy torrserver config + ansible.builtin.template: + src: "{{ inventory_hostname }}/settings.json.j2" + dest: /etc/torrserver/settings.json + owner: torrserver + group: torrserver + mode: "0640" + notify: restart torrserver + +- name: stat torrserver config in data dir + ansible.builtin.stat: + path: /var/lib/torrserver/data/settings.json + register: torrserver_config_stat + +- name: remove settings.json if it is not a symlink + ansible.builtin.file: + path: /var/lib/torrserver/data/settings.json + state: absent + when: + - torrserver_config_stat.stat.exists + - not torrserver_config_stat.stat.islnk + +- name: symlink torrserver config + ansible.builtin.file: + src: /etc/torrserver/settings.json + dest: /var/lib/torrserver/data/settings.json + state: link + notify: restart torrserver diff --git a/roles/torrserver/templates/torrserver/settings.json.j2 b/roles/torrserver/templates/torrserver/settings.json.j2 new file mode 100644 index 0000000..ff89a60 --- /dev/null +++ b/roles/torrserver/templates/torrserver/settings.json.j2 @@ -0,0 +1,50 @@ +{ + "BitTorr": { + "CacheSize": 1073741824, + "ConnectionsLimit": 25, + "DefaultTrackers": "http://retracker.local/announce\nhttp://bt4.t-ru.org/ann?magnet\nhttp://retracker.mgts.by:80/announce\nhttp://tracker.city9x.com:2710/announce\nhttp://tracker.electro-torrent.pl:80/announce\nhttp://tracker.internetwarriors.net:1337/announce\nhttp://tracker2.itzmx.com:6961/announce\nudp://opentor.org:2710\nudp://public.popcorn-tracker.org:6969/announce\nudp://tracker.opentrackr.org:1337/announce\nhttp://bt.svao-ix.ru/announce\nudp://explodie.org:6969/announce\nwss://tracker.btorrent.xyz\nwss://tracker.openwebtorrent.com", + "DisableDHT": false, + "DisablePEX": false, + "DisableTCP": false, + "DisableUPNP": false, + "DisableUTP": false, + "DisableUpload": false, + "DownloadRateLimit": 0, + "EnableBonjour": false, + "EnableDLNA": false, + "EnableDebug": false, + "EnableIPv6": false, + "EnableLPD": true, + "EnableRutorSearch": false, + "EnableTorznabSearch": false, + "ForceEncrypt": false, + "FriendlyName": "", + "LPDIPv6": false, + "MergeAllM3U": false, + "PeersListenPort": 0, + "PreloadCache": 25, + "ReaderReadAHead": 95, + "RemoveCacheOnDrop": false, + "ResponsiveMode": true, + "RetrackersMode": 0, + "ShowFSActiveTorr": true, + "SslCert": "", + "SslKey": "", + "SslPort": 0, + "StoreSettingsInJson": true, + "StoreViewedInJson": false, + "TMDBSettings": { + "APIKey": "", + "APIURL": "https://api.themoviedb.org", + "ImageURL": "https://image.tmdb.org", + "ImageURLRu": "https://imagetmdb.com" + }, + "TorrentDisconnectTimeout": 30, + "TorrentsSavePath": "", + "TorznabUrls": null, + "TrackTimecode": false, + "TrackersListURL": "", + "UploadRateLimit": 0, + "UseDisk": false + } +} \ No newline at end of file diff --git a/roles/unbound/files/router/unbound.conf b/roles/unbound/files/router/unbound.conf new file mode 100644 index 0000000..bd558e3 --- /dev/null +++ b/roles/unbound/files/router/unbound.conf @@ -0,0 +1,57 @@ +server: + verbosity: 3 + port: 5353 + interface: 127.0.0.1 + do-ip4: yes + do-ip6: no + do-udp: yes + do-tcp: yes + num-threads: 4 + msg-cache-slabs: 4 + rrset-cache-slabs: 4 + infra-cache-slabs: 4 + key-cache-slabs: 4 + msg-cache-size: 64m + rrset-cache-size: 128m + key-cache-size: 32m + neg-cache-size: 4m + cache-min-ttl: 300 + cache-max-ttl: 86400 + prefetch: yes + prefetch-key: yes + serve-expired: yes + edns-buffer-size: 1232 + so-reuseport: yes + auto-trust-anchor-file: "/var/lib/unbound/root.key" + harden-glue: yes + harden-dnssec-stripped: yes + qname-minimisation: yes + hide-identity: yes + hide-version: yes + tls-system-cert: yes + pad-queries: yes + pad-queries-block-size: 128 + access-control: 127.0.0.0/8 allow + access-control: 10.0.0.0/8 allow + local-zone: "10.0.in-addr.arpa." nodefault + local-zone: "lan." static + insecure-lan-zones: yes + ip-ratelimit: 200 + ip-ratelimit-slabs: 4 + tcp-connection-limit: 10.0.0.0/8 64 + +forward-zone: + name: "brawlstarsgame.com" + forward-tls-upstream: yes + forward-addr: 45.139.239.56@853#dns.nullsproxy.com + forward-addr: 141.95.97.120@853#dns.nullsproxy.com + forward-addr: 179.43.147.42@853#dns.nullsproxy.com + forward-addr: 185.211.245.131@853#dns.nullsproxy.com + forward-addr: 82.27.0.149@853#dns.nullsproxy.com + forward-addr: 81.17.20.83@853#dns.nullsproxy.com + +forward-zone: + name: "." + forward-tls-upstream: yes + forward-addr: 1.1.1.1@853#cloudflare-dns.com + forward-addr: 1.0.0.1@853#cloudflare-dns.com diff --git a/roles/unbound/handlers/main.yml b/roles/unbound/handlers/main.yml new file mode 100644 index 0000000..f79d039 --- /dev/null +++ b/roles/unbound/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart unbound + ansible.builtin.service: + name: unbound + state: restarted + enabled: true + listen: restart unbound diff --git a/roles/unbound/tasks/main.yml b/roles/unbound/tasks/main.yml new file mode 100644 index 0000000..9245dec --- /dev/null +++ b/roles/unbound/tasks/main.yml @@ -0,0 +1,13 @@ +--- +- name: install unbound + ansible.builtin.apt: + name: unbound + state: latest + update_cache: true + +- name: deploy unbound config + ansible.builtin.copy: + src: "{{ inventory_hostname }}/unbound.conf" + dest: /etc/unbound/unbound.conf + mode: "0744" + notify: restart unbound diff --git a/roles/valheim/files/start_server.sh b/roles/valheim/files/start_server.sh new file mode 100644 index 0000000..7d0623e --- /dev/null +++ b/roles/valheim/files/start_server.sh @@ -0,0 +1,7 @@ +#!/bin/bash +export templdpath=$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=./linux64:$LD_LIBRARY_PATH +export SteamAppId=892970 +echo "Starting server PRESS CTRL-C to exit" +./valheim_server.x86_64 -name "oyacoi" -port 2456 -world "world0" -password "ff32167" -public 0 +export LD_LIBRARY_PATH=$templdpath diff --git a/roles/valheim/files/valheim.service b/roles/valheim/files/valheim.service new file mode 100644 index 0000000..027a5a4 --- /dev/null +++ b/roles/valheim/files/valheim.service @@ -0,0 +1,15 @@ +[Unit] +Description=valheim server +Wants=network.target +After=syslog.target network-online.target + +[Service] +Type=simple +Restart=on-failure +RestartSec=10 +User=steamcmd +WorkingDirectory=/mnt/valheim/data +ExecStart=/bin/bash /mnt/valheim/data/start_server-custom.sh + +[Install] +WantedBy=multi-user.target diff --git a/roles/valheim/handlers/main.yml b/roles/valheim/handlers/main.yml new file mode 100644 index 0000000..9d0fefa --- /dev/null +++ b/roles/valheim/handlers/main.yml @@ -0,0 +1,7 @@ +--- +- name: restart valheim + ansible.builtin.systemd: + name: valheim.service + state: restarted + enabled: true + daemon_reload: true diff --git a/roles/valheim/tasks/main.yml b/roles/valheim/tasks/main.yml new file mode 100644 index 0000000..23b9955 --- /dev/null +++ b/roles/valheim/tasks/main.yml @@ -0,0 +1,94 @@ +--- +- name: create steamcmd group + ansible.builtin.group: + name: steamcmd + system: true + state: present + +- name: create steamcmd user + ansible.builtin.user: + name: steamcmd + group: steamcmd + system: true + shell: /bin/bash + home: /var/lib/steamcmd + create_home: true + state: present + +- name: configure debian-unstable.sources + ansible.builtin.deb822_repository: + name: debian-unstable + types: deb + uris: http://deb.debian.org/debian + suites: + - unstable + components: + - contrib + - main + - non-free + signed_by: /usr/share/keyrings/debian-archive-keyring.gpg + state: present + +- name: check if i386 architecture + ansible.builtin.command: dpkg --print-foreign-architectures + register: check_i386 + changed_when: false + failed_when: false + +- name: add i386 architecture + ansible.builtin.command: dpkg --add-architecture i386 + when: "'i386' not in check_i386.stdout" + +- name: accept agreement + ansible.builtin.debconf: + name: steamcmd + question: steam/question + vtype: string + value: "I AGREE" + +- name: install steamcmd + ansible.builtin.apt: + name: steamcmd + update_cache: true + +- name: ensure valheim data directory exists + ansible.builtin.file: + path: /mnt/valheim/data + owner: steamcmd + group: steamcmd + state: "directory" + +- name: check steam session + ansible.builtin.stat: + path: /var/lib/steamcmd/.local/share/Steam/config/config.vdf + register: steam_session + +- name: ensure steam authorization exists + ansible.builtin.fail: + msg: "Manual Steam authorization required. Please log in interactively." + when: not steam_session.stat.exists + +- name: install valheim server + ansible.builtin.command: + cmd: su - steamcmd -c "/usr/games/steamcmd +force_install_dir /mnt/valheim/data +login anonymous +app_update 896660 validate +exit" + register: valheim_result + changed_when: "'downloading' in valheim_result.stdout" + notify: restart valheim + +- name: deploy start_server.sh + ansible.builtin.copy: + src: start_server.sh + dest: /mnt/valheim/data/start_server-custom.sh + owner: steamcmd + group: steamcmd + mode: '0775' + notify: restart valheim + +- name: deploy valheim.service + ansible.builtin.copy: + src: valheim.service + dest: /etc/systemd/system/valheim.service + owner: root + group: root + mode: '0644' + notify: restart valheim diff --git a/roles/vaultwarden/handlers/main.yml b/roles/vaultwarden/handlers/main.yml new file mode 100644 index 0000000..3cfbff8 --- /dev/null +++ b/roles/vaultwarden/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart vaultwarden + ansible.builtin.systemd: + name: vaultwarden + state: restarted + enabled: true diff --git a/roles/vaultwarden/tasks/main.yml b/roles/vaultwarden/tasks/main.yml new file mode 100644 index 0000000..b1098a9 --- /dev/null +++ b/roles/vaultwarden/tasks/main.yml @@ -0,0 +1,71 @@ +--- +- name: download vaultwarden repo keyring + ansible.builtin.get_url: + url: https://vaultwarden-deb.pages.dev/vaultwarden-deb-repo-keyring.gpg + dest: /usr/share/keyrings/vaultwarden-deb-repo-keyring.gpg + mode: 0644 + environment: + http_proxy: "http://{{ hostvars['router']['ip'] }}:8080" + https_proxy: "http://{{ hostvars['router']['ip'] }}:8080" + +- name: add vaultwarden apt repository + ansible.builtin.copy: + dest: /etc/apt/sources.list.d/vaultwarden-deb-repo.list + content: "deb [signed-by=/usr/share/keyrings/vaultwarden-deb-repo-keyring.gpg by-hash=force] https://vaultwarden-deb.pages.dev trixie main\n" + mode: 0644 + +- name: configure apt to use proxy + ansible.builtin.template: + src: 95proxy.j2 + dest: /etc/apt/apt.conf.d/95proxy + mode: 0644 + +- name: install vaultwarden + ansible.builtin.apt: + name: vaultwarden + state: latest + update_cache: true + notify: restart vaultwarden + +- name: configure apt to use proxy + ansible.builtin.template: + src: "{{ inventory_hostname }}/vaultwarden.env.j2" + dest: /etc/vaultwarden.env + mode: 0644 + notify: restart vaultwarden + +- name: ensure vaultwarden data directory is a mountpoint + ansible.builtin.command: mountpoint -q /var/lib/vaultwarden + register: vw_mountpoint + failed_when: false + changed_when: false + +- name: remove default vaultwarden data directory + ansible.builtin.file: + path: /var/lib/vaultwarden + state: absent + when: vw_mountpoint.rc != 0 + +- name: ensure vaultwarden data source directory exists + ansible.builtin.file: + path: /mnt/vaultwarden/data + state: directory + owner: vaultwarden + group: vaultwarden + mode: "0755" + +- name: bind mount vaultwarden data directory + ansible.posix.mount: + path: /var/lib/vaultwarden + src: /mnt/vaultwarden/data + fstype: none + opts: bind + state: mounted + notify: restart vaultwarden + +- name: set vaultwarden data directory ownership + ansible.builtin.file: + path: /mnt/vaultwarden/data + owner: vaultwarden + group: vaultwarden + recurse: true diff --git a/roles/vaultwarden/templates/95proxy.j2 b/roles/vaultwarden/templates/95proxy.j2 new file mode 100644 index 0000000..bff617d --- /dev/null +++ b/roles/vaultwarden/templates/95proxy.j2 @@ -0,0 +1,2 @@ +Acquire::http::Proxy::vaultwarden-deb.pages.dev "http://{{ hostvars['router']['ip'] }}:8080"; +Acquire::https::Proxy::vaultwarden-deb.pages.dev "http://{{ hostvars['router']['ip'] }}:8080"; diff --git a/roles/vaultwarden/templates/vaultwarden/vaultwarden.env.j2 b/roles/vaultwarden/templates/vaultwarden/vaultwarden.env.j2 new file mode 100644 index 0000000..5413b51 --- /dev/null +++ b/roles/vaultwarden/templates/vaultwarden/vaultwarden.env.j2 @@ -0,0 +1,8 @@ +WEB_VAULT_ENABLED=true +DATA_FOLDER=/var/lib/vaultwarden/data +WEB_VAULT_FOLDER=/usr/share/vaultwarden/web-vault/ +DATABASE_URL=postgresql://vaultwarden_user:{{ database_password }}@{{ hostvars['pgsql'].ip }}:5432/vaultwarden?application_name=vaultwarden +ROCKET_ADDRESS=0.0.0.0 +ROCKET_PORT=8000 +EXTENDED_LOGGING=true +LOG_FILE=/var/log/vaultwarden/vaultwarden.log diff --git a/roles/xray-core/files/xray-core.service b/roles/xray-core/files/xray-core.service new file mode 100644 index 0000000..5aba614 --- /dev/null +++ b/roles/xray-core/files/xray-core.service @@ -0,0 +1,21 @@ +[Unit] +Description=Xray-core Service +Documentation=https://github.com/xtls/xray-core +After=network.target network-online.target nftables.service +Wants=network-online.target + +[Service] +Type=simple +User=xray-core +Group=xray-core +WorkingDirectory=/opt/xray-core +ExecStart=/opt/xray-core/xray run -config /etc/xray-core/config.json +Restart=on-failure +RestartSec=3s +LimitNOFILE=65535 +AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_ADMIN +CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_NET_ADMIN +NoNewPrivileges=true + +[Install] +WantedBy=multi-user.target diff --git a/roles/xray-core/handlers/main.yml b/roles/xray-core/handlers/main.yml new file mode 100644 index 0000000..5702972 --- /dev/null +++ b/roles/xray-core/handlers/main.yml @@ -0,0 +1,13 @@ +--- +- name: check xray-core config + ansible.builtin.command: su -s /bin/sh xray-core -c "/opt/xray-core/xray run -test -c /etc/xray-core/config.json" + changed_when: false + listen: restart xray-core + +- name: restart xray-core systemd service unit + ansible.builtin.systemd_service: + name: xray-core + state: restarted + enabled: true + daemon_reload: true + listen: restart xray-core diff --git a/roles/xray-core/tasks/main.yml b/roles/xray-core/tasks/main.yml new file mode 100644 index 0000000..8e517e3 --- /dev/null +++ b/roles/xray-core/tasks/main.yml @@ -0,0 +1,100 @@ +--- +- name: create xray-core group + ansible.builtin.group: + name: xray-core + system: true + state: present + +- name: create xray-core user + ansible.builtin.user: + name: xray-core + group: xray-core + system: true + shell: /usr/sbin/nologin + home: /var/lib/xray-core + create_home: false + state: present + +- name: install unzip + ansible.builtin.package: + name: unzip + state: present + +- name: get latest xray-core release info + ansible.builtin.uri: + url: https://api.github.com/repos/XTLS/Xray-core/releases/latest + return_content: true + register: xray_release + run_once: true + check_mode: false + +- name: set current xray-core version + ansible.builtin.set_fact: + xray_version: "{{ xray_release.json.tag_name | regex_replace('^v', '') }}" + xray_asset_url: "{{ xray_release.json.assets | selectattr('name', 'equalto', 'Xray-linux-64.zip') | map(attribute='browser_download_url') | first }}" + +- name: check xray-core installed version + ansible.builtin.shell: > + /opt/xray-core/xray version 2>/dev/null | grep -oP 'Xray \K[0-9.]+' | head -n 1 + register: xray_current_version + changed_when: false + failed_when: false + +- name: display xray-core version info + ansible.builtin.debug: + msg: "latest version: {{ xray_version }}, installed version: {{ xray_current_version.stdout | default('not installed', true) }}" + +- name: ensure xray-core directory exists + ansible.builtin.file: + path: /opt/xray-core + state: directory + owner: root + group: root + mode: "0755" + +- name: update xray-core + ansible.builtin.unarchive: + src: "{{ xray_asset_url }}" + dest: /opt/xray-core + remote_src: true + owner: root + group: root + when: xray_version != xray_current_version.stdout + notify: restart xray-core + +- name: make xray-core binary executable + ansible.builtin.file: + path: /opt/xray-core/xray + mode: "0755" + +- name: deploy xray-core systemd service unit + ansible.builtin.copy: + src: xray-core.service + dest: /etc/systemd/system/xray-core.service + mode: "0644" + notify: restart xray-core + +- name: ensure xray-core log directory exists + ansible.builtin.file: + path: /var/log/xray-core + state: directory + owner: xray-core + group: xray-core + mode: "0755" + +- name: ensure xray-core config directory exists + ansible.builtin.file: + path: /etc/xray-core + owner: root + group: root + state: directory + mode: "0755" + +- name: render xray-core dynamic config + ansible.builtin.template: + src: "{{ inventory_hostname }}/config.json.j2" + dest: "/etc/xray-core/config.json" + owner: root + group: xray-core + mode: "0644" + notify: restart xray-core diff --git a/roles/xray-core/templates/dev/config.json.j2 b/roles/xray-core/templates/dev/config.json.j2 new file mode 100644 index 0000000..1a17579 --- /dev/null +++ b/roles/xray-core/templates/dev/config.json.j2 @@ -0,0 +1,78 @@ +{ + "log": { + "access": "/var/log/xray-core/access.log", + "error": "/var/log/xray-core/error.log", + "loglevel": "warning", + "dnsLog": false, + "maskAddress": "" + }, + "dns": { + "queryStrategy": "UseIPv4", + "servers": [ + "1.1.1.1", + "1.0.0.1" + ] + }, + "inbounds": [ + { + "listen": "/dev/shm/xrxh.socket,0666", + "protocol": "vless", + "settings": { + "clients": [ +{% for user in xray_users %} + { + "email": "{{ user.email }}", + "flow": "xtls-rprx-vision", + "id": "{{ user.id }}" + }{{ "," if not loop.last else "" }} +{% endfor %} + ], + "decryption": "{{ xray_decryption }}" + }, + "streamSettings": { + "network": "xhttp", + "security": "none", + "xhttpSettings": { + "mode": "stream-one", + "path": "{{ xray_xhttp_path }}" + } + }, + "sniffing": { + "enabled": false + } + } + ], + "outbounds": [ + { + "tag": "direct", + "protocol": "freedom", + "settings": { + "domainStrategy": "UseIPv4" + } + }, + { + "tag": "blocked", + "protocol": "blackhole", + "settings": { + "response": { + "type": "none" + } + } + } + ], + "routing": { + "domainStrategy": "IPIfNonMatch", + "rules": [ + { + "type": "field", + "protocol": "bittorrent", + "outboundTag": "blocked" + }, + { + "type": "field", + "ip": "geoip:ru", + "outboundTag": "blocked" + } + ] + } +} diff --git a/roles/xray-core/templates/dev_shin/config.json.j2 b/roles/xray-core/templates/dev_shin/config.json.j2 new file mode 100644 index 0000000..1a17579 --- /dev/null +++ b/roles/xray-core/templates/dev_shin/config.json.j2 @@ -0,0 +1,78 @@ +{ + "log": { + "access": "/var/log/xray-core/access.log", + "error": "/var/log/xray-core/error.log", + "loglevel": "warning", + "dnsLog": false, + "maskAddress": "" + }, + "dns": { + "queryStrategy": "UseIPv4", + "servers": [ + "1.1.1.1", + "1.0.0.1" + ] + }, + "inbounds": [ + { + "listen": "/dev/shm/xrxh.socket,0666", + "protocol": "vless", + "settings": { + "clients": [ +{% for user in xray_users %} + { + "email": "{{ user.email }}", + "flow": "xtls-rprx-vision", + "id": "{{ user.id }}" + }{{ "," if not loop.last else "" }} +{% endfor %} + ], + "decryption": "{{ xray_decryption }}" + }, + "streamSettings": { + "network": "xhttp", + "security": "none", + "xhttpSettings": { + "mode": "stream-one", + "path": "{{ xray_xhttp_path }}" + } + }, + "sniffing": { + "enabled": false + } + } + ], + "outbounds": [ + { + "tag": "direct", + "protocol": "freedom", + "settings": { + "domainStrategy": "UseIPv4" + } + }, + { + "tag": "blocked", + "protocol": "blackhole", + "settings": { + "response": { + "type": "none" + } + } + } + ], + "routing": { + "domainStrategy": "IPIfNonMatch", + "rules": [ + { + "type": "field", + "protocol": "bittorrent", + "outboundTag": "blocked" + }, + { + "type": "field", + "ip": "geoip:ru", + "outboundTag": "blocked" + } + ] + } +} diff --git a/roles/xray-core/templates/router/config.json.j2 b/roles/xray-core/templates/router/config.json.j2 new file mode 100644 index 0000000..6c931bf --- /dev/null +++ b/roles/xray-core/templates/router/config.json.j2 @@ -0,0 +1,183 @@ +{ + "log": { + "access": "/var/log/xray-core/access.log", + "error": "/var/log/xray-core/error.log", + "loglevel": "warning", + "dnsLog": false, + "maskAddress": "" + }, + "dns": { + "tag": "dns-in", + "servers": ["localhost"], + "queryStrategy": "UseIPv4" + }, + "inbounds": [ + { + "tag": "tproxy-in", + "listen": "0.0.0.0", + "port": 61219, + "protocol": "dokodemo-door", + "settings": { + "followRedirect": true, + "network": "tcp,udp" + }, + "streamSettings": { + "sockopt": { + "tproxy": "tproxy" + } + }, + "sniffing": { + "enabled": false + } + }, + { + "tag": "socks-in", + "listen": "127.0.0.1", + "port": 1080, + "protocol": "socks", + "settings": { + "auth": "password", + "accounts": [ + { + "user": "embargo", + "pass": "moistnes12" + } + ], + "udp": true + }, + "sniffing": { + "enabled": false + } + }, + { + "tag": "http-in", + "listen": "0.0.0.0", + "port": 8080, + "protocol": "http", + "settings": { + "allowTransparent": false + }, + "sniffing": { + "enabled": false + } + } + ], + "outbounds": [ +{% for item in xray_outbounds %} + { + "tag": "vless-{{ item.tag }}", + "protocol": "vless", + "settings": { + "vnext": [ + { + "address": "{{ item.address }}", + "port": 443, + "users": [ + { + "id": "{{ item.xray_id }}", + "flow": "xtls-rprx-vision", + "encryption": "{{ item.xray_encryption }}" + } + ] + } + ], + "domainStrategy": "UseIPv4" + }, + "streamSettings": { + "network": "xhttp", + "xhttpSettings": { + "path": "{{ item.xray_xhttp_path }}", + "mode": "stream-one" + }, + "security": "tls", + "tlsSettings": { + "alpn": [ + "h2", + "h3" + ], + "fingerprint": "firefox" + } + } + }, +{% endfor %} + { + "tag": "direct", + "protocol": "freedom", + "settings": { + "domainStrategy": "UseIPv4" + } + }, + { + "tag": "blocked", + "protocol": "blackhole", + "settings": { + "response": { + "type": "none" + } + } + } + ], + "policy": { + "levels": { + "0": { + "handshake": 4, + "connIdle": 300, + "uplinkOnly": 2, + "downlinkOnly": 5, + "statsUserUplink": false, + "statsUserDownlink": false, + "statsUserOnline": false, + "bufferSize": 512 + } + }, + "system": { + "statsInboundUplink": false, + "statsInboundDownlink": false, + "statsOutboundUplink": false, + "statsOutboundDownlink": false + } + }, + "observatory": { + "subjectSelector": ["vless-"], + "probeUrl": "https://www.google.com/generate_204", + "probeInterval": "30s", + "enableConcurrency": true + }, + "routing": { + "domainStrategy": "IPIfNonMatch", +{% if xray_outbounds | length > 1 %} + "balancers": [ + { + "tag": "balancer-vless", + "selector": ["vless-"], + "strategy": { + "type": "leastLoad", + "settings": { + "costs": [ +{% for item in xray_outbounds %} + { "match": "vless-{{ item.tag }}", "value": {{ item.value }}}{{ "," if not loop.last else "" }} +{% endfor %} + ] + } + } + } + ], +{% endif %} + "rules": [ + { + "type": "field", + "protocol": ["bittorrent"], + "outboundTag": "direct" + }, + { + "type": "field", + "inboundTag": [ + "tproxy-in", + "socks-in", + "http-ip" + ], + "balancerTag": "{{ 'balancer-vless' if xray_outbounds | length > 1 else 'vless-' ~ xray_outbounds[0].tag }}" + } + ] + } +} diff --git a/roles/xray-core/templates/vector/config.json.j2 b/roles/xray-core/templates/vector/config.json.j2 new file mode 100644 index 0000000..1a17579 --- /dev/null +++ b/roles/xray-core/templates/vector/config.json.j2 @@ -0,0 +1,78 @@ +{ + "log": { + "access": "/var/log/xray-core/access.log", + "error": "/var/log/xray-core/error.log", + "loglevel": "warning", + "dnsLog": false, + "maskAddress": "" + }, + "dns": { + "queryStrategy": "UseIPv4", + "servers": [ + "1.1.1.1", + "1.0.0.1" + ] + }, + "inbounds": [ + { + "listen": "/dev/shm/xrxh.socket,0666", + "protocol": "vless", + "settings": { + "clients": [ +{% for user in xray_users %} + { + "email": "{{ user.email }}", + "flow": "xtls-rprx-vision", + "id": "{{ user.id }}" + }{{ "," if not loop.last else "" }} +{% endfor %} + ], + "decryption": "{{ xray_decryption }}" + }, + "streamSettings": { + "network": "xhttp", + "security": "none", + "xhttpSettings": { + "mode": "stream-one", + "path": "{{ xray_xhttp_path }}" + } + }, + "sniffing": { + "enabled": false + } + } + ], + "outbounds": [ + { + "tag": "direct", + "protocol": "freedom", + "settings": { + "domainStrategy": "UseIPv4" + } + }, + { + "tag": "blocked", + "protocol": "blackhole", + "settings": { + "response": { + "type": "none" + } + } + } + ], + "routing": { + "domainStrategy": "IPIfNonMatch", + "rules": [ + { + "type": "field", + "protocol": "bittorrent", + "outboundTag": "blocked" + }, + { + "type": "field", + "ip": "geoip:ru", + "outboundTag": "blocked" + } + ] + } +} diff --git a/roles/xray-lists/files/apply.sh b/roles/xray-lists/files/apply.sh new file mode 100644 index 0000000..1d6c702 --- /dev/null +++ b/roles/xray-lists/files/apply.sh @@ -0,0 +1,16 @@ +#!/bin/sh +set -e + +state=/var/lib/xray-lists + +if [ -e "$state/.reload-nft" ]; then + nft -c -f /etc/nftables.conf + nft -f /etc/nftables.conf + rm -f "$state/.reload-nft" +fi + +if [ -e "$state/.reload-dnsmasq" ]; then + dnsmasq --test + systemctl restart dnsmasq + rm -f "$state/.reload-dnsmasq" +fi diff --git a/roles/xray-lists/files/update.sh b/roles/xray-lists/files/update.sh new file mode 100644 index 0000000..8ea6491 --- /dev/null +++ b/roles/xray-lists/files/update.sh @@ -0,0 +1,16 @@ +#!/bin/sh +set -eu + +state=/var/lib/xray-lists +out=$(/opt/xray-lists/venv/bin/xray-lists --config /etc/xray-lists/config.yaml) + +echo "$out" + +if echo "$out" | grep -A 10 "changed:" | grep -q "nftsets.conf"; then + touch "$state/.reload-dnsmasq" +fi +if echo "$out" | grep -A 10 "changed:" | grep -q "\.elements\.nft"; then + touch "$state/.reload-nft" +fi + +exit 0 diff --git a/roles/xray-lists/files/xray-lists.service b/roles/xray-lists/files/xray-lists.service new file mode 100644 index 0000000..6b2ba0f --- /dev/null +++ b/roles/xray-lists/files/xray-lists.service @@ -0,0 +1,23 @@ +[Unit] +Description=Update Xray lists + +[Service] +Type=oneshot +User=xray-lists +Group=xray-lists +WorkingDirectory=/var/lib/xray-lists +UMask=0022 +ExecStart=/opt/xray-lists/update.sh +ExecStartPost=+/opt/xray-lists/apply.sh + +NoNewPrivileges=yes +PrivateTmp=yes +PrivateDevices=yes +ProtectHome=yes +ProtectSystem=strict +ReadWritePaths=/var/lib/xray-lists +ProtectKernelTunables=yes +ProtectKernelModules=yes +ProtectControlGroups=yes +RestrictSUIDSGID=yes +LockPersonality=yes diff --git a/roles/xray-lists/files/xray-lists.timer b/roles/xray-lists/files/xray-lists.timer new file mode 100644 index 0000000..c726253 --- /dev/null +++ b/roles/xray-lists/files/xray-lists.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Run xray-lists update + +[Timer] +OnBootSec=5min +OnUnitActiveSec=12h +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/roles/xray-lists/handlers/main.yml b/roles/xray-lists/handlers/main.yml new file mode 100644 index 0000000..b9310eb --- /dev/null +++ b/roles/xray-lists/handlers/main.yml @@ -0,0 +1,26 @@ +--- +- name: reload nftables + ansible.builtin.command: nft -f /etc/nftables.conf + +- name: restart dnsmasq + ansible.builtin.service: + name: dnsmasq + state: restarted + +- name: run xray-lists systemd timer unit + ansible.builtin.systemd_service: + name: xray-lists.timer + state: started + enabled: true + daemon_reload: true + +- name: update xray-lists + ansible.builtin.systemd_service: + name: xray-lists.service + state: started + +- name: restart xray-lists timer + ansible.builtin.systemd_service: + name: xray-lists.timer + state: restarted + daemon_reload: true diff --git a/roles/xray-lists/tasks/main.yml b/roles/xray-lists/tasks/main.yml new file mode 100644 index 0000000..a037636 --- /dev/null +++ b/roles/xray-lists/tasks/main.yml @@ -0,0 +1,147 @@ +--- +- name: create xray-lists group + ansible.builtin.group: + name: xray-lists + system: true + state: present + +- name: create xray-lists user + ansible.builtin.user: + name: xray-lists + group: xray-lists + system: true + shell: /usr/sbin/nologin + home: /var/lib/xray-lists + create_home: true + state: present + +- name: install required system packages + ansible.builtin.apt: + name: + - python3-venv + - git + - rsync + state: present + update_cache: true + +- name: ensure xray-lists directory exists + ansible.builtin.file: + path: "/etc/xray-lists" + state: directory + owner: "root" + group: "root" + mode: "0755" + +- name: ensure local mirror of xray-lists exists on the runner + ansible.builtin.git: + repo: "https://gitea.oyacoi.ru/pyrschtjag/xray-lists.git" + dest: "{{ xray_lists_runner_mirror | default(lookup('env','HOME') + '/.cache/xray-lists-mirror') }}" + version: main + force: true + delegate_to: localhost + run_once: true + ignore_errors: true + vars: + ansible_connection: local + +- name: attempt to clone/update xray-lists repository directly on the host + block: + - name: clone xray-lists repository from gitea on the host + ansible.builtin.git: + repo: "https://gitea.oyacoi.ru/pyrschtjag/xray-lists.git" + dest: /opt/xray-lists/xray-lists-src + version: main + force: true + rescue: + - name: warn that gitea is unreachable from the host + ansible.builtin.debug: + msg: "gitea.oyacoi.ru is unreachable from this host, falling back to the local copy from the runner" + + - name: check whether the runner has a usable local mirror + ansible.builtin.stat: + path: "{{ xray_lists_runner_mirror | default(lookup('env','HOME') + '/.cache/xray-lists-mirror') }}/.git" + register: runner_mirror_stat + delegate_to: localhost + vars: + ansible_connection: local + + - name: abort if the runner has no local mirror either + ansible.builtin.fail: + msg: "gitea is unreachable and the runner has no local mirror of xray-lists - cannot deploy" + when: not runner_mirror_stat.stat.exists + + - name: ensure xray-lists-src directory exists on the host before sync + ansible.builtin.file: + path: /opt/xray-lists/xray-lists-src + state: directory + owner: root + group: root + mode: "0755" + + - name: sync xray-lists source (including .git) from the runner to the host + ansible.posix.synchronize: + src: "{{ xray_lists_runner_mirror | default(lookup('env','HOME') + '/.cache/xray-lists-mirror') }}/" + dest: "root@{{ ip }}:/opt/xray-lists/xray-lists-src/" + rsync_opts: + - "--delete" + +- name: create python venv for xray-lists + ansible.builtin.command: python3 -m venv /opt/xray-lists/venv + args: + creates: /opt/xray-lists/venv/bin/pip + +- name: check if xray-lists is installed + ansible.builtin.command: /opt/xray-lists/venv/bin/pip show xray-lists + register: pip_check + changed_when: false + failed_when: false + +- name: install xray-lists package into venv + ansible.builtin.command: /opt/xray-lists/venv/bin/pip install -e "/opt/xray-lists/xray-lists-src[socks]" + when: pip_check.rc != 0 + +- name: deploy helper scripts + ansible.builtin.copy: + src: "{{ item }}" + dest: "/opt/xray-lists/{{ item }}" + owner: root + group: root + mode: "0755" + loop: + - update.sh + - apply.sh + +- name: deploy systemd service and timer unit + ansible.builtin.copy: + src: "{{ item }}" + dest: "/etc/systemd/system/{{ item }}" + owner: root + group: root + mode: "0644" + loop: + - xray-lists.service + - xray-lists.timer + notify: run xray-lists systemd timer unit + +- name: ensure xray-lists config directory exists + ansible.builtin.file: + path: "/etc/xray-lists" + state: directory + owner: "root" + group: "root" + mode: "0755" + +- name: render xray-lists config + ansible.builtin.template: + src: xray-config.yaml.j2 + dest: /etc/xray-lists/config.yaml + owner: root + group: xray-lists + mode: "0640" + register: xray_lists_config + +- name: update xray-lists + ansible.builtin.systemd_service: + name: xray-lists.service + state: started + when: xray_lists_config.changed diff --git a/roles/xray-lists/templates/xray-config.yaml.j2 b/roles/xray-lists/templates/xray-config.yaml.j2 new file mode 100644 index 0000000..865c619 --- /dev/null +++ b/roles/xray-lists/templates/xray-config.yaml.j2 @@ -0,0 +1,51 @@ +#jinja2: trim_blocks: True, lstrip_blocks: True +global: + cache_dir: {{ xray_lists_global.cache_dir }} + output_dir: {{ xray_lists_global.output_dir }} + dnsmasq_output: {{ xray_lists_global.dnsmasq_output }} +{% if xray_lists_global.proxy is defined %} + proxy: "{{ xray_lists_global.proxy }}" +{% endif %} +{% if proxy_user is defined %} + proxy_user: "{{ proxy_user }}" + proxy_pass: "{{ proxy_pass }}" +{% endif %} + http_timeout: {{ xray_lists_global.http_timeout | default(20) }} +ip_sets: +{% for id, item in xray_ip_sets.items() %} + - id: {{ id }} + output: {{ id }}_ip.elements.nft +{% if item.static is defined %} + static: +{% for s in item.static %} + - {{ s }} +{% endfor %} +{% endif %} +{% if item.urls is defined %} + urls: +{% for u in item.urls %} + - {{ u }} +{% endfor %} +{% endif %} +{% endfor %} +domain_sets: +{% for id, item in xray_domain_sets.items() %} + - id: {{ id }} + dnsmasq_target: "4#inet#filter#{{ id }}_dom" +{% if item.static is defined %} + static: +{% for s in item.static %} + - {{ s }} +{% endfor %} +{% endif %} +{% if item.urls is defined %} + urls: +{% for u in item.urls %} + - {{ u }} +{% endfor %} +{% endif %} +{% endfor %} +output_rules: +{% for rule in output_rules %} + - {{ rule }} +{% endfor %} diff --git a/roles/zabbix-server/handlers/main.yml b/roles/zabbix-server/handlers/main.yml new file mode 100644 index 0000000..b2ac8d6 --- /dev/null +++ b/roles/zabbix-server/handlers/main.yml @@ -0,0 +1,12 @@ +--- +- name: restart zabbix server + ansible.builtin.systemd: + name: zabbix-server + state: restarted + enabled: true + +- name: restart apache + ansible.builtin.systemd: + name: apache2 + state: reloaded + enabled: true diff --git a/roles/zabbix-server/tasks/main.yml b/roles/zabbix-server/tasks/main.yml new file mode 100644 index 0000000..dd98536 --- /dev/null +++ b/roles/zabbix-server/tasks/main.yml @@ -0,0 +1,64 @@ +--- +- name: download zabbix package + ansible.builtin.get_url: + url: "https://repo.zabbix.com/zabbix/7.4/release/debian/pool/main/z/zabbix-release/zabbix-release_latest_7.4+debian13_all.deb" + dest: "/tmp/zabbix-release_latest_7.4+debian13_all.deb" + mode: "0644" + +- name: install zabbix release package + ansible.builtin.apt: + deb: "/tmp/zabbix-release_latest_7.4+debian13_all.deb" + state: present + +- name: install zabbix server and frontend + ansible.builtin.apt: + name: + - zabbix-server-pgsql + - zabbix-frontend-php + - php8.4-pgsql + - zabbix-apache-conf + - zabbix-sql-scripts + state: present + update_cache: true + notify: + - restart zabbix server + - restart apache + +- name: disable default db config + ansible.builtin.replace: + path: /etc/zabbix/zabbix_server.conf + regexp: '^(DB\w+=.*)$' + replace: '# \1' + notify: restart zabbix server + +- name: deploy zabbix server config + ansible.builtin.template: + src: "{{ item }}" + dest: "/etc/zabbix/zabbix_server.d/{{ item | basename | regex_replace('\\.j2$', '') }}" + owner: root + group: root + mode: '0644' + loop: "{{ query('ansible.builtin.fileglob', role_path + '/templates/' + inventory_hostname + '/*.conf.j2') }}" + notify: restart zabbix server + +- name: deploy zabbix frontend config + ansible.builtin.template: + src: "{{ inventory_hostname }}/zabbix.conf.php.j2" + dest: "/etc/zabbix/web/zabbix.conf.php" + owner: root + group: root + mode: "0644" + notify: restart zabbix server + +- name: disable default apache site + ansible.builtin.command: a2dissite 000-default + args: + removes: /etc/apache2/sites-enabled/000-default.conf + notify: restart apache + +- name: set zabbix apache alias to root + ansible.builtin.replace: + path: /etc/apache2/conf-enabled/zabbix.conf + regexp: '^(\s*)Alias /zabbix /usr/share/zabbix/ui\s*$' + replace: '\1Alias / /usr/share/zabbix/ui/' + notify: restart apache diff --git a/roles/zabbix-server/templates/zabbix/database.conf.j2 b/roles/zabbix-server/templates/zabbix/database.conf.j2 new file mode 100644 index 0000000..6d3007c --- /dev/null +++ b/roles/zabbix-server/templates/zabbix/database.conf.j2 @@ -0,0 +1,5 @@ +DBHost={{ hostvars['pgsql'].ip }} +DBName=zabbix +DBUser=zabbix_user +DBPassword={{ database_password }} +DBPort=5432 diff --git a/roles/zabbix-server/templates/zabbix/zabbix.conf.php.j2 b/roles/zabbix-server/templates/zabbix/zabbix.conf.php.j2 new file mode 100644 index 0000000..b7d1cc8 --- /dev/null +++ b/roles/zabbix-server/templates/zabbix/zabbix.conf.php.j2 @@ -0,0 +1,29 @@ +- + {{ item.extra_zfs_properties | default({}) + | combine(({'quota': (item.quota | ansible.builtin.human_to_bytes | string)} + if item.quota is defined else {})) }} + loop: "{{ zfs }}" + +- name: ensure zfs datasets are mounted + ansible.builtin.command: zfs mount -a + changed_when: false +- name: manage zfs dataset permissions + ansible.builtin.file: + path: "/{{ item.name }}" + owner: "100000" + group: "100000" + loop: "{{ zfs }}" + when: item.state | default('present') != 'absent'