diff --git a/.github/workflows/molecule.yml b/.github/workflows/molecule.yml index 074a1ad..41a012c 100644 --- a/.github/workflows/molecule.yml +++ b/.github/workflows/molecule.yml @@ -19,10 +19,11 @@ jobs: matrix: scenario: - deploy - - stopped - - masked + - stop + - mask - databases - configure + - initdb image: - name: ubuntu2204 command: /lib/systemd/systemd @@ -34,6 +35,11 @@ jobs: command: /lib/systemd/systemd - name: rockylinux9 command: /usr/lib/systemd/systemd + exclude: + - scenario: initdb + image: + name: rockylinux9 + command: /usr/lib/systemd/systemd steps: - name: Check out the codebase diff --git a/molecule/configure/molecule.yml b/molecule/configure/molecule.yml index 049bfdb..f0f6e47 100644 --- a/molecule/configure/molecule.yml +++ b/molecule/configure/molecule.yml @@ -7,7 +7,7 @@ dependency: driver: name: docker platforms: - - name: postgresql-install-01 + - name: postgresql-configure-01 image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2204}-ansible:latest" command: ${MOLECULE_DOCKER_COMMAND:-""} cgroupns_mode: host diff --git a/molecule/databases/molecule.yml b/molecule/databases/molecule.yml index 2304e7e..476e0da 100644 --- a/molecule/databases/molecule.yml +++ b/molecule/databases/molecule.yml @@ -7,7 +7,7 @@ dependency: driver: name: docker platforms: - - name: postgresql-install-01 + - name: postgresql-databases-01 image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2204}-ansible:latest" command: ${MOLECULE_DOCKER_COMMAND:-""} cgroupns_mode: host diff --git a/molecule/deploy/molecule.yml b/molecule/deploy/molecule.yml index 85b094a..1136082 100644 --- a/molecule/deploy/molecule.yml +++ b/molecule/deploy/molecule.yml @@ -7,7 +7,7 @@ dependency: driver: name: docker platforms: - - name: postgresql-install-01 + - name: postgresql-deploy-01 image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2204}-ansible:latest" command: ${MOLECULE_DOCKER_COMMAND:-""} cgroupns_mode: host diff --git a/molecule/initdb/molecule.yml b/molecule/initdb/molecule.yml new file mode 100644 index 0000000..237229e --- /dev/null +++ b/molecule/initdb/molecule.yml @@ -0,0 +1,59 @@ +--- +dependency: + name: galaxy + options: + role-file: requirements.yml + requirements-file: requirements.yml +driver: + name: docker +platforms: + - name: postgresql-initdb-01 + image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2204}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + privileged: true + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + tmpfs: + - /tmp + - /opt +provisioner: + name: ansible + playbooks: + prepare: ../common/prepare.yml + converge: ../common/converge.yml + side_effect: ../common/converge.yml + config_options: + defaults: + callbacks_enabled: ansible.posix.profile_tasks + inventory: + hosts: + all: + vars: + postgresql_nolog: false + postgresql_initdb: false + postgresql_service_state: stopped + postgresql_service_masked: true + postgresql_service_enabled: false + postgresql_pip_manage: false +verifier: + name: ansible +scenario: + prepare_sequence: + - prepare + create_sequence: + - create + converge_sequence: + - converge + destroy_sequence: + - destroy + cleanup_sequence: + - cleanup + test_sequence: + - dependency + - create + - prepare + - converge + - side_effect + - verify diff --git a/molecule/initdb/verify.yml b/molecule/initdb/verify.yml new file mode 100644 index 0000000..7368328 --- /dev/null +++ b/molecule/initdb/verify.yml @@ -0,0 +1,34 @@ +--- +- ansible.builtin.import_playbook: ../common/verify.yml + +- name: Verify datadir + hosts: all + gather_facts: true + become: true + tasks: + - name: Import role defaults + ansible.builtin.include_role: + name: nephelaiio.postgresql + tasks_from: vars.yml + + - name: Stat PostgreSQL datadir + ansible.builtin.stat: + path: "{{ _postgresql_datadir }}" + register: _datadir_query + + - name: Verify PostgreSQL datadir + ansible.builtin.assert: + that: _datadir_query.stat.exists + + - name: List PostgreSQL datadir files + ansible.builtin.find: + paths: "{{ _postgresql_datadir }}" + file_type: any + register: _datadir_files + + - name: Verify PostgreSQL files + ansible.builtin.assert: + that: _files | length == 0 + fail_msg: "Found datadir files [{{ _files | join(',') }}]" + vars: + _files: "{{ _datadir_files.files | map(attribute='path') }}" diff --git a/molecule/masked/molecule.yml b/molecule/mask/molecule.yml similarity index 97% rename from molecule/masked/molecule.yml rename to molecule/mask/molecule.yml index 8981a29..59c7096 100644 --- a/molecule/masked/molecule.yml +++ b/molecule/mask/molecule.yml @@ -7,7 +7,7 @@ dependency: driver: name: docker platforms: - - name: postgresql-install-01 + - name: postgresql-mask-01 image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2204}-ansible:latest" command: ${MOLECULE_DOCKER_COMMAND:-""} cgroupns_mode: host diff --git a/molecule/stopped/molecule.yml b/molecule/stop/molecule.yml similarity index 97% rename from molecule/stopped/molecule.yml rename to molecule/stop/molecule.yml index 199942a..eb274a1 100644 --- a/molecule/stopped/molecule.yml +++ b/molecule/stop/molecule.yml @@ -7,7 +7,7 @@ dependency: driver: name: docker platforms: - - name: postgresql-install-01 + - name: postgresql-stop-01 image: "geerlingguy/docker-${MOLECULE_DOCKER_IMAGE:-ubuntu2204}-ansible:latest" command: ${MOLECULE_DOCKER_COMMAND:-""} cgroupns_mode: host diff --git a/tasks/install.yml b/tasks/install.yml index 809879d..9a829d2 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -19,6 +19,23 @@ vars: _lock_state: install +- name: Configure cluster initialization for Debian distributions + when: ansible_os_family == "Debian" + block: + - name: Install postgresql common package + ansible.builtin.package: + name: postgresql-common + + - name: Disable database initialization + ansible.builtin.copy: + dest: "/etc/postgresql-common/createcluster.conf" + content: | + create_main_cluster = off + owner: root + group: root + mode: 0644 + when: not (_postgresql_initdb | bool) + - name: Install packages and configure package holds block: - name: Install postgresql packages diff --git a/tasks/vars.yml b/tasks/vars.yml index 8c7eab2..7f89613 100644 --- a/tasks/vars.yml +++ b/tasks/vars.yml @@ -17,7 +17,7 @@ _postgresql_pgoptions: "{{ (_auth_method == _auth_scram_sha256) | ternary(_auth_scram_option, '') }}" _postgresql_conf_include: "{{ _conf_include }}" _postgresql_conf_main: "{{ _conf_main }}" - _postgresql_conf_hba: "{{ _conf_datadir }}/pg_hba.conf" + _postgresql_conf_hba: "{{ _conf_confdir }}/pg_hba.conf" _postgresql_conf_ansible: "{{ _conf_include }}/{{ __postgresql_conf_ansible }}" _postgresql_conf_pgaudit: "{{ _conf_include }}/{{ __postgresql_conf_pgaudit }}" _postgresql_conf_pgcron: "{{ _conf_include }}/{{ __postgresql_conf_pgcron }}"