community / community.general / 0.1.1 / module / postgresql_owner Change an owner of PostgreSQL database object Authors: Andrew Klychkov (@Andersson007) preview | supported by communitycommunity.general.postgresql_owner (0.1.1) — module
Install with ansible-galaxy collection install community.general:==0.1.1
collections: - name: community.general version: 0.1.1
Change an owner of PostgreSQL database object.
Also allows to reassign the ownership of database objects owned by a database role to another role.
# Set owner as alice for function myfunc in database bar by ansible ad-hoc command: # ansible -m postgresql_owner -a "db=bar new_owner=alice obj_name=myfunc obj_type=function" - name: The same as above by playbook postgresql_owner: db: bar new_owner: alice obj_name: myfunc obj_type: function
- name: Set owner as bob for table acme in database bar postgresql_owner: db: bar new_owner: bob obj_name: acme obj_type: table
- name: Set owner as alice for view test_view in database bar postgresql_owner: db: bar new_owner: alice obj_name: test_view obj_type: view
- name: Set owner as bob for tablespace ssd in database foo postgresql_owner: db: foo new_owner: bob obj_name: ssd obj_type: tablespace
- name: Reassign all object in database bar owned by bob to alice postgresql_owner: db: bar new_owner: alice reassign_owned_by: bob
- name: Reassign all object in database bar owned by bob and bill to alice postgresql_owner: db: bar new_owner: alice reassign_owned_by: - bob - bill
db: aliases: - login_db description: - Name of database to connect to. type: str port: aliases: - login_port default: 5432 description: - Database port to connect to. type: int ca_cert: aliases: - ssl_rootcert description: - Specifies the name of a file containing SSL certificate authority (CA) certificate(s). - If the file exists, the server's certificate will be verified to be signed by one of these authorities. type: str obj_name: description: - Name of a database object to change ownership. - Mutually exclusive with I(reassign_owned_by). type: str obj_type: aliases: - type choices: - database - function - matview - sequence - schema - table - tablespace - view description: - Type of a database object. - Mutually exclusive with I(reassign_owned_by). type: str ssl_mode: choices: - allow - disable - prefer - require - verify-ca - verify-full default: prefer description: - Determines whether or with what priority a secure SSL TCP/IP connection will be negotiated with the server. - See U(https://www.postgresql.org/docs/current/static/libpq-ssl.html) for more information on the modes. - Default of C(prefer) matches libpq default. type: str new_owner: description: - Role (user/group) to set as an I(obj_name) owner. required: true type: str login_host: description: - Host running the database. type: str login_user: default: postgres description: - The username used to authenticate with. type: str fail_on_role: default: true description: - If C(yes), fail when I(reassign_owned_by) role does not exist. Otherwise just warn and continue. - Mutually exclusive with I(obj_name) and I(obj_type). type: bool session_role: description: - Switch to session_role after connecting. The specified session_role must be a role that the current login_user is a member of. - Permissions checking for SQL commands is carried out as though the session_role were the one that had logged in originally. type: str login_password: description: - The password used to authenticate with. type: str login_unix_socket: description: - Path to a Unix domain socket for local connections. type: str reassign_owned_by: description: - The list of role names. The ownership of all the objects within the current database, and of all shared objects (databases, tablespaces), owned by this role(s) will be reassigned to I(owner). - Pay attention - it reassigns all objects owned by this role(s) in the I(db)! - If role(s) exists, always returns changed True. - Cannot reassign ownership of objects that are required by the database system. - Mutually exclusive with C(obj_type). elements: str type: list
queries: description: List of executed queries. returned: always sample: - REASSIGN OWNED BY "bob" TO "alice" type: str