This commit is contained in:
Robert Kaussow 2024-08-13 09:40:06 +02:00
parent ad3a53bed7
commit e340d11ad5
Signed by: xoxys
GPG Key ID: 4E692A2EAECC03C0
2 changed files with 56 additions and 59 deletions

View File

@ -1,6 +1,6 @@
--- ---
- name: Restart PostgreSQL - name: Restart PostgreSQL
service: ansible.builtin.service:
name: postgres name: postgres
state: restarted state: restarted
daemon_reload: True daemon_reload: True

View File

@ -1,65 +1,62 @@
--- ---
- block: - name: Create network specs
- name: Create network specs ansible.builtin.template:
template: src: etc/containers/systemd/postgres.network.j2
src: etc/containers/systemd/postgres.network.j2 dest: "/etc/containers/systemd/postgres.network"
dest: "/etc/containers/systemd/postgres.network" owner: root
owner: root group: root
group: root mode: "0640"
mode: "0640" when: postgres_network | splitext | last == ".network"
when: postgres_network | splitext | last == ".network" notify: __postgres_restart
notify: __postgres_restart
- name: Create container volumes - name: Create container volumes
containers.podman.podman_volume: containers.podman.podman_volume:
name: "{{ item.name }}" name: "{{ item.name }}"
options: "{{ item.options | default(omit) }}" options: "{{ item.options | default(omit) }}"
state: "{{ item.state | default('present') }}" state: "{{ item.state | default('present') }}"
loop: "{{ postgres_volumes }}" loop: "{{ postgres_volumes }}"
loop_control: loop_control:
label: "{{ item.name }}" label: "{{ item.name }}"
when: item.type | default("volume") | lower == "volume" when: item.type | default("volume") | lower == "volume"
register: __postgres_volumes_raw register: __postgres_volumes_raw
- name: Register container volumes map - name: Register container volumes map
set_fact: ansible.builtin.set_fact:
__postgres_volumes_map: "{{ __postgres_volumes_raw.results | json_query('[].volume') | items2dict(key_name='Name', value_name='Mountpoint') }}" __postgres_volumes_map: "{{ __postgres_volumes_raw.results | json_query('[].volume') | items2dict(key_name='Name', value_name='Mountpoint') }}"
- name: Deploy postgres env files - name: Deploy postgres env files
template: ansible.builtin.template:
src: "etc/containers/systemd/{{ item }}.j2" src: "etc/containers/systemd/{{ item }}.j2"
dest: "/etc/containers/systemd/{{ item }}" dest: "/etc/containers/systemd/{{ item }}"
owner: root owner: root
group: root group: root
mode: "0640" mode: "0640"
loop: loop:
- postgres.env - postgres.env
- postgres.sys.env - postgres.sys.env
notify: __postgres_restart notify: __postgres_restart
- name: Create container specs - name: Create container specs
template: ansible.builtin.template:
src: etc/containers/systemd/postgres.container.j2 src: etc/containers/systemd/postgres.container.j2
dest: "/etc/containers/systemd/postgres.container" dest: "/etc/containers/systemd/postgres.container"
owner: root owner: root
group: root group: root
mode: "0640" mode: "0640"
notify: __postgres_restart notify: __postgres_restart
- name: Deploy init-user-db - name: Deploy init-user-db
ansible.builtin.copy: ansible.builtin.copy:
src: init-user-db.sh src: init-user-db.sh
dest: "{{ __postgres_volumes_map['postgres-initdb'] }}" dest: "{{ __postgres_volumes_map['postgres-initdb'] }}"
owner: "{{ postgres_uid }}" owner: "{{ postgres_uid }}"
group: "{{ postgres_gid }}" group: "{{ postgres_gid }}"
mode: "0644" mode: "0644"
when: "'postgres-initdb' in __postgres_volumes_map" when: "'postgres-initdb' in __postgres_volumes_map"
- name: Ensure service state - name: Ensure service state
systemd: ansible.builtin.service:
name: "postgres.service" name: "postgres.service"
state: started state: started
daemon_reload: True daemon_reload: True
enabled: True enabled: True
become: True
become_user: root