Add the Affine playbook

This commit is contained in:
tanshu committed 2026-10-18 21:35:52 +05:30
1 parent a9ac51bd43
commit 34cb4aa3dc
8 files changed
+164

No files matched your search

@@ -0,0 +1,44 @@
---
# Tasks for Sharelatex role
- name: Pull Affine migration image
docker_image:
name: "{{ migration_image }}"
source: pull
force_source: yes
- name: Ensure Affine Storage Directory exists
file:
path: "/var/lib/{{ host_directory }}/storage"
state: directory
mode: 0755
- name: Ensure Affine Config Directory exists
file:
path: "/var/lib/{{ host_directory }}/config"
state: directory
mode: 0755
- name: Ensure 'affine' Docker network exists
docker_network:
name: "{{ docker_network }}"
state: present
connected:
- "{{ postgres_container }}"
- "{{ redis_container }}"
- name: Create Affine migration container
docker_container:
name: "{{ migration_container }}"
image: "{{ migration_image }}"
state: started
restart_policy: "no"
command: "sh -c node ./scripts/self-host-predeploy.js"
env:
REDIS_SERVER_HOST: "{{ redis_container }}"
DATABASE_URL: "{{ db_url }}"
AFFINE_INDEXER_ENABLED: "false"
volumes:
- "/var/lib/{{ host_directory }}/storage:/root/.affine/storage"
- "/var/lib/{{ host_directory }}/config:/root/.affine/config"
networks:
- name: "{{ docker_network }}"
+30
View File
@@ -0,0 +1,30 @@
---
# Tasks for Affine role
- name: Pull Affine image
docker_image:
name: "{{ docker_image }}"
source: pull
force_source: yes
- name: Create Affine container
docker_container:
name: "{{ docker_container }}"
image: "{{ docker_image }}"
state: started
restart_policy: "unless-stopped"
env:
REDIS_SERVER_HOST: "{{ redis_container }}"
DATABASE_URL: "{{ db_url }}"
AFFINE_INDEXER_ENABLED: "false"
volumes:
- "/var/lib/{{ host_directory }}/storage:/root/.affine/storage"
- "/var/lib/{{ host_directory }}/config:/root/.affine/config"
networks:
- name: "{{ docker_network }}"
- name: Add caddy to the 'affine' network
docker_network:
name: "{{ docker_network }}"
connected:
- name: "{{ caddy_container }}"
appends: yes
+7
View File
@@ -0,0 +1,7 @@
---
# Handlers for Nginx role
- name: Restart caddy container
docker_container:
name: "{{ caddy_container }}"
state: started
restart: true
+22
View File
@@ -0,0 +1,22 @@
---
- name: Read current Caddyfile
ansible.builtin.slurp:
path: "{{ caddyfile_path }}"
register: caddyfile_raw
- name: Decode Caddyfile content
set_fact:
caddyfile_content: "{{ caddyfile_raw['content'] | b64decode }}"
- name: Check if snippet already exists
set_fact:
snippet_present: "{{ snippet_block in caddyfile_content }}"
- name: Add snippet if missing
ansible.builtin.blockinfile:
path: "{{ caddyfile_path }}"
marker: "# {mark} Ansible managed Caddy snippet for {{ host }}"
block: "{{ snippet_block }}"
create: yes
when: not snippet_present
notify: Restart caddy container