Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
82efa2d
use the proginal postgresql configuration file
khaledk2 May 23, 2024
3637a0e
Allow updating the config, add test case and restore listen_addresses
khaledk2 May 25, 2024
35930b0
Fix re-run the role without having the org file
khaledk2 Jun 11, 2024
0879c9f
fix syntax error
khaledk2 Jun 11, 2024
9ee77fa
Clean up the code and set_facts
khaledk2 Jun 11, 2024
9790b98
remove redundant check
khaledk2 Jun 12, 2024
743d5f3
Improve tasks name
khaledk2 Jun 14, 2024
dcaa4eb
clean up the configuration file and copy to org in case of org is not…
khaledk2 Jun 27, 2024
8151508
Fix check mode orginal file issue
khaledk2 Jul 7, 2024
5b1c41a
clean up the code
khaledk2 Jul 7, 2024
bc2b2ad
Update task name to address Petr's comment
khaledk2 Jul 23, 2024
bd8814a
Use interpreter /usr/bin/python to fix the error with latest ansible …
pwalczysko Sep 12, 2025
eb111db
Upgrade the testing framework
pwalczysko Sep 12, 2025
c4f47a0
Add explanatory comment
pwalczysko Sep 12, 2025
87bdcf9
Reformulate comment
pwalczysko Sep 12, 2025
4154acc
Point to the branch on postgresql-client role to fix build
pwalczysko Sep 12, 2025
b9252ed
Fix pointing to a branch in another requirements.yml file, fix in pla…
pwalczysko Sep 12, 2025
e15d52a
Do not test on postgresql12 as it is eol and crashes the test
pwalczysko Sep 29, 2025
1429db3
Also remove postgres13 as it is eol very soon
pwalczysko Sep 29, 2025
8f33683
Use correct ansible_python_interpreter
pwalczysko Sep 29, 2025
e8d477e
Also add postgres 17,18 cf. postgresql-client role
pwalczysko Oct 13, 2025
c889da6
Point to the correct branch on psql-client role
pwalczysko Oct 13, 2025
0186272
Implement update_cache only for apt with param
pwalczysko Oct 27, 2025
bf39101
Revert pointing to branch, go back to ome.postgresql_client
pwalczysko Nov 4, 2025
86d2b42
Fix FQCN and review include/import
pwalczysko Nov 4, 2025
ff6fc56
Update tasks/main.yml
pwalczysko Nov 4, 2025
138a500
Use FQCN for the two missed modules
pwalczysko Nov 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,34 @@ on:
jobs:

list-scenarios:
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
outputs:
matrix: ${{ steps.listscenarios.outputs.scenarios }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- id: listscenarios
uses: ome/action-ansible-molecule-list-scenarios@main

test:
name: Test
needs:
- list-scenarios
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
strategy:
# Keep running so we can see if other tests pass
fail-fast: false
matrix:
scenario: ${{fromJson(needs.list-scenarios.outputs.matrix)}}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
python-version: '3.12'
- name: Install Ansible & Molecule
run: pip install "ansible<8" ansible-lint flake8 \
"molecule<5" molecule-plugins[docker] pytest-testinfra \
"ansible-compat<4"
run: |
pip install "requests" "ansible" "ansible-lint" "flake8"
pip install "molecule" "ansible-compat"
pip install molecule-plugins[docker] pytest-testinfra
- name: Run molecule
run: molecule test -s "${{ matrix.scenario }}"

Expand All @@ -45,7 +46,7 @@ jobs:
if: startsWith(github.ref, 'refs/tags')
needs:
- test
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: galaxy
uses: ansible-actions/ansible-galaxy-action@v1.2.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Role Variables

Defaults: `defaults/main.yml`

- `postgresql_version`: The PostgreSQL major version: `12`, `13`, `14`, `15`, `16`
- `postgresql_version`: The PostgreSQL major version: `14`, `15`, `16`, `17`, `18`
- `postgresql_package_version`: The PostgreSQL full version, leave this empty to use the latest minor release from `postgresql_version`, ignored on Ubuntu
- `postgresql_dist_redhat` or `postgresql_dist_debian`: Object that define configuration attributes for PostgreSQL on each specific OS, these variables allow to change the interaction between variables defined at [ome.postgresql](https://galaxy.ansible.com/ome/postgresql) and [ome.postgresql_client](https://github.com/ome/ansible-role-postgresql-client)

Expand Down
5 changes: 3 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ postgresql_server_auth: []
# Recursively reset the owner/group of the postgres datadir?
postgresql_server_chown_datadir: false

postgres_config_file_contents: ''
######################################################################
# Internal role variables, do not modify
######################################################################
Expand All @@ -51,14 +52,14 @@ postgresql_dist_redhat:
{{
(postgresql_package_version | length > 0) |
ternary('-' + postgresql_package_version, '')
}}
}}

# Attributes are parsed and used to set facts at tasks/debian.yml.
# Debian variation, following the same principles of postgresql_dist_redhat
postgresql_dist_debian:
bindir: /usr/lib/postgresql/{{ postgresql_version }}/bin
confdir: /etc/postgresql/{{ postgresql_version }}/main
conf_postgresql_src: postgresql-conf-10-ubuntu.j2
conf_postgresql_src: postgresql-conf.j2
datadir: /var/lib/postgresql/{{ postgresql_version }}/main
basename: postgresql-{{ postgresql_version }}
service: postgresql
2 changes: 1 addition & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ galaxy_info:
description: Upstream PostgreSQL server
company: Open Microscopy Environment
license: BSD
min_ansible_version: 2.10
min_ansible_version: 2.11
platforms:
- name: EL
versions:
Expand Down
1 change: 1 addition & 0 deletions meta/requirements.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---

- src: ome.postgresql_client
6 changes: 3 additions & 3 deletions molecule/resources/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
- hosts: all
tasks:
- name: create test tables publicdb
command: >
ansible.builtin.command: >
env PGPASSWORD=tester123 psql -h localhost -U tester publicdb
-c "{{ item }}"
register: result
Expand All @@ -40,7 +40,7 @@
(select text from regular);

- name: create test tables secretdb
command: >-
ansible.builtin.command: >-
env PGPASSWORD=alice123 psql -h localhost -U alice secretdb
-c "{{ item }}"
register: result
Expand All @@ -59,7 +59,7 @@
- name: set privileges on secretdb tables
become: true
become_user: postgres
postgresql_privs:
community.postgresql.postgresql_privs:
database: "{{ item }}"
obj: regular
privs: SELECT
Expand Down
1 change: 1 addition & 0 deletions molecule/resources/requirements.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---

- src: ome.postgresql_client
13 changes: 11 additions & 2 deletions molecule/resources/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,23 @@ def test_server_listen(host):
assert listen_addresses == "listen_addresses = localhost"


def test_backup_config_exist(host):
version = get_version(host)
if host.system_info.distribution == 'rocky':
config_backup = '/var/lib/pgsql/{version}/data/postgresql.conf.org'
else:
config_backup = '/etc/postgresql/{version}/main/postgresql.conf.org'
with host.sudo():
backup_file = config_backup.format(version=version)
assert host.file(backup_file).is_file


def test_psql_version(host):
ver = get_version(host)
out = host.check_output('psql --version')
assert out.startswith('psql (PostgreSQL) {}.'.format(ver))


# Create

def createdb(host, db, should_pass, password, name):
try:
host.check_output(
Expand Down
4 changes: 2 additions & 2 deletions molecule/resources/tests/test_extra_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def test_server_log_file_name(host):
# Check previous day too in case this is run at midnight
version = get_version(host)
if host.system_info.distribution == 'rocky':
logdir = '/var/lib/pgsql/{version}/data/pg_log'
logdir = '/var/lib/pgsql/{version}/data/log'
else:
logdir = '/var/lib/postgresql/{version}/main/pg_log'
logdir = '/var/lib/postgresql/{version}/main/log'
date1 = datetime.today()
date0 = date1 - timedelta(days=1)
logdir = logdir.format(version=version)
Expand Down
18 changes: 9 additions & 9 deletions molecule/rockylinux9/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ lint: |
ansible-lint
flake8
platforms:
- name: postgresql-12-r9
- name: postgresql-14-r9
image: eniocarboni/docker-rockylinux-systemd:9
image_version: latest
command: /sbin/init
Expand All @@ -20,7 +20,7 @@ platforms:
- /sys/fs/cgroup
groups:
- extra_options
- name: postgresql-13-r9
- name: postgresql-15-r9
image: eniocarboni/docker-rockylinux-systemd:9
image_version: latest
command: /sbin/init
Expand All @@ -30,7 +30,7 @@ platforms:
- /sys/fs/cgroup
groups:
- extra_options
- name: postgresql-14-r9
- name: postgresql-16-r9
image: eniocarboni/docker-rockylinux-systemd:9
image_version: latest
command: /sbin/init
Expand All @@ -40,7 +40,7 @@ platforms:
- /sys/fs/cgroup
groups:
- extra_options
- name: postgresql-15-r9
- name: postgresql-17-r9
image: eniocarboni/docker-rockylinux-systemd:9
image_version: latest
command: /sbin/init
Expand All @@ -50,7 +50,7 @@ platforms:
- /sys/fs/cgroup
groups:
- extra_options
- name: postgresql-16-r9
- name: postgresql-18-r9
image: eniocarboni/docker-rockylinux-systemd:9
image_version: latest
command: /sbin/init
Expand All @@ -66,16 +66,16 @@ provisioner:
name: ansible-lint
inventory:
host_vars:
postgresql-12-r9:
postgresql_version: "12"
postgresql-13-r9:
postgresql_version: "13"
postgresql-14-r9:
postgresql_version: "14"
postgresql-15-r9:
postgresql_version: "15"
postgresql-16-r9:
postgresql_version: "16"
postgresql-17-r9:
postgresql_version: "17"
postgresql-18-r9:
postgresql_version: "18"
group_vars:
extra_options:
postgresql_server_conf:
Expand Down
1 change: 0 additions & 1 deletion molecule/rockylinux9/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
tasks:
- name: Upgrade ca-certificates
ansible.builtin.dnf:
update_cache: true
pkg:
- ca-certificates
state: latest
22 changes: 11 additions & 11 deletions molecule/ubuntu2204/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ lint: |
ansible-lint
flake8
platforms:
- name: postgresql-12-u2204
- name: postgresql-14-u2204
image: eniocarboni/docker-ubuntu-systemd:22.04
command: /sbin/init
privileged: true
cgroupns_mode: host
tmpfs:
- /sys/fs/cgroup
- name: postgresql-13-u2204
- name: postgresql-15-u2204
image: eniocarboni/docker-ubuntu-systemd:22.04
command: /sbin/init
privileged: true
cgroupns_mode: host
tmpfs:
- /sys/fs/cgroup
- name: postgresql-14-u2204
- name: postgresql-16-u2204
image: eniocarboni/docker-ubuntu-systemd:22.04
command: /sbin/init
privileged: true
cgroupns_mode: host
tmpfs:
- /sys/fs/cgroup
- name: postgresql-15-u2204
- name: postgresql-17-u2204
image: eniocarboni/docker-ubuntu-systemd:22.04
command: /sbin/init
privileged: true
cgroupns_mode: host
tmpfs:
- /sys/fs/cgroup
- name: postgresql-16-u2204
- name: postgresql-18-u2204
image: eniocarboni/docker-ubuntu-systemd:22.04
command: /sbin/init
privileged: true
Expand All @@ -51,12 +51,6 @@ provisioner:
name: ansible-lint
inventory:
host_vars:
postgresql-12-u2204:
postgresql_version: "12"
ansible_python_interpreter: /usr/bin/python3
postgresql-13-u2204:
postgresql_version: "13"
ansible_python_interpreter: /usr/bin/python3
postgresql-14-u2204:
postgresql_version: "14"
ansible_python_interpreter: /usr/bin/python3
Expand All @@ -66,6 +60,12 @@ provisioner:
postgresql-16-u2204:
postgresql_version: "16"
ansible_python_interpreter: /usr/bin/python3
postgresql-17-u2204:
postgresql_version: "17"
ansible_python_interpreter: /usr/bin/python3
postgresql-18-u2204:
postgresql_version: "18"
ansible_python_interpreter: /usr/bin/python3
group_vars:
extra_options:
postgresql_server_conf:
Expand Down
1 change: 1 addition & 0 deletions molecule/ubuntu2204/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
tasks:
- ansible.builtin.apt:
update_cache: true
cache_valid_time: 86400
14 changes: 9 additions & 5 deletions tasks/databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
# privilege for functions; and USAGE privilege for languages."

- name: postgres | revoke default permissions
postgresql_privs:
community.postgresql.postgresql_privs:
database: "{{ item.name }}"
privs: ALL
roles: PUBLIC
Expand All @@ -61,7 +61,7 @@

# Revoke the default permissions on the public schema
- name: postgres | revoke default schema permissions
postgresql_privs:
community.postgresql.postgresql_privs:
database: "{{ item.name }}"
obj: public
privs: ALL
Expand All @@ -75,7 +75,7 @@
# The default public schema is owned by postgres, and since the PUBLIC
# privileges are revoked we must grant them back to the owner
- name: postgres | grant database owner public schema privileges
postgresql_privs:
community.postgresql.postgresql_privs:
database: "{{ item.name }}"
obj: public
privs: ALL
Expand All @@ -87,7 +87,7 @@
- "{{ postgresql_databases }}"

- name: postgres | grant connect privileges
postgresql_privs:
community.postgresql.postgresql_privs:
database: "{{ item.1 }}"
privs: CONNECT
roles: "{{ item.0.user }}"
Expand All @@ -98,7 +98,7 @@
- databases

- name: postgres | grant usage privileges on default public schema
postgresql_privs:
community.postgresql.postgresql_privs:
database: "{{ item.1 }}"
objs: public
privs: USAGE
Expand All @@ -111,3 +111,7 @@

become: true
become_user: "{{ postgresql_become_user }}"
# Need to install VM-wide packages (e.g. libselinux-python3)
# using the default python implementation - otherwise the task fails
vars:
ansible_python_interpreter: "/usr/bin/python3"
4 changes: 3 additions & 1 deletion tasks/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
become: true
ansible.builtin.apt:
update_cache: true
cache_valid_time: 86400
name: >-
{{ postgresql_dist_debian.basename }}
state: present
Expand All @@ -13,6 +14,7 @@
become: true
ansible.builtin.apt:
update_cache: true
cache_valid_time: 86400
# Needs to match the Ansible interpreter
name: >-
python{{
Expand All @@ -21,7 +23,7 @@
state: present

- name: postgres | set debian dist variables
set_fact:
ansible.builtin.set_fact:
postgresql_dist_datadir: "{{ postgresql_dist_debian.datadir }}"
postgresql_dist_bindir: "{{ postgresql_dist_debian.bindir }}"
postgresql_dist_confdir: "{{ postgresql_dist_debian.confdir }}"
Expand Down
Loading