fix: support standalone postgres and dynamic litellm path

This commit is contained in:
Haitao Pan 2026-06-14 11:09:52 +08:00
parent bfb6b17e29
commit 6346684af5
7 changed files with 93 additions and 5 deletions

View File

@ -66,12 +66,32 @@
become: true
become_user: "{{ litellm_service_user }}"
- name: Resolve LiteLLM Python site-packages path
ansible.builtin.shell: |
python3 - <<'PY'
import glob
import os
paths = glob.glob(os.path.expanduser("~/.local/lib/python*/site-packages/litellm/proxy"))
if not paths:
raise SystemExit("litellm proxy package path not found")
print(sorted(paths)[-1])
PY
register: litellm_proxy_package_path
changed_when: false
become: true
become_user: "{{ litellm_service_user }}"
- name: Set LiteLLM Python paths
ansible.builtin.set_fact:
litellm_proxy_dir: "{{ litellm_proxy_package_path.stdout | trim }}"
litellm_python_site_packages: "{{ (litellm_proxy_package_path.stdout | trim) | dirname | dirname }}"
- name: Generate Prisma Python Client
ansible.builtin.shell: |
export PATH={{ litellm_service_home }}/.local/bin:$PATH
prisma generate
args:
chdir: "{{ litellm_service_home }}/.local/lib/python3.12/site-packages/litellm/proxy/"
chdir: "{{ litellm_proxy_dir }}"
become: true
become_user: "{{ litellm_service_user }}"
changed_when: false

View File

@ -8,7 +8,7 @@ User={{ litellm_service_user }}
Group={{ litellm_service_group }}
WorkingDirectory={{ litellm_service_home }}
EnvironmentFile={{ litellm_env_file }}
Environment=PYTHONPATH={{ litellm_service_home }}/.local/lib/python3.12/site-packages
Environment=PYTHONPATH={{ litellm_python_site_packages | default(litellm_service_home ~ '/.local/lib/python3.12/site-packages') }}
Environment=PYTHONUSERBASE={{ litellm_service_home }}/.local
Environment=PATH={{ litellm_service_home }}/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ExecStart={{ litellm_service_home }}/.local/bin/litellm --host {{ litellm_listen_host }} --port {{ litellm_listen_port }} --config {{ litellm_config_file }}
@ -19,4 +19,4 @@ StandardError=journal
SyslogIdentifier=litellm-proxy
[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target

View File

@ -6,5 +6,5 @@ LITELLM_DB_PASSWORD={{ litellm_database_password }}
{% if litellm_database_url | trim | length > 0 %}
DATABASE_URL={{ litellm_database_url }}
{% endif %}
PYTHONPATH={{ litellm_service_home }}/.local/lib/python3.12/site-packages
PYTHONPATH={{ litellm_python_site_packages | default(litellm_service_home ~ '/.local/lib/python3.12/site-packages') }}
STORE_MODEL_IN_DB=True

View File

@ -0,0 +1,20 @@
---
postgresql_use_official_repo: false
postgresql_package_dependencies:
- ca-certificates
- gnupg
postgresql_repo_key_url: https://www.postgresql.org/media/keys/ACCC4CF8.asc
postgresql_repo_key_path: /etc/apt/trusted.gpg.d/postgresql.asc
postgresql_repo: "deb http://apt.postgresql.org/pub/repos/apt {{ ansible_distribution_release }}-pgdg main"
postgresql_packages_base:
- postgresql
- postgresql-contrib
postgresql_extra_packages: []
postgresql_service_name: postgresql
postgresql_conf_path: /etc/postgresql/17/main/postgresql.conf
postgresql_hba_path: /etc/postgresql/17/main/pg_hba.conf
postgresql_listen_addresses: "127.0.0.1"
postgresql_port: 5432
postgresql_password_encryption: scram-sha-256
postgresql_allowed_hosts: []
postgresql_auth_method: scram-sha-256

View File

@ -66,6 +66,26 @@
path: "{{ postgresql_conf_path }}"
register: postgresql_conf_file
- name: Discover PostgreSQL configuration file when default path is absent
ansible.builtin.shell: |
set -e
find /etc/postgresql -path '*/main/postgresql.conf' -type f | sort -V | tail -n 1
register: postgresql_conf_discovery
changed_when: false
when: not postgresql_conf_file.stat.exists
- name: Use discovered PostgreSQL configuration file
ansible.builtin.set_fact:
postgresql_conf_path: "{{ postgresql_conf_discovery.stdout | trim }}"
when:
- not postgresql_conf_file.stat.exists
- postgresql_conf_discovery.stdout | trim | length > 0
- name: Refresh facts for PostgreSQL configuration file
ansible.builtin.stat:
path: "{{ postgresql_conf_path }}"
register: postgresql_conf_file
- name: Configure listen_addresses in postgresql.conf
ansible.builtin.lineinfile:
path: "{{ postgresql_conf_path }}"
@ -97,6 +117,26 @@
path: "{{ postgresql_hba_path }}"
register: postgresql_hba_file
- name: Discover PostgreSQL pg_hba.conf when default path is absent
ansible.builtin.shell: |
set -e
find /etc/postgresql -path '*/main/pg_hba.conf' -type f | sort -V | tail -n 1
register: postgresql_hba_discovery
changed_when: false
when: not postgresql_hba_file.stat.exists
- name: Use discovered PostgreSQL pg_hba.conf
ansible.builtin.set_fact:
postgresql_hba_path: "{{ postgresql_hba_discovery.stdout | trim }}"
when:
- not postgresql_hba_file.stat.exists
- postgresql_hba_discovery.stdout | trim | length > 0
- name: Refresh facts for PostgreSQL pg_hba.conf
ansible.builtin.stat:
path: "{{ postgresql_hba_path }}"
register: postgresql_hba_file
- name: Configure pg_hba.conf access rules
ansible.builtin.blockinfile:
path: "{{ postgresql_hba_path }}"

View File

@ -40,7 +40,7 @@
# 基础数据与密钥设施
- import_playbook: setup-vault.yaml
- import_playbook: deploy_postgresql_svc_plus.yml
- import_playbook: setup-postgres-standalone.yaml
- import_playbook: setup-litellm.yaml
# 大模型与 AI Agents

View File

@ -0,0 +1,8 @@
---
- name: Deploy standalone PostgreSQL
hosts: all
become: true
gather_facts: true
roles:
- role: roles/vhosts/postgres
tags: [postgresql]