diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..9c2304c --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,2 @@ +exclude_paths: + - roles diff --git a/README.md b/README.md index 21e87a0..1394f24 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,12 @@ This repository contains the invidious infrastructure. 2. Install requirements: `ansible-galaxy install -r requirements.yml -p roles` ## Hosts -### invidious.io +### invidious.io (old) + +Install old requirements: `ansible-galaxy install -r requirements-old.yml -p roles` `ansible-playbook main.yml -i inventory.yml --ask-vault-pass` + +### tin.invidious.io + +`ansible-playbook tin.yml -i inventory.yml` diff --git a/group_vars/main/main.yml b/group_vars/main/main.yml index b130325..f442848 100644 --- a/group_vars/main/main.yml +++ b/group_vars/main/main.yml @@ -12,7 +12,6 @@ apt_packages: - net-tools - python3-setuptools - jq - - prometheus-node-exporter pip_install_packages: - name: docker diff --git a/group_vars/all/vault b/host_vars/invidious.io/vault similarity index 100% rename from group_vars/all/vault rename to host_vars/invidious.io/vault diff --git a/host_vars/tin.invidious.io/main.yml b/host_vars/tin.invidious.io/main.yml new file mode 100644 index 0000000..3b673d3 --- /dev/null +++ b/host_vars/tin.invidious.io/main.yml @@ -0,0 +1,3 @@ +--- +docker_compose_version: "1.29.2" +caddy_config: "{{ lookup('template', 'templates/tin-Caddyfile.j2') }}" diff --git a/inventory.yml b/inventory.yml index ced6667..c0120b4 100644 --- a/inventory.yml +++ b/inventory.yml @@ -4,4 +4,4 @@ all: main: hosts: invidious.io: - ansible_host: 188.34.196.170 + tin.invidious.io: diff --git a/requirements-old.yml b/requirements-old.yml new file mode 100644 index 0000000..ee3e536 --- /dev/null +++ b/requirements-old.yml @@ -0,0 +1,10 @@ +roles: + - name: jnv.unattended-upgrades + version: v1.10.0 + - name: geerlingguy.pip + version: 2.0.0 + - name: geerlingguy.docker + version: 3.0.0 + - name: caddy_ansible.caddy_ansible + - name: cloudalchemy.prometheus + - name: cloudalchemy.grafana diff --git a/requirements.yml b/requirements.yml index ee3e536..c2b7047 100644 --- a/requirements.yml +++ b/requirements.yml @@ -1,10 +1,11 @@ roles: - name: jnv.unattended-upgrades - version: v1.10.0 + # from github because version missing on galaxy, https://github.com/jnv/ansible-role-unattended-upgrades/issues/89 + src: https://github.com/jnv/ansible-role-unattended-upgrades + version: v1.12.1 - name: geerlingguy.pip - version: 2.0.0 + version: 2.1.0 - name: geerlingguy.docker - version: 3.0.0 + version: 4.1.1 - name: caddy_ansible.caddy_ansible - - name: cloudalchemy.prometheus - - name: cloudalchemy.grafana + version: v3.0.4 diff --git a/tasks/compose.yml b/tasks/compose.yml new file mode 100644 index 0000000..1d37854 --- /dev/null +++ b/tasks/compose.yml @@ -0,0 +1,18 @@ +--- +- name: Create compose folders + file: + path: "/root/compose/{{ app }}" + state: directory + recurse: true + mode: 0755 + +- name: Template compose files + template: + src: "compose/{{ app }}.yml" + dest: "/root/compose/{{ app }}/docker-compose.yml" + mode: 0600 + +- name: Compose app + community.docker.docker_compose: + project_src: "/root/compose/{{ app }}" + pull: true diff --git a/templates/compose/instances-api.yml b/templates/compose/instances-api.yml new file mode 100644 index 0000000..ae5d5bc --- /dev/null +++ b/templates/compose/instances-api.yml @@ -0,0 +1,7 @@ +--- +services: + api: + image: quay.io/invidious/instances:latest + restart: unless-stopped + ports: + - "127.0.0.1:3000:3000" diff --git a/templates/compose/redirect.yml b/templates/compose/redirect.yml new file mode 100644 index 0000000..03bcfa6 --- /dev/null +++ b/templates/compose/redirect.yml @@ -0,0 +1,10 @@ +--- +services: + redirect: + image: quay.io/invidious/invidious-redirect:latest + restart: unless-stopped + ports: + - "127.0.0.1:8080:80" + # disable (spammy logs) + logging: + driver: "none" diff --git a/templates/tin-Caddyfile.j2 b/templates/tin-Caddyfile.j2 new file mode 100644 index 0000000..c36e5ab --- /dev/null +++ b/templates/tin-Caddyfile.j2 @@ -0,0 +1,75 @@ +# {{ ansible_managed }} + +(common) { + encode gzip + respond /robots.txt 200 { + body "User-agent: * +Disallow: / +" +} + log { + output file /var/log/caddy/access.log { + roll_size 500mb + roll_keep 5 + } + format filter { + wrap json + fields { + common_log delete + request>remote_addr ip_mask { + ipv4 24 + ipv6 32 + } + } + } + } +} + +www.invidio.us { + import common + redir https://invidious.io{uri} +} +#invidious.io { +# import common +# root * /var/www/invidious.io +# file_server +#} +git.invidious.io { + import common + redir https://github.com/iv-org/invidious +} + +invidio.us { + import common + redir https://redirect.invidious.io{uri} + header /api* content-type "application/json" + respond /api* "{\"error\":\"This server no longer hosts the Invidious API.\"}" 410 +} +redirect.invidious.io { + import common + reverse_proxy http://127.0.0.1:8080 +} + +instances.invidio.us { + import common + redir https://api.invidious.io{uri} +} +api.invidious.io { + import common + reverse_proxy http://127.0.0.1:3000 + header /static* Cache-Control "max-age=86400" +} + +uptime.invidio.us { + import common + redir https://stats.uptimerobot.com/89VnzSKAn{uri} +} +uptime.invidious.io { + import common + redir https://stats.uptimerobot.com/89VnzSKAn{uri} +} + +#docs.invidious.io { +# import common +# reverse_proxy http://127.0.0.1:3001 +#} diff --git a/tin.yml b/tin.yml new file mode 100644 index 0000000..5a490c7 --- /dev/null +++ b/tin.yml @@ -0,0 +1,61 @@ +--- +- hosts: tin.invidious.io + handlers: + - name: restart ssh + systemd: + name: sshd + state: restarted + + tasks: + - name: SSH config + template: + src: sshd_config.j2 + dest: /etc/ssh/sshd_config + mode: 0644 + notify: restart ssh + tags: [ssh, base] + + - name: SSH keys + template: + src: authorized_keys.j2 + dest: /root/.ssh/authorized_keys + mode: 0600 + tags: [ssh, base] + + - name: Install packages + apt: + name: "{{ apt_packages }}" + update_cache: true + tags: [apt, base] + + - name: unattended-upgrades + import_role: + name: jnv.unattended-upgrades + tags: [unattended-upgrades] + + - name: pip + import_role: + name: geerlingguy.pip + tags: [pip,docker] + + - name: docker + import_role: + name: geerlingguy.docker + tags: [dockerd, docker] + + - name: Deploy invidious api + import_tasks: tasks/compose.yml + vars: + app: instances-api + tags: [instances-api, api, docker] + + - name: Deploy invidious api + import_tasks: tasks/compose.yml + vars: + app: redirect + tags: [redirect, docker] + + - name: caddy + import_role: + name: caddy_ansible.caddy_ansible + tags: [caddy]