Compare commits

..

1 Commits

4 changed files with 12 additions and 42 deletions

View File

@ -38,15 +38,6 @@ postgresql_container_etc_hosts: ~
postgresql_container_restart_policy: "on-failure"
postgresql_container_state: >-2
{{ (postgresql_state == 'present') | ternary('started', 'absent') }}
postgresql_container_volumes: ~
postgresql_container_base_volumes:
- "{{ postgresql_data_path }}:{{ postgresql_container_data_dir }}:z"
- "{{ postgresql_pg_hba_conf_file }}:{{ postgresql_container_data_dir }}/pg_hba.conf:ro"
- "{{ postgresql_pg_ident_conf_file }}:{{ postgresql_container_data_dir }}/pg_ident.conf:ro"
- "{{ postgresql_container_passwd_file }}:/etc/passwd:ro"
postgresql_container_merged_volumes: >-2
{{ postgresql_container_base_volumes
+ (postgresql_container_volumes | default([], true)) }}
# (Memory) performance tuning
postgresql_container_memory: ~
@ -56,5 +47,4 @@ postgresql_container_oom_kill: ~
postgresql_container_oom_score_adj: ~
postgresql_container_ulimits: ~
postgresql_container_passwd_file: "{{ postgresql_config_path }}/passwd"
postgresql_container_data_dir: "/var/lib/postgresql/data"
postgresql_container_passwd_file: "/etc/postgresql/{{ postgresql_major_version }}/passwd"

View File

@ -1,7 +1,7 @@
---
postgresql_user: postgresql
postgresql_version: >-2
{{ postgresql_versions[postgresql_major_version | string] }}
{{ postgresql_version[postgres_major_version | string] }}
postgresql_major_version: 16
postgresql_versions:
"17": "17.2"
@ -14,20 +14,12 @@ postgresql_config_path: >-2
postgresql_data_path: >-2
/var/lib/postgresql/{{ postgresql_major_version }}
postgresql_pg_ident_conf_file: >-2
{{ postgresql_config_path }}/pg_ident.conf
{{ postgresql_data_path }}/pg_ident.conf
postgresql_pg_hba_conf_file: >-2
{{ postgresql_config_path }}/pg_hba.conf
{{ postgresql_data_path }}/pg_hba.conf
postgresql_admin_role: "{{ postgresql_user }}"
postgresql_admin_role_contype: local
postgresql_admin_role_method: peer
postgresql_admin_local_user: >-2
{{ ansible_facts['user_id'] }}
postgresql_admin_role_mapping_name: >-2
{{ postgresql_admin_local_user }}_{{ postgresql_admin_role }}
postgresql_admin_pg_ident_conf: >-2
{{ postgresql_admin_role_mapping_name }}\t{{ postgresql_admin_local_user }}\t{{ postgresql_admin_role }}
postgresql_admin_pg_hba_conf_options: >-2
map={{ postgresql_admin_role_mapping_name }}
postgresql_superuser_password: ~
postgresql_state: present

View File

@ -21,7 +21,7 @@
- name: Initialize database if empty
ansible.builtin.include_tasks:
file: "initialize-docker.yml"
file: "docker-initialize.yml"
when:
- postgresql_state == 'present'
@ -33,7 +33,6 @@
user: "{{ postgresql_container_user | default(omit, true) }}"
ports: "{{ postgresql_container_ports | default(omit, true) }}"
labels: "{{ postgresql_container_labels | default(omit, true) }}"
volumes: "{{ postgresql_container_merged_volumes }}"
recreate: "{{ postgresql_container_recreate | default(omit, true) }}"
networks: "{{ postgresql_container_networks | default(omit, true) }}"
etc_hosts: "{{ postgresql_container_etc_hosts | default(omit, true) }}"
@ -45,3 +44,5 @@
ulimits: "{{ postgresql_container_ulimits | default(omit, true) }}"
restart_policy: "{{ postgresql_container_restart_policy | default(omit, true) }}"
state: "{{ postgresql_container_state }}"
-

View File

@ -1,26 +1,13 @@
---
- name: Ensure container '{{ postgresql_container_name }}' is {{ postgresql_container_state }} to initialise the database
community.docker.docker_container:
name: "{{ postgresql_container_name }}"
user: "{{ postgresql_container_user }}"
image: "{{ postgresql_container_image }}"
env: >-2
{{ postgresql_container_env | default({}, true)
| combine({'POSTGRES_PASSWORD': postgresql_superuser_password}) }}
user: "{{ postgresql_container_user | default(omit, true) }}"
ports: "{{ postgresql_container_ports | default(omit, true) }}"
ports: "{{ postgresql_container_ports }}"
labels: "{{ postgresql_container_labels | default(omit, true) }}"
volumes: "{{ postgresql_container_merged_volumes }}"
recreate: "{{ postgresql_container_recreate | default(omit, true) }}"
networks: "{{ postgresql_container_networks | default(omit, true) }}"
etc_hosts: "{{ postgresql_container_etc_hosts | default(omit, true) }}"
memory: "{{ postgresql_container_memory | default(omit, true) }}"
memory_reservation: "{{ postgresql_container_memory_reservation | default(omit, true) }}"
oom_killer: "{{ postgresql_container_oom_killer | default(omit, true) }}"
oom_score_adj: "{{ postgresql_container_oom_score_adj | default(omit, true) }}"
shm_size: "{{ postgresql_container_shm_size | default(omit, true) }}"
ulimits: "{{ postgresql_container_ulimits | default(omit, true) }}"
restart_policy: "{{ postgresql_container_restart_policy | default(omit, true) }}"
state: "{{ postgresql_container_state }}"
state: started
register: postgresql_container_info
- name: Wait for container startup
@ -28,7 +15,7 @@
- name: Wait for container startup (socket)
ansible.builtin.wait_for:
path: "{{ postgresql_config_unix_socket_directories | first }}.s.PGSQL.{{ postgresql_config_port }}"
when: "postgresql_config_connect_socket | bool"
when: "{{ postgresql_config_connect_socket }}"
- name: Wait for container startup (port)
ansible.builtin.wait_for:
host: >-2
@ -37,7 +24,7 @@
postgresql_config_listen_addresses | first
) }}
port: "{{ postgresql_config_port }}"
when: "not postgresql_config_connect_socket | bool"
when: "{{ not postgresql_config_connect_socket }}"
vars:
pg_addresses: "{{ postgresql_config_listen_addresses | join(',') }}"