community.postgresql 5.0.0 Released - Major Update to postgresql_membership and Removal of Legacy Options
Introduction
community.postgresql is the Ansible collection that provides modules and plugins to manage PostgreSQL databases, roles, privileges, and configuration from playbooks. It is one of the collections bundled in the ansible community package and is commonly used for automating database provisioning and access control.
Version 5.0.0 is a major release, jumping from 4.2.0. Unlike a routine patch bump, this release contains breaking changes centered almost entirely on the postgresql_membership module, plus the removal of previously deprecated connection options across the collection. Anyone using postgresql_membership in production playbooks should read the porting guide below before upgrading.
Whats New
Minor Changes
- Replaced the deprecated
ansible.module_utils.sixcompatibility shims with their Python standard library equivalents.ansible.module_utils.sixis deprecated in ansible-core 2.21 and scheduled for removal in 2.24. postgresql_membership- addedgranted_by_any, both at the top level and permembershipsrow, to manage every grant of a membership regardless of who made it, matching the behavior of the deprecatedgroupsoption.GRANTthen names no granting role, andstate=absent/state=exactrevoke every grant of the membership.postgresql_membership- added thegrantsandeffective_optionsreturn values, listing every grant of the requested pairs and the options the target role effectively holds.postgresql_membership- added themembershipsoption: one membership per row, each with its owntarget_roles,granted_by,admin_option,inherit_option, andset_option, applied in a single transaction. It is mutually exclusive withgroups; the top-leveltarget_rolesacts as the default for rows that name none (see issue #757).postgresql_membership- movedPgMembershipout of thepostgresmodule_utils into a newmembershipmodule_utils, split intoPgMembershipByPair(thegroupsmodel) andPgMembershipByGrantor(themembershipsmodel). External code importing these classes must follow the move.postgresql_membership- withmemberships, the module now checks before emitting aGRANTthat the connecting role has the privileges of the granting role and that the granting role holdsADMIN OPTIONon the group, failing and naming the roles that do hold it. The deprecatedgroupsoption records the same privilege check for every granting role found before it revokes. A task with nothing left to do is not checked.
Breaking Changes / Porting Guide
postgresql_membership-state=exactnow reportsgrantedwith an entry for every requested group, the same asstate=presentdoes, soresult.granted == {}no longer holds on an unchanged run.postgresql_membership- amembershipsrow must setgranted_bywhen the connecting role holdsADMIN OPTIONon a group only through another role, since PostgreSQL refuses to record a grant under a role that lacks the option. The deprecatedgroupsoption is not affected by this rule.postgresql_membership- on PostgreSQL 16 and later, amembershipsrow manages only the grant recorded under its granting role (the bootstrap superuser when the connecting role is a superuser, the connecting role otherwise, or the role named bygranted_by).state=presentcreates that grant even if another role has already granted the membership, whilestate=absentandstate=exactneither revoke nor report grants recorded under another role. This means a previously unchanged task may reportchangedon its first run and trigger handlers. The deprecatedgroupsoption still treats the (group, target role) pair as the membership regardless of who granted it (see issue #757).
Deprecated Features
postgresql_membership- the top-levelgroupsoption is deprecated and will be removed incommunity.postgresql6.0.0.granted_by_anycombined with thegroupskey ofmembershipsbehaves identically across versions;target_rolesremains at the top level, and an emptymembershipslist withstate=exactreplaces an emptygroupslist.
Removed Features (previously deprecated)
- PostgreSQL modules - the previously deprecated
login,host, andunix_socket-related legacy connection options (announced for removal in earlier changelogs) have been dropped from this release. Playbooks still referencing these legacy option names should be updated to the current connection parameters before upgrading.
postgresql_membership: groups vs memberships at a glance
| Aspect | groups (deprecated) | memberships (new) |
|---|---|---|
| Granularity | One shared target_roles list for all groups | Per-row target_roles, granted_by, admin_option, inherit_option, set_option |
| Grant ownership | Ignores who granted (granted_by_any behavior) | Tracks the specific granting role by default |
state=exact behavior | Legacy reporting | Reports granted for every requested group, same as state=present |
| Removal target | community.postgresql 6.0.0 | Recommended going forward |
| Module utils | PgMembershipByPair | PgMembershipByGrantor |
Installation and Verification
# Install or upgrade the collection from Ansible Galaxy
ansible-galaxy collection install community.postgresql --upgrade
# Verify the installed version
ansible-galaxy collection list community.postgresql
# Inspect the changelog shipped with the collection
cat ~/.ansible/collections/ansible_collections/community/postgresql/CHANGELOG.rst
Before upgrading in environments that rely on postgresql_membership, test playbooks against a staging PostgreSQL instance (ideally version 16+) to confirm the new grant-tracking behavior does not unexpectedly report changed on tasks previously considered idempotent.