2023-12-29 23:58:57 +01:00
|
|
|
- name: Create Docker network for PostgreSQL
|
|
|
|
docker_network:
|
|
|
|
name: postgres_network
|
|
|
|
state: present
|
|
|
|
when: run_once_docker_postgres is not defined
|
|
|
|
|
|
|
|
- name: Install PostgreSQL
|
|
|
|
docker_container:
|
|
|
|
name: postgres
|
|
|
|
image: postgres:latest
|
|
|
|
detach: yes
|
|
|
|
env:
|
|
|
|
POSTGRES_PASSWORD: "{{ central_postgres_password }}"
|
2023-12-31 11:14:18 +01:00
|
|
|
POSTGRES_INITDB_ARGS: "--encoding=UTF8 --locale=C" # Necessary for docker-matrix
|
2023-12-29 23:58:57 +01:00
|
|
|
networks:
|
|
|
|
- name: postgres_network
|
|
|
|
published_ports:
|
|
|
|
- "127.0.0.1:5432:5432"
|
|
|
|
when: run_once_docker_postgres is not defined
|
|
|
|
|
2023-12-31 11:14:18 +01:00
|
|
|
- name: wait for availability of postgres
|
|
|
|
wait_for:
|
|
|
|
host: "127.0.0.1"
|
|
|
|
port: "5432"
|
|
|
|
delay: 0
|
|
|
|
timeout: 120
|
|
|
|
when: run_once_docker_postgres is not defined
|
|
|
|
|
|
|
|
- name: Create database
|
|
|
|
postgresql_db:
|
|
|
|
name: "{{ database_databasename }}"
|
|
|
|
state: present
|
|
|
|
login_user: postgres
|
|
|
|
login_password: "{{ central_postgres_password }}"
|
|
|
|
login_host: 127.0.0.1
|
|
|
|
login_port: 5432
|
|
|
|
listen: create database
|
|
|
|
|
|
|
|
- name: Create database user
|
|
|
|
postgresql_user:
|
|
|
|
name: "{{ database_username }}"
|
|
|
|
password: "{{ database_password }}"
|
|
|
|
db: "{{ database_databasename }}"
|
|
|
|
priv: ALL
|
|
|
|
state: present
|
|
|
|
login_user: postgres
|
|
|
|
login_password: "{{ central_postgres_password }}"
|
|
|
|
login_host: 127.0.0.1
|
|
|
|
login_port: 5432
|
|
|
|
listen: create database
|
|
|
|
|
2023-12-29 23:58:57 +01:00
|
|
|
- name: Run the docker_postgres tasks once
|
|
|
|
set_fact:
|
|
|
|
run_once_docker_postgres: true
|
|
|
|
when: run_once_docker_postgres is not defined
|