databases/roles/postgresql/tasks/initialize-docker.yml

36 lines
1.5 KiB
YAML

- 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 }}"
ports: "{{ postgresql_container_ports }}"
labels: "{{ postgresql_container_labels | default(omit, true) }}"
networks: "{{ postgresql_container_networks | default(omit, true) }}"
etc_hosts: "{{ postgresql_container_etc_hosts | default(omit, true) }}"
state: started
register: postgresql_container_info
- name: Wait for container startup
block:
- 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 }}"
- name: Wait for container startup (port)
ansible.builtin.wait_for:
host: >-2
{{ (pg_addresses == '*') | ternary(
omit,
postgresql_config_listen_addresses | first
) }}
port: "{{ postgresql_config_port }}"
when: "{{ not postgresql_config_connect_socket }}"
vars:
pg_addresses: "{{ postgresql_config_listen_addresses | join(',') }}"
- name: Ensure init container '{{ postgresql_container_name }}' is removed
community.docker.docker_container:
name: "{{ postgresql_container_name }}"
state: absent