update ansible playbook

This commit is contained in:
2025-08-29 20:45:35 -07:00
parent ab3009d329
commit d765bf1746
5 changed files with 164 additions and 35 deletions

12
ansible/ansible.cfg Normal file
View File

@@ -0,0 +1,12 @@
# ansible.cfg
[defaults]
inventory = inventory.yml
host_key_checking = False
timeout = 30
retry_files_enabled = False
gathering = smart
fact_caching = memory
[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
pipelining = True

View File

@@ -8,8 +8,8 @@ all:
supabase-1: supabase-1:
ansible_host: 91.99.108.216 ansible_host: 91.99.108.216
ansible_user: root # or ubuntu/debian depending on your image ansible_user: root # or ubuntu/debian depending on your image
ansible_ssh_private_key_file: ~/.ssh/your_private_key # path to your SSH key ansible_ssh_private_key_file: ~/.ssh/id_ed25519 # path to your SSH key
# Alternative format if you prefer: # Alternative format if you prefer:
# [supabase_servers] # [supabase_servers]
# supabase-1 ansible_host=YOUR_SERVER_IP ansible_user=root # supabase-1 ansible_host=YOUR_SERVER_IP ansible_user=root

View File

@@ -31,15 +31,41 @@
- ufw - ufw
state: present state: present
- name: Remove any existing Docker repositories
file:
path: "{{ item }}"
state: absent
loop:
- /etc/apt/sources.list.d/docker.list
- /etc/apt/keyrings/docker.gpg
- /usr/share/keyrings/docker-archive-keyring.gpg
- name: Remove Docker from main sources list
lineinfile:
path: /etc/apt/sources.list
regexp: '.*download\.docker\.com.*'
state: absent
- name: Create keyrings directory
file:
path: /etc/apt/keyrings
state: directory
mode: '0755'
- name: Add Docker's official GPG key - name: Add Docker's official GPG key
apt_key: shell: |
url: https://download.docker.com/linux/ubuntu/gpg curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
state: present chmod a+r /etc/apt/keyrings/docker.gpg
args:
creates: /etc/apt/keyrings/docker.gpg
- name: Add Docker repository - name: Add Docker repository
apt_repository: shell: |
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable" echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list
state: present
- name: Update apt cache after adding Docker repo
apt:
update_cache: true
- name: Install Docker CE - name: Install Docker CE
apt: apt:
@@ -50,19 +76,19 @@
- docker-buildx-plugin - docker-buildx-plugin
- docker-compose-plugin - docker-compose-plugin
state: present state: present
update_cache: yes update_cache: true
- name: Start and enable Docker service - name: Start and enable Docker service
systemd: systemd:
name: docker name: docker
state: started state: started
enabled: yes enabled: true
- name: Add current user to docker group - name: Add current user to docker group
user: user:
name: "{{ ansible_user }}" name: "{{ ansible_user }}"
groups: docker groups: docker
append: yes append: true
- name: Create /opt directory if it doesn't exist - name: Create /opt directory if it doesn't exist
file: file:
@@ -75,14 +101,14 @@
repo: https://github.com/supabase/supabase repo: https://github.com/supabase/supabase
dest: "{{ supabase_dir }}" dest: "{{ supabase_dir }}"
depth: 1 depth: 1
force: yes force: true
- name: Set proper ownership for Supabase directory - name: Set proper ownership for Supabase directory
file: file:
path: "{{ supabase_dir }}" path: "{{ supabase_dir }}"
owner: "{{ ansible_user }}" owner: "{{ ansible_user }}"
group: "{{ ansible_user }}" group: "{{ ansible_user }}"
recurse: yes recurse: true
- name: Install Node.js 18.x repository - name: Install Node.js 18.x repository
shell: curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - shell: curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
@@ -95,11 +121,36 @@
state: present state: present
update_cache: yes update_cache: yes
- name: Install Supabase CLI - name: Install Supabase CLI using the official method
npm: block:
name: supabase - name: Download Supabase CLI binary
global: yes get_url:
state: present url: "https://github.com/supabase/cli/releases/latest/download/supabase_linux_amd64.tar.gz"
dest: /tmp/supabase_cli.tar.gz
mode: '0644'
- name: Create supabase CLI directory
file:
path: /usr/local/bin
state: directory
mode: '0755'
- name: Extract Supabase CLI
unarchive:
src: /tmp/supabase_cli.tar.gz
dest: /tmp/
remote_src: true
- name: Move supabase binary to PATH
copy:
src: /tmp/supabase
dest: /usr/local/bin/supabase
mode: '0755'
remote_src: true
rescue:
- name: Supabase CLI installation failed - continuing without it
debug:
msg: "Supabase CLI installation failed, but this is optional for Docker-based setup"
- name: Create PowerSync directory - name: Create PowerSync directory
file: file:
@@ -109,25 +160,50 @@
group: "{{ ansible_user }}" group: "{{ ansible_user }}"
mode: '0755' mode: '0755'
- name: Download PowerSync Server - name: Create PowerSync config file
get_url: copy:
url: https://github.com/powersync-ja/powersync-service/releases/latest/download/powersync-server-linux-amd64.tar.gz content: |
dest: /tmp/powersync-server.tar.gz # PowerSync Service Configuration
mode: '0644' # See: https://docs.powersync.com/installation/self-hosting
port: 80
- name: Extract PowerSync Server
unarchive: database:
src: /tmp/powersync-server.tar.gz type: postgresql
dest: "{{ powersync_dir }}" uri: postgresql://postgres:your_password@supabase_db:5432/postgres
remote_src: yes
# Add your PowerSync configuration here
# This is a basic template - customize according to your needs
dest: "{{ powersync_dir }}/config.yaml"
owner: "{{ ansible_user }}" owner: "{{ ansible_user }}"
group: "{{ ansible_user }}" group: "{{ ansible_user }}"
mode: '0644'
- name: Create PowerSync docker-compose file
copy:
content: |
version: '3.8'
services:
powersync:
image: journeyapps/powersync-service:latest
container_name: powersync
ports:
- "8080:80"
environment:
- POWERSYNC_CONFIG_B64
restart: unless-stopped
volumes:
- ./config.yaml:/tmp/config.yaml:ro
command: sh -c 'export POWERSYNC_CONFIG_B64=$(base64 -w 0 /tmp/config.yaml) && powersync-service'
dest: "{{ powersync_dir }}/docker-compose.yml"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: '0644'
- name: Copy Supabase docker-compose.yml to working directory - name: Copy Supabase docker-compose.yml to working directory
copy: copy:
src: "{{ supabase_dir }}/docker/docker-compose.yml" src: "{{ supabase_dir }}/docker/docker-compose.yml"
dest: "{{ supabase_dir }}/docker-compose.yml" dest: "{{ supabase_dir }}/docker-compose.yml"
remote_src: yes remote_src: true
owner: "{{ ansible_user }}" owner: "{{ ansible_user }}"
group: "{{ ansible_user }}" group: "{{ ansible_user }}"
@@ -138,7 +214,7 @@
remote_src: yes remote_src: yes
owner: "{{ ansible_user }}" owner: "{{ ansible_user }}"
group: "{{ ansible_user }}" group: "{{ ansible_user }}"
force: no force: false
- name: Configure UFW firewall - name: Configure UFW firewall
ufw: ufw:
@@ -174,13 +250,13 @@
- name: Reload systemd daemon - name: Reload systemd daemon
systemd: systemd:
daemon_reload: yes daemon_reload: true
- name: Start and enable Supabase service - name: Start and enable Supabase service
systemd: systemd:
name: supabase name: supabase
state: started state: started
enabled: yes enabled: true
- name: Display setup information - name: Display setup information
debug: debug:
@@ -189,8 +265,13 @@
- "PowerSync has been installed in {{ powersync_dir }}" - "PowerSync has been installed in {{ powersync_dir }}"
- "Supabase Studio will be available at http://{{ ansible_default_ipv4.address }}:3000" - "Supabase Studio will be available at http://{{ ansible_default_ipv4.address }}:3000"
- "Supabase API will be available at http://{{ ansible_default_ipv4.address }}:8000" - "Supabase API will be available at http://{{ ansible_default_ipv4.address }}:8000"
- "PowerSync will be available at http://{{ ansible_default_ipv4.address }}:8080"
- "To start Supabase: cd {{ supabase_dir }} && docker compose up -d" - "To start Supabase: cd {{ supabase_dir }} && docker compose up -d"
- "Configuration file: {{ supabase_dir }}/.env" - "To start PowerSync: cd {{ powersync_dir }} && docker compose up -d"
- "Configuration files:"
- " - Supabase: {{ supabase_dir }}/.env"
- " - PowerSync: {{ powersync_dir }}/config.yaml"
- "IMPORTANT: Update PowerSync config.yaml with your database credentials!"
handlers: handlers:
- name: restart supabase - name: restart supabase
@@ -201,4 +282,4 @@
- name: restart powersync - name: restart powersync
systemd: systemd:
name: powersync name: powersync
state: restarted state: restarted

View File

@@ -0,0 +1,18 @@
# templates/powersync.service.j2
[Unit]
Description=PowerSync Service (Docker)
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory={{ powersync_dir }}
ExecStart=/usr/bin/docker compose up -d
ExecStop=/usr/bin/docker compose down
TimeoutStartSec=0
User={{ ansible_user }}
Group=docker
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,18 @@
# templates/supabase.service.j2
[Unit]
Description=Supabase Service
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory={{ supabase_dir }}
ExecStart=/usr/bin/docker compose up -d
ExecStop=/usr/bin/docker compose down
TimeoutStartSec=0
User={{ ansible_user }}
Group=docker
[Install]
WantedBy=multi-user.target