From 6f920e4497c16328daf37ca711636c4135ce9f31 Mon Sep 17 00:00:00 2001 From: tolerryan Date: Sun, 1 Nov 2026 03:34:41 +0000 Subject: [PATCH] updating playbook for 2nd vps --- inventory.yml | 6 +- roles/archivewarrior/defaults/main.yml | 13 +++ roles/archivewarrior/tasks/main.yml | 78 +++++++++++++++ .../templates/docker-compose.yml.j2 | 98 +++++++++++++++++++ roles/postgres/tasks/main.yml | 27 ----- site.yml | 7 +- 6 files changed, 196 insertions(+), 33 deletions(-) create mode 100644 roles/archivewarrior/defaults/main.yml create mode 100644 roles/archivewarrior/tasks/main.yml create mode 100644 roles/archivewarrior/templates/docker-compose.yml.j2 delete mode 100644 roles/postgres/tasks/main.yml diff --git a/inventory.yml b/inventory.yml index 4e62856..c8cc443 100644 --- a/inventory.yml +++ b/inventory.yml @@ -9,10 +9,10 @@ all: #vps2: # ansible_host: 203.0.113.11 - dbservers: + archivewarrior: hosts: - #vps3: - # ansible_host: 203.0.113.12 + chi2: + ansible_host: 107.175.70.69 authelia: hosts: diff --git a/roles/archivewarrior/defaults/main.yml b/roles/archivewarrior/defaults/main.yml new file mode 100644 index 0000000..4f566b3 --- /dev/null +++ b/roles/archivewarrior/defaults/main.yml @@ -0,0 +1,13 @@ +# User config +archive_user: jester45 +archive_uid: 1024 +archive_gid: 1024 + +# Path Configurations +base_app_dir: "/app/archivewarrior" +docker_dir: "/app/docker/archivewarrior" +data_dir: "/app/data/archivewarrior" + +# Container Configuration +container_name: "archivewarrior" +image_version: "latest" \ No newline at end of file diff --git a/roles/archivewarrior/tasks/main.yml b/roles/archivewarrior/tasks/main.yml new file mode 100644 index 0000000..be51b08 --- /dev/null +++ b/roles/archivewarrior/tasks/main.yml @@ -0,0 +1,78 @@ +--- + +- name: Remove nginx, avoids port 80 conflict + ansible.builtin.apt: + name: nginx + state: absent + +- name: Remove nginx service, avoids port 80 conflict + ansible.builtin.service: + name: nginx + state: stopped + enabled: false + +- name: Create authelia directories + ansible.builtin.file: + path: "{{ item }}" + state: directory + owner: root + group: root + mode: "0750" + loop: + - "{{ authelia_base_dir }}" + - "{{ authelia_config_dir }}" + - "{{ authelia_data_dir }}" + +- name: Check if Caddyfile path is wrongly a directory + ansible.builtin.stat: + path: "{{ authelia_base_dir }}/Caddyfile" + register: caddyfile_stat + +- name: Remove Caddyfile if it was created as a directory + ansible.builtin.file: + path: "{{ authelia_base_dir }}/Caddyfile" + state: absent + when: caddyfile_stat.stat.exists and caddyfile_stat.stat.isdir + +- name: Deploy Caddyfile + ansible.builtin.template: + src: Caddyfile.j2 + dest: "{{ authelia_base_dir }}/Caddyfile" + owner: root + group: root + mode: "0640" + notify: restart authelia + +- name: Deploy configuration.yml + ansible.builtin.template: + src: configuration.yml.j2 + dest: "{{ authelia_config_dir }}/configuration.yml" + owner: root + group: root + mode: "0640" + notify: restart authelia + +- name: Deploy users_database.yml + ansible.builtin.template: + src: users_database.yml.j2 + dest: "{{ authelia_config_dir }}/users_database.yml" + owner: root + group: root + mode: "0640" + notify: restart authelia + when: authelia_users is defined + +- name: Deploy docker-compose.yml + ansible.builtin.template: + src: docker-compose.yml.j2 + dest: "{{ authelia_base_dir }}/docker-compose.yml" + owner: root + group: root + mode: "0640" + register: compose_file + +- name: Pull and start authelia via docker compose + community.docker.docker_compose_v2: + project_src: "{{ authelia_base_dir }}" + state: present + pull: missing diff --git a/roles/archivewarrior/templates/docker-compose.yml.j2 b/roles/archivewarrior/templates/docker-compose.yml.j2 new file mode 100644 index 0000000..19ce5bd --- /dev/null +++ b/roles/archivewarrior/templates/docker-compose.yml.j2 @@ -0,0 +1,98 @@ +--- +- name: Deploy ArchiveWarrior Docker Container + hosts: all + become: true + vars: + + tasks: + # ---------------------------------------------------- + # 1. PREREQUISITES & DOCKER INSTALLATION + # ---------------------------------------------------- + - name: Check if Docker is already installed + ansible.builtin.command: docker --version + register: docker_check + changed_when: false + failed_when: false + + - name: Install Docker via convenience script if missing + ansible.builtin.shell: | + set -o pipefail + curl -fsSL https://docker.com | sh + args: + executable: /bin/bash + when: docker_check.rc != 0 + changed_when: true + + - name: Ensure Docker service is running and enabled + ansible.builtin.systemd: + name: docker + state: started + enabled: true + + # ---------------------------------------------------- + # 2. USER & DIRECTORY CONFIGURATION + # ---------------------------------------------------- + - name: Create dedicated group for ArchiveWarrior + ansible.builtin.group: + name: "{{ archive_user }}" + gid: "{{ archive_gid }}" + state: present + + - name: Create dedicated system user for ArchiveWarrior + ansible.builtin.user: + name: "{{ archive_user }}" + uid: "{{ archive_uid }}" + group: "{{ archive_user }}" + groups: docker + append: true + shell: /usr/sbin/nologin + system: true + state: present + + - name: Create persistent storage and layout directories + ansible.builtin.file: + path: "{{ item }}" + state: directory + owner: "{{ archive_user }}" + group: "{{ archive_user }}" + mode: '0755' + loop: + - "{{ base_app_dir }}" + - "{{ docker_dir }}" + - "{{ data_dir }}" + + # ---------------------------------------------------- + # 3. DOCKER COMPOSE DEPLOYMENT + # ---------------------------------------------------- + - name: Write docker-compose.yml configuration file + ansible.builtin.copy: + dest: "{{ docker_dir }}/docker-compose.yml" + owner: "{{ archive_user }}" + group: "{{ archive_user }}" + mode: '0640' + content: | + version: '3.8' + services: + archivewarrior: + image: atdr.meo.ws/archiveteam/archivewarrior:${image_version} + container_name: ${container_name} + restart: unless-stopped + user: "${archive_uid}:${archive_gid}" + logging: + driver: "json-file" + options: + max-size: "10m" + max-file: "3" + volumes: + - ${data_dir}:/home/warrior/data + environment: + - DOWNLOADER=YourNameOrNickname + - SELECTED_PROJECT=auto + - CONCURRENT_ITEMS=6 + + - name: Pull and start ArchiveWarrior Docker container + # Using community.docker.docker_compose_v2 to handle stack management safely + community.docker.docker_compose_v2: + project_src: "{{ docker_dir }}" + state: present + pull: always diff --git a/roles/postgres/tasks/main.yml b/roles/postgres/tasks/main.yml deleted file mode 100644 index a56b191..0000000 --- a/roles/postgres/tasks/main.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -- name: Install postgresql - ansible.builtin.apt: - name: - - "postgresql-{{ postgres_version }}" - - python3-psycopg2 - state: present - -- name: Ensure postgresql is running and enabled - ansible.builtin.service: - name: postgresql - state: started - enabled: true - -# - name: Create databases -# become_user: postgres -# community.postgresql.postgresql_db: -# name: "{{ item.name }}" -# loop: "{{ postgres_databases }}" - -# - name: Create users -# become_user: postgres -# community.postgresql.postgresql_user: -# name: "{{ item.name }}" -# password: "{{ item.password }}" -# loop: "{{ postgres_users }}" -# no_log: true diff --git a/site.yml b/site.yml index f1e1e93..6c93fb5 100644 --- a/site.yml +++ b/site.yml @@ -20,11 +20,12 @@ - docker - nginx -- name: Database servers - hosts: dbservers +- name: archivewarrior servers + hosts: archivewarrior become: true roles: - - postgres + - docker + - archivewarrior - name: authelia servers hosts: authelia