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,7 +8,7 @@ all:
supabase-1:
ansible_host: 91.99.108.216
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:
# [supabase_servers]

View File

@@ -31,15 +31,41 @@
- ufw
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
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
shell: |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
args:
creates: /etc/apt/keyrings/docker.gpg
- name: Add Docker repository
apt_repository:
repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
state: present
shell: |
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
- name: Update apt cache after adding Docker repo
apt:
update_cache: true
- name: Install Docker CE
apt:
@@ -50,19 +76,19 @@
- docker-buildx-plugin
- docker-compose-plugin
state: present
update_cache: yes
update_cache: true
- name: Start and enable Docker service
systemd:
name: docker
state: started
enabled: yes
enabled: true
- name: Add current user to docker group
user:
name: "{{ ansible_user }}"
groups: docker
append: yes
append: true
- name: Create /opt directory if it doesn't exist
file:
@@ -75,14 +101,14 @@
repo: https://github.com/supabase/supabase
dest: "{{ supabase_dir }}"
depth: 1
force: yes
force: true
- name: Set proper ownership for Supabase directory
file:
path: "{{ supabase_dir }}"
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
recurse: yes
recurse: true
- name: Install Node.js 18.x repository
shell: curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
@@ -95,11 +121,36 @@
state: present
update_cache: yes
- name: Install Supabase CLI
npm:
name: supabase
global: yes
state: present
- name: Install Supabase CLI using the official method
block:
- name: Download Supabase CLI binary
get_url:
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
file:
@@ -109,25 +160,50 @@
group: "{{ ansible_user }}"
mode: '0755'
- name: Download PowerSync Server
get_url:
url: https://github.com/powersync-ja/powersync-service/releases/latest/download/powersync-server-linux-amd64.tar.gz
dest: /tmp/powersync-server.tar.gz
mode: '0644'
- name: Create PowerSync config file
copy:
content: |
# PowerSync Service Configuration
# See: https://docs.powersync.com/installation/self-hosting
port: 80
- name: Extract PowerSync Server
unarchive:
src: /tmp/powersync-server.tar.gz
dest: "{{ powersync_dir }}"
remote_src: yes
database:
type: postgresql
uri: postgresql://postgres:your_password@supabase_db:5432/postgres
# Add your PowerSync configuration here
# This is a basic template - customize according to your needs
dest: "{{ powersync_dir }}/config.yaml"
owner: "{{ 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
copy:
src: "{{ supabase_dir }}/docker/docker-compose.yml"
dest: "{{ supabase_dir }}/docker-compose.yml"
remote_src: yes
remote_src: true
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
@@ -138,7 +214,7 @@
remote_src: yes
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
force: no
force: false
- name: Configure UFW firewall
ufw:
@@ -174,13 +250,13 @@
- name: Reload systemd daemon
systemd:
daemon_reload: yes
daemon_reload: true
- name: Start and enable Supabase service
systemd:
name: supabase
state: started
enabled: yes
enabled: true
- name: Display setup information
debug:
@@ -189,8 +265,13 @@
- "PowerSync has been installed in {{ powersync_dir }}"
- "Supabase Studio will be available at http://{{ ansible_default_ipv4.address }}:3000"
- "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"
- "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:
- name: restart supabase

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