2023-12-29 23:58:57 +01:00
|
|
|
- name: Create Docker network for PostgreSQL
|
|
|
|
docker_network:
|
2024-01-02 21:13:34 +01:00
|
|
|
name: central_postgres_network
|
2023-12-29 23:58:57 +01:00
|
|
|
state: present
|
|
|
|
when: run_once_docker_postgres is not defined
|
|
|
|
|
|
|
|
- name: Install PostgreSQL
|
|
|
|
docker_container:
|
2024-01-04 20:57:02 +01:00
|
|
|
name: central-postgres
|
|
|
|
image: "postgres:{{database_version}}"
|
2023-12-29 23:58:57 +01:00
|
|
|
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:
|
2024-01-02 21:13:34 +01:00
|
|
|
- name: central_postgres_network
|
2023-12-29 23:58:57 +01:00
|
|
|
published_ports:
|
|
|
|
- "127.0.0.1:5432:5432"
|
2024-01-04 20:57:02 +01:00
|
|
|
volumes:
|
|
|
|
- central_postgres_database:/var/lib/postgresql/data
|
2023-12-29 23:58:57 +01:00
|
|
|
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
|
2024-01-04 20:57:02 +01:00
|
|
|
timeout: 300
|
2023-12-31 11:14:18 +01:00
|
|
|
when: run_once_docker_postgres is not defined
|
|
|
|
|
2024-01-04 20:57:02 +01:00
|
|
|
- name: install python-psycopg2
|
|
|
|
pacman:
|
|
|
|
name: python-psycopg2
|
|
|
|
state: present
|
|
|
|
when: run_once_docker_postgres is not defined
|
|
|
|
|
|
|
|
- name: "Create database: {{ database_databasename }}"
|
2023-12-31 11:14:18 +01:00
|
|
|
postgresql_db:
|
|
|
|
name: "{{ database_databasename }}"
|
|
|
|
state: present
|
|
|
|
login_user: postgres
|
|
|
|
login_password: "{{ central_postgres_password }}"
|
|
|
|
login_host: 127.0.0.1
|
|
|
|
login_port: 5432
|
|
|
|
|
2024-01-04 20:57:02 +01:00
|
|
|
- name: "Create database user: {{ database_username }}"
|
2023-12-31 11:14:18 +01:00
|
|
|
postgresql_user:
|
2024-01-04 20:57:02 +01:00
|
|
|
name: "{{ database_username }}"
|
|
|
|
password: "{{ database_password }}"
|
|
|
|
db: "{{ database_databasename }}"
|
|
|
|
state: present
|
|
|
|
login_user: postgres
|
|
|
|
login_password: "{{ central_postgres_password }}"
|
|
|
|
login_host: 127.0.0.1
|
|
|
|
login_port: 5432
|
|
|
|
|
|
|
|
- name: "Set privileges for database user: {{ database_username }}"
|
|
|
|
postgresql_privs:
|
|
|
|
db: "{{ database_databasename }}"
|
|
|
|
role: "{{ database_username }}"
|
|
|
|
objs: ALL_IN_SCHEMA
|
|
|
|
privs: ALL
|
|
|
|
type: table
|
|
|
|
state: present
|
|
|
|
login_user: postgres
|
|
|
|
login_password: "{{ central_postgres_password }}"
|
|
|
|
login_host: 127.0.0.1
|
|
|
|
login_port: 5432
|
|
|
|
|
|
|
|
- name: Grant all privileges at the database level
|
|
|
|
postgresql_privs:
|
|
|
|
db: "{{ database_databasename }}"
|
|
|
|
role: "{{ database_username }}"
|
|
|
|
privs: ALL
|
|
|
|
type: database
|
|
|
|
state: present
|
|
|
|
login_user: postgres
|
|
|
|
login_password: "{{ central_postgres_password }}"
|
|
|
|
login_host: 127.0.0.1
|
|
|
|
login_port: 5432
|
|
|
|
|
|
|
|
- name: Grant all privileges on all tables in the public schema
|
|
|
|
postgresql_privs:
|
2023-12-31 11:14:18 +01:00
|
|
|
db: "{{ database_databasename }}"
|
2024-01-04 20:57:02 +01:00
|
|
|
role: "{{ database_username }}"
|
|
|
|
objs: ALL_IN_SCHEMA
|
|
|
|
privs: ALL
|
|
|
|
type: table
|
|
|
|
schema: public
|
2023-12-31 11:14:18 +01:00
|
|
|
state: present
|
|
|
|
login_user: postgres
|
|
|
|
login_password: "{{ central_postgres_password }}"
|
|
|
|
login_host: 127.0.0.1
|
|
|
|
login_port: 5432
|
|
|
|
|
2024-01-04 20:57:02 +01:00
|
|
|
- name: Set comprehensive privileges for user on public schema
|
|
|
|
postgresql_query:
|
|
|
|
db: "{{ database_databasename }}"
|
|
|
|
login_user: postgres
|
|
|
|
login_password: "{{ central_postgres_password }}"
|
|
|
|
login_host: 127.0.0.1
|
|
|
|
login_port: 5432
|
|
|
|
query: |
|
|
|
|
GRANT USAGE ON SCHEMA public TO {{ database_username }};
|
|
|
|
GRANT CREATE ON SCHEMA public TO {{ database_username }};
|
|
|
|
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL PRIVILEGES ON TABLES TO {{ database_username }};
|
|
|
|
|
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
|