infra/ansible/postgres-with-1password.yml
2025-08-02 11:14:56 -05:00

50 lines
No EOL
1.7 KiB
YAML

---
# Example playbook for PostgreSQL setup with 1Password integration
# Usage: ansible-playbook -i inventory.yml postgres-with-1password.yml
- name: Configure PostgreSQL server with 1Password integration
hosts: postgres
become: yes
vars:
# Enable 1Password integration
use_1password: true
# Optionally specify 1Password account ID
# If not specified, defaults to YOOATCZZSVGH7AD6VABUVPORLI
# op_account_id: "YOUR_ACCOUNT_ID"
# Override any defaults here
postgresql_databases:
- name: aprsme_prod
owner: aprsme
postgresql_users:
- name: aprsme
# Password will be generated and stored in 1Password
priv: "aprsme_prod:ALL"
roles:
- base
- raid
- postgresql
post_tasks:
- name: Display connection information
debug:
msg: |
PostgreSQL is now configured!
Connection details:
- Host: {{ ansible_host }}
- Port: 5432 (PostgreSQL direct)
- Port: 6432 (PgBouncer pooled)
- Database: {{ postgresql_databases[0].name }}
- User: {{ postgresql_users[0].name }}
- Password: Stored in 1Password as "PostgreSQL {{ postgresql_users[0].name }} - {{ ansible_hostname }}"
Connection strings:
- Direct: postgresql://{{ postgresql_users[0].name }}:<password>@{{ ansible_host }}:5432/{{ postgresql_databases[0].name }}
- Pooled: postgresql://{{ postgresql_users[0].name }}:<password>@{{ ansible_host }}:6432/{{ postgresql_databases[0].name }}
To retrieve the password:
op item get "PostgreSQL {{ postgresql_users[0].name }} - {{ ansible_hostname }}" --fields password