postgresql_membership – Add or remove PostgreSQL roles from groups¶
New in version 2.8.
Synopsis¶
Adds or removes PostgreSQL roles from groups (other roles).
Users are roles with login privilege.
Groups are PostgreSQL roles usually without LOGIN privilege.
Common use case:
add a new group (groups) by postgresql_user module with role_attr_flags=NOLOGIN
grant them desired privileges by postgresql_privs module
add desired PostgreSQL users to the new group (groups) by this module
Parameters¶
Notes¶
Note
The default authentication assumes that you are either logging in as or sudo’ing to the
postgres
account on the host.To avoid “Peer authentication failed for user postgres” error, use postgres user as a become_user.
This module uses psycopg2, a Python PostgreSQL database adapter. You must ensure that psycopg2 is installed on the host before using this module.
If the remote host is the PostgreSQL server (which is the default case), then PostgreSQL must also be installed on the remote host.
For Ubuntu-based systems, install the postgresql, libpq-dev, and python-psycopg2 packages on the remote host before using this module.
The ca_cert parameter requires at least Postgres version 8.4 and psycopg2 version 2.4.3.
See Also¶
See also
- postgresql_user – Add or remove a user (role) from a PostgreSQL server instance
The official documentation on the postgresql_user module.
- postgresql_privs – Grant or revoke privileges on PostgreSQL database objects
The official documentation on the postgresql_privs module.
- postgresql_owner – Change an owner of PostgreSQL database object
The official documentation on the postgresql_owner module.
- PostgreSQL role membership reference
Complete reference of the PostgreSQL role membership documentation.
- PostgreSQL role attributes reference
Complete reference of the PostgreSQL role attributes documentation.
Examples¶
- name: Grant role read_only to alice and bob
postgresql_membership:
group: read_only
target_roles:
- alice
- bob
state: present
# you can also use target_roles: alice,bob,etc to pass the role list
- name: Revoke role read_only and exec_func from bob. Ignore if roles don't exist
postgresql_membership:
groups:
- read_only
- exec_func
target_role: bob
fail_on_role: no
state: absent
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Status¶
This module is not guaranteed to have a backwards compatible interface. [preview]
This module is maintained by the Ansible Community. [community]
Authors¶
Andrew Klychkov (@Andersson007)
Hint
If you notice any issues in this documentation, you can edit this document to improve it.