-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostgresql.yml
44 lines (41 loc) · 1.3 KB
/
postgresql.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---
- name: Create postgres volume
community.docker.docker_volume:
name: "{{ postgres['data_volume'] }}"
- name: Create postgres container
community.docker.docker_container:
name: "{{ postgres['container_name'] }}"
image: "{{ postgres['container_image'] }}"
hostname: "{{ postgres['container_hostname'] }}"
restart_policy: unless-stopped
image_name_mismatch: recreate
recreate: true
ports:
- "5432:5432"
env:
POSTGRES_USER: "{{ postgres_db_user }}"
POSTGRES_PASSWORD: "{{ postgres_db_pass }}"
networks:
- name: "{{ postgres['network'] }}"
volumes:
- "{{ postgres['data_volume'] }}:/var/lib/postgresql/data"
healthcheck:
test: ["CMD", "pg_isready", "-U", "{{ postgres_db_user }}"]
interval: 1m30s
timeout: 10s
retries: 3
start_period: 30s
- name: Connect postgresql container to public network
community.docker.docker_network:
name: "{{ docker_networks[0].name }}"
connected:
- postgres
appends: true
- name: Wait for PostgreSQL to become available
community.docker.docker_container_exec:
container: "{{ postgres['container_name'] }}"
command: bash -c "until pg_isready -U {{ postgres_db_user }}; do sleep 1; done"
register: result
until: result is succeeded
retries: 30
delay: 1