mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-31 23:58:57 +02:00
Renamed the mariadb, openldap and postgres database
This commit is contained in:
60
roles/svc-db-postgres/tasks/main.yml
Normal file
60
roles/svc-db-postgres/tasks/main.yml
Normal file
@@ -0,0 +1,60 @@
|
||||
- name: Create Docker network for PostgreSQL
|
||||
docker_network:
|
||||
name: "{{ applications[application_id].network }}"
|
||||
state: present
|
||||
ipam_config:
|
||||
- subnet: "{{ networks.local['svc-db-postgres'].subnet }}"
|
||||
when: run_once_docker_postgres is not defined
|
||||
|
||||
- name: Install PostgreSQL
|
||||
docker_container:
|
||||
name: "{{ applications[application_id].hostname }}"
|
||||
image: "{{ applications | get_docker_image(application_id) }}"
|
||||
detach: yes
|
||||
env:
|
||||
POSTGRES_PASSWORD: "{{ applications[application_id].credentials.postgres_password }}"
|
||||
POSTGRES_INITDB_ARGS: "--encoding=UTF8 --locale=C" # Necessary for web-app-matrix
|
||||
networks:
|
||||
- name: "{{ applications[application_id].network }}"
|
||||
published_ports:
|
||||
- "127.0.0.1:{{ applications[application_id].port }}:5432"
|
||||
volumes:
|
||||
- postgres_database:/var/lib/postgresql/data
|
||||
restart_policy: "{{ docker_restart_policy }}"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 30s
|
||||
register: setup_postgres_container_result
|
||||
when: run_once_docker_postgres is not defined
|
||||
|
||||
- name: Wait for Postgres inside the container
|
||||
shell: "docker exec {{ applications[application_id].hostname }} pg_isready -U postgres"
|
||||
register: pg_ready
|
||||
until: pg_ready.rc == 0
|
||||
retries: 30
|
||||
delay: 5
|
||||
when:
|
||||
- setup_postgres_container_result is defined
|
||||
- setup_postgres_container_result.changed
|
||||
- run_once_docker_postgres is not defined
|
||||
|
||||
- name: install python-psycopg2
|
||||
pacman:
|
||||
name: python-psycopg2
|
||||
state: present
|
||||
when: run_once_docker_postgres is not defined
|
||||
|
||||
- name: Load database initialization tasks dynamically
|
||||
include_tasks: init_database.yml
|
||||
when:
|
||||
- database_username is defined
|
||||
- database_password is defined
|
||||
- database_name is defined
|
||||
|
||||
- name: Run the docker_postgres tasks once
|
||||
set_fact:
|
||||
run_once_docker_postgres: true
|
||||
when: run_once_docker_postgres is not defined
|
Reference in New Issue
Block a user