Last active
February 12, 2025 18:28
-
-
Save wsargent/d54da142382beabbe274d83a654711f8 to your computer and use it in GitHub Desktop.
ansible playbook for installing Letta + Postgres + pgvector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| - name: Install Letta Server with Docker | |
| hosts: all | |
| become: true | |
| vars: | |
| letta_data_dir: /opt/letta/data | |
| postgres_data_dir: /opt/letta/pgdata | |
| postgres_password: "{{ lookup('community.general.onepassword', 'letta-postgres database', field='password', vault='will-connect-vault') }}" | |
| anthropic_api_key: "{{ lookup('community.general.onepassword', 'Anthropic API Key', field='credential', vault='will-connect-vault') }}" | |
| mistral_api_key: "{{ lookup('community.general.onepassword', 'Mistral API Key', field='credential', vault='will-connect-vault') }}" | |
| letta_server_secure: "true" | |
| letta_server_password: "{{ lookup('community.general.onepassword', 'letta-server password', field='password', vault='will-connect-vault') }}" | |
| ollama_base_url: "{{ lookup('community.general.onepassword', 'ollama tailscale', field='url', vault='will-connect-vault') }}" | |
| tasks: | |
| - name: Install required packages | |
| apt: | |
| name: | |
| - apt-transport-https | |
| - ca-certificates | |
| - curl | |
| - software-properties-common | |
| - python3-pip | |
| state: present | |
| update_cache: yes | |
| - name: install-tailscale | |
| import_role: | |
| name: artis3n.tailscale | |
| vars: | |
| tailscale_authkey: "{{ lookup('community.general.onepassword', 'vagrant-tailscale', field='credential', vault='will-connect-vault') }}" | |
| tailscale_args: "--ssh" | |
| insecurely_log_authkey: false | |
| - name: Add Docker GPG key | |
| apt_key: | |
| url: https://download.docker.com/linux/ubuntu/gpg | |
| state: present | |
| - name: Add Docker repository | |
| apt_repository: | |
| repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable | |
| state: present | |
| - name: Install Docker | |
| apt: | |
| name: docker-ce | |
| state: present | |
| update_cache: yes | |
| - name: Create Letta directories | |
| file: | |
| path: "{{ item }}" | |
| state: directory | |
| mode: '0755' | |
| loop: | |
| - "{{ letta_data_dir }}" | |
| - "{{ postgres_data_dir }}" | |
| - name: Install Docker Python dependencies | |
| pip: | |
| name: | |
| - "docker>=3.0.0,<7.0.0" | |
| - "requests<2.32" | |
| - "dbus-python" | |
| state: present | |
| - name: Start Docker service | |
| service: | |
| name: docker | |
| state: started | |
| enabled: yes | |
| - name: Install Python Docker package | |
| pip: | |
| name: docker | |
| state: present | |
| - name: Install PostgreSQL client dependencies | |
| apt: | |
| name: | |
| - postgresql-client | |
| - libpq-dev | |
| state: present | |
| - name: Install Python psycopg2 https://stackoverflow.com/a/71853700 | |
| pip: | |
| name: psycopg2 | |
| state: present | |
| - name: Pull PostgreSQL Docker image | |
| docker_image: | |
| name: pgvector/pgvector | |
| source: pull | |
| tag: pg14 | |
| - name: Run PostgreSQL container | |
| docker_container: | |
| name: letta-postgres | |
| image: pgvector/pgvector:pg14 | |
| network_mode: host | |
| state: started | |
| restart_policy: unless-stopped | |
| volumes: | |
| - "{{ postgres_data_dir }}:/var/lib/postgresql/data" | |
| env: | |
| POSTGRES_PASSWORD: "{{ postgres_password }}" | |
| POSTGRES_USER: letta | |
| POSTGRES_DB: letta | |
| ports: | |
| - "5432:5432" | |
| - name: Wait for PostgreSQL to be ready | |
| wait_for: | |
| port: 5432 | |
| timeout: 30 | |
| - name: Create pgvector extension | |
| community.postgresql.postgresql_query: | |
| db: letta | |
| port: 5432 | |
| login_host: localhost | |
| login_user: letta | |
| login_password: "{{ postgres_password }}" | |
| query: CREATE EXTENSION IF NOT EXISTS vector; | |
| - name: Pull Letta Docker image | |
| docker_image: | |
| name: letta/letta | |
| source: pull | |
| tag: latest | |
| - name: Run Letta container | |
| docker_container: | |
| name: letta-server | |
| image: letta/letta:latest | |
| network_mode: host | |
| state: started | |
| restart_policy: unless-stopped | |
| volumes: | |
| - "{{ letta_data_dir }}:/data" | |
| env: | |
| SECURE: "{{ letta_server_secure }}" | |
| LETTA_SERVER_PASSWORD: "{{ letta_server_password }}" | |
| ANTHROPIC_API_KEY: "{{ anthropic_api_key }}" | |
| MISTRAL_API_KEY: "{{ mistral_api_key }}" | |
| OLLAMA_BASE_URL: "{{ ollama_base_url }}" | |
| DATABASE_URL: "postgresql://letta:{{ postgres_password }}@localhost:5432/letta" | |
| ports: | |
| - "8283:8283" | |
| - name: Wait for Letta server to be ready | |
| wait_for: | |
| port: 8283 | |
| timeout: 60 | |
| - name: Set tailscale serve to expose Letta on the internet | |
| ansible.builtin.command: tailscale funnel --bg --https 443 localhost:8283 | |
| become: true | |
| - name: Display connection information | |
| debug: | |
| msg: | |
| - "Letta server is now running and accessible via Tailscale HTTPS" | |
| - "You can connect to it using your Tailscale domain" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment